:root {
    /* Light Mode Variables (Default) */
    --bg-main: #f4f7f6;
    --bg-card: #ffffff;
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --primary: #3498db;
    --primary-hover: #2980b9;
    --success: #2ecc71;
    --danger: #e74c3c;
    --warning: #f1c40f;
    --border: #e0e6ed;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    --sidebar-bg: #2c3e50;
    --sidebar-text: #ecf0f1;
    --sidebar-hover: #34495e;
}

[data-theme="dark"] {
    /* Dark Mode Variables */
    --bg-main: #121212;
    --bg-card: #1e1e1e;
    --text-main: #e0e0e0;
    --text-muted: #a0a0a0;
    --primary: #3d5afe;
    --primary-hover: #536dfe;
    --success: #00c853;
    --danger: #d50000;
    --warning: #ffd600;
    --border: #333333;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --sidebar-bg: #1a1a1a;
    --sidebar-text: #e0e0e0;
    --sidebar-hover: #333333;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', 'Roboto', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Utilities */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
}

.card {
    background-color: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease, border-color 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.1);
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s ease, transform 0.1s ease;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-block {
    display: block;
    width: 100%;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

/* =========================================
   Responsive Grid System
   ========================================= */
.grid-1-2 {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
}
.grid-1-1 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}
.grid-3-col {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}
.grid-4-col {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.grid-gap-15 {
    gap: 15px;
}
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* =========================================
   Mobile Sidebar & Topbar Elements
   ========================================= */
.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 24px;
    cursor: pointer;
    margin-right: 15px;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* =========================================
   Media Queries (Tablets & Mobile)
   ========================================= */
@media (max-width: 768px) {
    /* Stack Grids */
    .grid-1-2, .grid-1-1, .grid-2-1, .grid-3-col {
        grid-template-columns: 1fr;
    }
    
    .grid-4-col {
        grid-template-columns: 1fr 1fr;
    }
    
    /* Responsive Layout */
    .app-wrapper {
        grid-template-columns: 1fr;
    }
    
    /* Hide Sidebar by default */
    .sidebar {
        position: fixed;
        left: -250px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: left 0.3s ease;
    }
    
    /* Open Sidebar */
    .sidebar.mobile-open {
        left: 0;
    }
    
    /* Show Hamburger Menu */
    .hamburger {
        display: block;
    }
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background-color: var(--bg-main);
    color: var(--text-main);
    font-size: 16px;
    transition: all 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--bg-card);
    box-shadow: 0 0 0 4px rgba(61, 90, 254, 0.15);
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 500;
}

.alert-danger {
    background-color: rgba(231, 76, 60, 0.1);
    color: var(--danger);
    border: 1px solid rgba(231, 76, 60, 0.2);
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.table th, .table td {
    padding: 15px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background-color: rgba(0, 0, 0, 0.03);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0.5px;
}

.table tbody tr {
    transition: background-color 0.2s ease;
}

.table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .table th {
    background-color: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    color: var(--primary);
}

.nav-menu {
    list-style: none;
    padding: 20px 0;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    margin-bottom: 5px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background-color 0.2s ease, padding-left 0.2s ease;
}

.nav-link:hover {
    background-color: var(--sidebar-hover);
    padding-left: 25px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: 70px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    transition: background-color 0.3s ease;
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    color: var(--text-main);
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
}
.theme-toggle:hover {
    background-color: var(--border);
}

.content-area {
    padding: 30px;
    overflow-y: auto;
    flex: 1;
}

/* Notification Styles */
.notification-container {
    position: relative;
    display: inline-block;
    margin-right: 15px;
}

.notification-bell {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-main);
    cursor: pointer;
    position: relative;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.notification-bell:hover {
    background-color: var(--border);
}

/* Ringing Animation */
@keyframes ring {
    0% { transform: rotate(0); }
    10% { transform: rotate(15deg); }
    20% { transform: rotate(-10deg); }
    30% { transform: rotate(15deg); }
    40% { transform: rotate(-10deg); }
    50% { transform: rotate(0); }
    100% { transform: rotate(0); }
}

.notification-bell i.ringing {
    animation: ring 1.5s infinite ease-in-out;
    transform-origin: top center;
}

.notification-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 10px;
    height: 10px;
    background-color: var(--danger);
    border-radius: 50%;
    border: 2px solid var(--bg-card);
    display: none; /* Shown via JS */
}

.notification-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 350px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    margin-top: 10px;
}

.notification-dropdown.show {
    display: flex;
    animation: fadeInDropdown 0.2s ease;
}

@keyframes fadeInDropdown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.notification-header {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    font-weight: bold;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notification-list {
    max-height: 400px;
    overflow-y: auto;
}

.notification-item {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: var(--text-main);
    display: flex;
    gap: 15px;
    transition: background-color 0.2s;
}

.notification-item:hover {
    background-color: rgba(0,0,0,0.02);
}

[data-theme="dark"] .notification-item:hover {
    background-color: rgba(255,255,255,0.02);
}

.notification-item.unread {
    background-color: rgba(52, 152, 219, 0.05);
}

.notification-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: rgba(52, 152, 219, 0.1);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.notification-content {
    flex: 1;
}

.notification-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 5px;
}

.notification-message {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
}

.notification-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 5px;
}

.notification-empty {
    padding: 30px;
    text-align: center;
    color: var(--text-muted);
}

/* Auth Layout */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-main);
    position: relative;
    overflow: hidden;
}




.auth-card {
    width: 100%;
    max-width: 420px;
    background: #0e0e0e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    position: relative;
    z-index: 1;
    animation: cardEntrance 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    opacity: 0;
    transform: translateY(30px);
    color: #ffffff;
}

.auth-card h1, .auth-card h2, .auth-card h3, .auth-card h4 {
    color: #ffffff;
}

.auth-card p, .auth-card label {
    color: rgba(255, 255, 255, 0.8);
}

.auth-card a {
    color: #64b5f6;
}

@keyframes cardEntrance {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h1 {
    color: var(--primary);
    font-size: 28px;
    margin-bottom: 10px;
}

.auth-header p {
    color: var(--text-muted);
}

.demo-credentials {
    margin-top: 20px;
    padding: 15px;
    background-color: rgba(52, 152, 219, 0.1);
    border: 1px solid rgba(52, 152, 219, 0.2);
    border-radius: 8px;
    font-size: 14px;
}

.demo-credentials h4 {
    margin-bottom: 10px;
    color: var(--primary);
}

.demo-credentials p {
    margin-bottom: 5px;
    color: var(--text-main);
}

.text-center { text-align: center; }
.mt-3 { margin-top: 15px; }

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-value {
    font-size: 32px;
    font-weight: bold;
    margin: 10px 0;
    color: var(--primary);
}

/* Responsive Grids */
.grid-1-1 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.grid-4-col { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.grid-gap-15 { gap: 15px; }

/* Table Wrapper */
.table-responsive {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table th,
.table-responsive table td {
    white-space: nowrap;
}

/* Sidebar Unpinned State */
.sidebar.unpinned {
    width: 70px;
}
.sidebar.unpinned .nav-link span {
    display: none;
}
.sidebar.unpinned .sidebar-header span {
    display: none;
}
.sidebar.unpinned .nav-link {
    justify-content: center;
    padding: 15px 0;
}
.sidebar.unpinned .nav-link:hover {
    padding-left: 0;
}
.sidebar.unpinned .nav-link i {
    margin-right: 0 !important;
    font-size: 20px;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}
.sidebar-overlay.active {
    display: block;
}
.hamburger {
    display: none;
    font-size: 24px;
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    margin-right: 15px;
}
.pin-btn {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 16px;
    margin-left: auto;
    transition: transform 0.2s;
}
.pin-btn:hover {
    color: var(--text-main);
}
.sidebar.unpinned .pin-btn {
    margin: 0 auto;
}
.sidebar.unpinned .pin-btn i {
    transform: rotate(45deg);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .grid-1-1, .grid-1-2, .grid-2-1, .grid-3-col {
        grid-template-columns: 1fr !important;
    }
    .grid-4-col {
        grid-template-columns: 1fr 1fr !important;
    }
    .sidebar {
        position: fixed;
        left: -260px;
        height: 100vh;
        z-index: 1000;
        width: 260px !important;
    }
    .sidebar.mobile-open {
        left: 0;
    }
    .sidebar.mobile-open .nav-link span,
    .sidebar.mobile-open .sidebar-header span {
        display: inline;
    }
    .sidebar.mobile-open .nav-link {
        justify-content: flex-start;
        padding: 12px 20px;
    }
    .sidebar.mobile-open .nav-link i {
        margin-right: 8px !important;
        font-size: 16px;
    }
    .hamburger {
        display: block;
    }
    .pin-btn {
        display: none;
    }
    .content-area {
        padding: 15px;
    }
}

/* GAMIFICATION TOASTS */
.gamification-toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.gamification-toast {
    background: var(--card-bg);
    border-left: 5px solid #FFD700;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 15px;
    transform: translateX(120%);
    animation: slideInToast 0.5s forwards, fadeOutToast 0.5s 4s forwards;
    min-width: 250px;
}

@keyframes slideInToast {
    to { transform: translateX(0); }
}

@keyframes fadeOutToast {
    to { opacity: 0; transform: translateY(-20px); }
}

.gamification-toast-icon {
    font-size: 24px;
    color: #FFD700;
}

.gamification-toast-content strong {
    display: block;
    font-size: 14px;
    color: var(--text-main);
    margin-bottom: 2px;
}

.gamification-toast-content span {
    font-size: 12px;
    color: var(--text-muted);
}

/* GAMIFICATION WIDGET */
.gamification-widget {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.1), rgba(255, 152, 0, 0.1));
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
}

.gamification-widget::before {
    content: '';
    position: absolute;
    top: -50px; right: -50px;
    width: 150px; height: 150px;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.2) 0%, transparent 70%);
    border-radius: 50%;
}

.level-badge {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #FFD700, #FF9800);
    border-radius: 50%;
    margin: 0 auto 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #000;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(255, 215, 0, 0.3);
}

.level-badge span { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.level-badge strong { font-size: 32px; line-height: 1; }

.xp-bar-container {
    background: rgba(255,255,255,0.1);
    height: 10px;
    border-radius: 5px;
    margin: 15px 0 5px;
    overflow: hidden;
    position: relative;
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #FFD700, #4CAF50);
    transition: width 1s ease-out;
}

.badge-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 15px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
    transition: transform 0.2s;
}

.badge-item.locked {
    opacity: 0.5;
    filter: grayscale(100%);
}

.badge-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    margin-bottom: 10px;
    color: #fff;
}

/* GAMIFICATION MOBILE TWEAKS */
@media (max-width: 768px) {
    .badges-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
@media (max-width: 480px) {
    .badges-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
}

.modal-content {
    background-color: var(--bg-card);
    margin: 10% auto;
    padding: 25px;
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
    animation: modal-fade-in 0.3s;
}

@keyframes modal-fade-in {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.close {
    color: var(--text-muted);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: var(--text-main);
    text-decoration: none;
    cursor: pointer;
}
