:root {
    --primary: #2A9D8F;
    --primary-light: #E0F2F1;
    --primary-dark: #1D6F64;
    --accent: #E9C46A;
    --accent-red: #E76F51;

    --bg-body: #F4F7F9;
    --bg-surface: #FFFFFF;

    --text-main: #264653;
    --text-muted: #6B7C85;
    --border-light: #E1E8ED;

    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;

    --shadow-sm: 0 2px 8px rgba(42, 157, 143, 0.08);
    --shadow-md: 0 8px 24px rgba(42, 157, 143, 0.12);

    --font-main: 'Outfit', sans-serif;

    --transition: all 0.3s ease;
}

body.dark-theme {
    --bg-body: #121212;
    --bg-surface: #1E1E1E;
    --text-main: #E0E0E0;
    --text-muted: #B0B0B0;
    --border-light: #333333;
    --primary-light: #1D2D2B;
    /* Darker tint of primary */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, handle inside containers */
}

/* Utility */
.mobile-only {
    display: none !important;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    transition: var(--transition);
}

.sidebar.collapsed {
    width: 80px;
}

.sidebar.collapsed .brand h1,
.sidebar.collapsed .nav-links span,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .user-info {
    display: none;
    opacity: 0;
}

.icon-btn-ghost {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.icon-btn-ghost:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2.5rem;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar.collapsed .brand {
    justify-content: center;
}

/* Collapsed state behavior */
.sidebar.collapsed .brand-logo {
    display: flex;
    /* Keep logo visible */
    gap: 0;
}

.sidebar.collapsed .brand-logo h1 {
    display: none;
}

.sidebar.collapsed .brand {
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

/* In collapsed mode, we want the toggle button to be centered */
.sidebar.collapsed #sidebar-toggle {
    margin: 0 auto;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.nav-links {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    /* Prevent content jumping when scrollbar appears */

    /* Modern Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}

.nav-links::-webkit-scrollbar {
    width: 4px;
}

.nav-links::-webkit-scrollbar-track {
    background: transparent;
}

.nav-links::-webkit-scrollbar-thumb {
    background-color: var(--border-light);
    border-radius: 4px;
}

.nav-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin: 1.5rem 0 0.5rem 12px;
    font-weight: 600;
    white-space: nowrap;
}

.nav-item {
    margin-bottom: 4px;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.sidebar.collapsed .nav-item a {
    justify-content: center;
    padding: 12px 0;
}

.nav-item a i {
    font-size: 1.25rem;
    min-width: 24px;
    /* Ensure icon doesn't shrink */
}

.nav-item:hover a,
.nav-item.active a {
    background-color: var(--primary-light);
    color: var(--primary-dark);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
    overflow: hidden;
    /* Hide overflow content during collapse */
}

.user-profile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.user-info .name {
    font-size: 0.9rem;
    font-weight: 600;
}

.user-info .role {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    background-color: transparent;
    /* Clean look */
}

#page-title {
    font-size: 1.75rem;
    font-weight: 600;
}

.actions {
    display: flex;
    gap: 1rem;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
    background: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--bg-surface);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* Breadcrumbs */
.breadcrumbs {
    padding: 0 2rem 1.5rem 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.breadcrumb-item:hover {
    color: var(--primary);
}

.breadcrumb-item:last-child {
    color: var(--text-main);
    font-weight: 600;
    cursor: default;
    pointer-events: none;
}

.breadcrumb-separator {
    font-size: 0.8rem;
    color: var(--border-light);
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 0 2rem 2rem 2rem;
}

/* Content Blocks & Cards */
.animate-in {
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.welcome-banner {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 2rem;
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.welcome-text h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--bg-surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    border: 1px solid transparent;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0.5rem 0;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--border-light);
    border-radius: 4px;
    margin-top: 1rem;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
}

/* Unit Cards */
.units-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.unit-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    cursor: pointer;
}

.unit-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.unit-image {
    height: 140px;
    background-color: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
}

.unit-image i {
    font-size: 3rem;
    color: var(--primary);
    opacity: 0.5;
}

.unit-content {
    padding: 1.5rem;
}

.unit-tag {
    display: inline-block;
    padding: 4px 12px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.quiz-container {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
    box-shadow: var(--shadow-sm);
}

.quiz-question {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    font-weight: 500;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.quiz-option {
    padding: 1rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.quiz-option:hover {
    background-color: var(--primary-light);
    border-color: var(--primary);
}

.quiz-option.selected {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}


/* Streak Widget */
.streak-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.fire-icon {
    font-size: 2.5rem;
    transition: all 0.5s ease;
    margin-bottom: 0.5rem;
}

.fire-icon.active {
    color: #FF5722;
    /* Vivid Orange/Red */
    filter: drop-shadow(0 0 10px rgba(255, 87, 34, 0.6));
    animation: flame-pulse 1.5s infinite alternate;
}

.fire-icon.dull {
    color: var(--text-muted);
    opacity: 0.4;
    filter: grayscale(100%);
}

@keyframes flame-pulse {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 8px rgba(255, 87, 34, 0.4));
    }

    100% {
        transform: scale(1.15);
        filter: drop-shadow(0 0 18px rgba(255, 87, 34, 0.8));
    }
}

.streak-count {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.streak-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Unit Content View */
.unit-view-container {
    display: flex;
    height: calc(100vh - 80px);
    /* Subtract header */
    gap: 1.5rem;
    overflow: hidden;
}

.content-sidebar {
    width: 280px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.lesson-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.lesson-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    margin-bottom: 4px;
}

.lesson-item:hover {
    background: var(--bg-body);
}

.lesson-item.active {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
}

.lesson-item.completed {
    color: var(--text-muted);
}

.lesson-icon {
    font-size: 1.2rem;
}

.content-main {
    flex: 1;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 3rem;
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
    position: relative;
    /* Green accent borderline as requested */
    border: 2px solid var(--primary);
    display: flex;
    flex-direction: column;
    min-height: 60vh;
}

.content-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.content-body {
    line-height: 1.8;
    font-size: 1.1rem;
    color: var(--text-main);
    flex: 1;
    /* Pushes navigation to bottom */
}

.content-navigation {
    display: flex;
    justify-content: space-between;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-light);
    /* Ensure it stays at bottom if content is short */
    margin-top: auto;
}

/* Make sure the main content area doesn't double scroll with the page */
.main-content {
    overflow: hidden;
}

#content-area {
    /* For unit view, we might want to remove padding or adjust it so the split view fits well */
    height: 100%;
}

/* Back Button Style */
.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 50px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}

.btn-back:hover {
    color: var(--primary);
    border-color: var(--primary);
    transform: translateX(-4px);
    box-shadow: var(--shadow-md);
}

.btn-back i {
    font-size: 1.1rem;
}

.btn-back:hover i {
    transform: translateY(-2px);
}

/* =========================================
   Responsive Design
   ========================================= */

/* Tablet View (max-width: 1024px) */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .units-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

/* Mobile View (max-width: 768px) */
@media (max-width: 768px) {

    /* Layout Adjustments */
    .app-container {
        position: relative;
    }

    /* Mobile Sidebar: Fixed Overlay */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100vh;
        z-index: 1000;
        width: 260px;
        box-shadow: var(--shadow-md);
        transform: translateX(0);
        /* Open by default status, will use .collapsed to hide */
    }

    /* When collapsed on mobile, move off-screen completely */
    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 260px;
        /* Maintain width so it doesn't shrink during transition */
    }

    /* Override desktop collapsed styles which hide internal elements */
    .sidebar.collapsed .brand h1,
    .sidebar.collapsed .nav-links span,
    .sidebar.collapsed .nav-label,
    .sidebar.collapsed .user-info {
        display: block;
        opacity: 1;
    }

    .sidebar.collapsed .brand-logo {
        display: flex;
    }

    /* Toggle Button Visibility Override */
    .mobile-only {
        display: flex !important;
    }

    /* Main Content Styling */
    .main-content {
        width: 100%;
    }

    .top-bar {
        padding: 0 1rem;
        gap: 1rem;
    }

    #page-title {
        font-size: 1.25rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .content-area {
        padding: 1rem;
    }

    /* Dashboard items */
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .welcome-banner {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
        padding: 1.5rem;
    }

    .welcome-icon {
        display: none;
    }

    /* Unit View Stack */
    .unit-view-container {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    .content-sidebar {
        width: 100%;
        height: auto;
        max-height: 250px;
        margin-bottom: 1rem;
    }

    .content-main {
        min-height: auto;
        height: auto;
        border: none;
        padding: 1.5rem;
    }

    /* Exams */
    .exam-start-container {
        margin: 1rem auto;
    }

    .breadcrumbs {
        padding: 0 1rem 1rem 1rem;
        font-size: 0.8rem;
        flex-wrap: wrap;
    }
}

/* =========================================
   Settings View Styles
   ========================================= */

.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
}

.form-input {
    width: 100%;
    padding: 12px;
    background: var(--bg-body);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 1rem;
    font-family: var(--font-main);
    transition: var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.2);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-light);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

/* Danger Button */
.btn-danger {
    background-color: #ffebee;
    color: var(--accent-red);
    border: 1px solid var(--accent-red);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-danger:hover {
    background-color: var(--accent-red);
    color: white;
}

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-light);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--bg-body);
    color: var(--text-main);
    border-color: var(--text-muted);
}

/* =========================================
   Onboarding Modal Styles
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    /* controlled by JS, usually none */
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.onboarding-content {
    background: var(--bg-surface);
    width: 90%;
    max-width: 500px;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    text-align: center;
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.onboarding-step {
    display: none;
    flex-direction: column;
    align-items: center;
}

.onboarding-step.active {
    display: flex;
}

.onboarding-step h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.onboarding-step p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    line-height: 1.5;
}

.step-indicator {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 2rem;
}

.step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--border-light);
    transition: var(--transition);
}

.step-dot.active {
    background-color: var(--primary);
    width: 24px;
    border-radius: 4px;
}

/* Choice Grid for Theme Selection */
.choice-grid {
    display: flex;
    gap: 1rem;
    width: 100%;
    margin-bottom: 2rem;
}

.choice-card {
    flex: 1;
    padding: 1.5rem;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.choice-card i {
    font-size: 2rem;
    color: var(--text-muted);
}

.choice-card:hover {
    border-color: var(--primary);
    background-color: var(--bg-body);
}

.choice-card.selected {
    border-color: var(--primary);
    background-color: var(--primary-light);
}

.choice-card.selected i,
.choice-card.selected div {
    color: var(--primary-dark);
    font-weight: 600;
}
