/* Brand Font */
@font-face {
    font-family: "Ivy Mode";
    src: url("../fonts/ivy-mode-light.eot");
    src:
        url("../fonts/ivy-mode-light.eot?#iefix") format("embedded-opentype"),
        url("../fonts/ivy-mode-light.woff2") format("woff2"),
        url("../fonts/ivy-mode-light.woff") format("woff");
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

/* Design Tokens */
:root {
    --font-sans:
        "Manrope", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
        sans-serif;
    --font-brand: "Ivy Mode", Georgia, serif;
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 4rem;

    --color-bg: #fffcf8;
    --color-surface: #f7f2ec;
    --color-border: #e4dbd0;
    --color-text: #36281d;
    --color-text-muted: #8c7a6b;
    --color-primary: #36281d;
    --color-secondary: #d5b5a3;

    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;

    /* Font Size Scale */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.25rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;

    /* Z-Index Layers */
    --z-base: 1;
    --z-topbar: 100;
    --z-nav-dropdown: 101;
    --z-overlay: 500;
    --z-sidebar: 600;

    /* Colors — Semantic */
    --color-black: #000000;
    --color-white: #ffffff;
    --color-overlay: rgba(54, 40, 29, 0.5);
    --color-hover-light: rgba(54, 40, 29, 0.03);
    --color-active-light: rgba(54, 40, 29, 0.07);

    /* State Colors */
    --color-success: #2d8a4e;

    /* Button Colors */
    --color-primary-hover: #4a3828;

    /* Layout */
    --sidebar-width: 300px;
    --topbar-height: 64px;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #1a1410;
        --color-surface: #2a2118;
        --color-border: #3d3128;
        --color-text: #f2ece6;
        --color-text-muted: #a8998a;
        --color-primary: #d4c4b0;

        --color-black: #000000;
        --color-white: #ffffff;
        --color-overlay: rgba(0, 0, 0, 0.7);
        --color-hover-light: rgba(255, 255, 255, 0.04);
        --color-active-light: rgba(255, 255, 255, 0.08);

        --color-success: #4ade80;
        --color-primary-hover: #e8ddd2;
    }
}

/* Base Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
    letter-spacing: inherit;
}

body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    letter-spacing: 0.025em;
}

/* Focus Styles */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Remove outline for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* Top Navigation Bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 var(--space-lg);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.logo {
    font-family: var(--font-brand);
    font-weight: 300;
    font-size: var(--text-xl);
    letter-spacing: 0.035em;
    color: var(--color-text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.logo-icon {
    width: 1.4em;
    height: 1.4em;
    fill: currentColor;
    flex-shrink: 0;
}

/* Desktop nav (inside topbar) */
.nav-links--desktop {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    list-style: none;
}

/* Mobile nav (below topbar, in document flow) */
.nav-links--mobile {
    display: none;
}

.nav-link {
    color: var(--color-text-muted);
    text-decoration: none;
    transition: color 0.15s;
}

.nav-link:hover {
    color: var(--color-text);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: 500;
}

.hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-sm);
}

.hamburger span {
    width: 24px;
    height: 2px;
    background: var(--color-text);
    transition: all 0.3s;
    transform-origin: center;
}

.hamburger.active span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

/* Main Layout */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: calc(100vh - var(--topbar-height));
}

/* Sidebar */
.sidebar {
    background-color: var(--color-surface);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
    overscroll-behavior: contain;
    height: calc(100vh - var(--topbar-height));
    /* Scroll shadow indicators */
    background-image:
        linear-gradient(var(--color-surface) 30%, transparent),
        linear-gradient(transparent, var(--color-surface) 70%),
        radial-gradient(farthest-side at 50% 0,
            var(--color-overlay),
            transparent),
        radial-gradient(farthest-side at 50% 100%,
            var(--color-overlay),
            transparent);
    background-position:
        0 0,
        0 100%,
        0 0,
        0 100%;
    background-repeat: no-repeat;
    background-size:
        100% 40px,
        100% 40px,
        100% 14px,
        100% 14px;
    background-attachment: local, local, scroll, scroll;
    position: sticky;
    top: var(--topbar-height);
}

.course-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

.course-label {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-sm);
}

.course-title {
    font-size: var(--text-base);
    font-weight: 600;
    margin-bottom: var(--space-md);
    line-height: 1.4;
}

.course-progress {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.progress-text {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--color-primary);
    transition: width 0.3s;
}

/* Lesson Navigation */
.lesson-nav {
    padding: var(--space-md) 0;
}

.lesson-section {
    border-bottom: 1px solid var(--color-border);
}

.lesson-section summary {
    list-style: none;
    cursor: pointer;
    padding: var(--space-sm) var(--space-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
}

.lesson-section summary::-webkit-details-marker {
    display: none;
}

.lesson-section summary::before {
    content: "▶";
    flex-shrink: 0;
    width: 1rem;
    line-height: 1.6;
    text-align: center;
    transition: transform 0.2s;
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.lesson-section[open] summary::before {
    transform: rotate(90deg);
}

.section-number {
    flex: 1;
    min-width: 0;
    font-size: var(--text-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-primary);
}

.section-progress {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.lesson-list {
    list-style: none;
    padding: 0;
}

.lesson-item {
    transition: background 0.15s;
    /* color: var(--color-text-muted); */
    color: var(--color-primary);
}

.lesson-item a {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    padding-left: calc(var(--space-lg) + var(--space-md) + var(--space-sm));
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.lesson-item:hover {
    background: var(--color-hover-light);
}

.lesson-item.active {
    /* background: var(--color-active-light); */
    background-color: #e6dbd0;
    font-weight: 500;
}

.lesson-status {
    width: 20px;
    text-align: center;
    line-height: 1.6;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.lesson-item.completed .lesson-status {
    color: var(--color-primary);
}

.lesson-item.active .lesson-status {
    color: var(--color-primary);
}

.lesson-item .lesson-title {
    flex: 1;
    font-size: var(--text-sm);
}

.lesson-duration {
    font-size: var(--text-xs);
    line-height: 1.6;
    color: var(--color-text-muted);
    flex-shrink: 0;
    margin-top: 3px;
}

.icon-pdf {
    width: 1em;
    height: 1em;
    fill: currentColor;
    vertical-align: middle;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--color-overlay);
    z-index: var(--z-overlay);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* Main Content */
.content {
    padding: var(--space-xl) var(--space-lg);
    overflow-y: auto;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    background-color: #fff;
}

.course-nav-mobile {
    display: none;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
    border: 1px solid var(--color-border);
}

.course-nav-mobile-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.course-nav-mobile-info .course-title {
    font-size: var(--text-sm);
    margin-bottom: 0;
}

.course-nav-mobile-info .course-label {
    margin-bottom: 0;
}

.sidebar-toggle {
    padding: var(--space-sm) var(--space-md);
    background: var(--color-primary);
    color: var(--color-bg);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

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

/* Video Player */
.video-player {
    margin-bottom: var(--space-xl);
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--color-black);
}

.video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* Lesson Info */
.lesson-info {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-xl);
    gap: var(--space-sm) var(--space-lg);
}

.lesson-info-left {
    flex: 1;
}

.lesson-heading {
    font-family: var(--font-brand);
    font-size: var(--text-2xl);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0;
}

.lesson-meta {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}

.lesson-info-right {
    display: flex;
    gap: var(--space-md);
    flex-shrink: 0;
}

.lesson-info-right form {
    display: flex;
}

.btn-save,
.btn-next {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-lg);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    font-size: var(--text-sm);
}

.btn-next {
    background: var(--color-primary);
    color: var(--color-secondary);
    border: 3px solid var(--color-secondary);
    /* border-radius: var(--radius-lg); */
    text-decoration: none;
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--text-sm);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 2px 8px rgba(0, 0, 0, 0.15);
}

.btn-save .icon-circle-check {
    /* color: var(--color-success); */
    color: var(--color-secondary);
    font-size: var(--text-xl);
}

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

.btn-save--completed {
    /* background: var(--color-secondary); */
    /* color: #fff; */
    /* border-color: var(--color-success); */
    border: 1px solid var(--color-border);

}

.btn-save--completed:hover .icon-circle-check {
    color: #fff;
}

.btn-save--completed:hover {
    opacity: 0.9;
    color: #fff;
    background: var(--color-secondary);
}

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

/* Lead capture */
.lead-capture {
    margin-top: var(--space-lg);
    padding: var(--space-lg);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--color-secondary);
}

.lead-capture-link {
    background: none;
    border: none;
    color: var(--color-primary);
    font-family: inherit;
    font-size: var(--text-base);
    cursor: pointer;
    padding: 0;
    text-align: left;
    line-height: 1.6;
}

.lead-capture-link:hover {
    color: var(--color-secondary);
}

.lead-capture-confirmed {
    color: var(--color-primary);
    font-size: var(--text-base);
    margin: 0;
    line-height: 1.6;
}

/* Tabs */
.tabs {
    display: flex;
    gap: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-xl);
}

.tab {
    padding: var(--space-md) 0;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: -1px;
}

.tab:hover {
    color: var(--color-text);
}

.tab.active {
    color: var(--color-text);
    border-bottom-color: var(--color-primary);
}

/* Tab Content */
.tab-content {
    min-height: 400px;
}

.tab-panel {
    display: none;
    animation: fadeIn 0.2s ease;
}

.tab-panel.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

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

.comments-section.active {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

#comments-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

.comment {
    display: flex;
    gap: var(--space-md);
}

.comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: 500;
    flex-shrink: 0;
    overflow: hidden;
}

.comment-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.comment-body {
    flex: 1;
}

.comment-header {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
    margin-bottom: var(--space-xs);
}

.comment-author {
    font-weight: 500;
    font-size: var(--text-sm);
}

.comment-time {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.comment-text {
    margin-bottom: var(--space-sm);
    font-size: var(--text-sm);
    line-height: 1.6;
}

.comment-actions {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.comment-action {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    cursor: pointer;
    padding: 0;
    transition: color 0.15s;
}

.comment-action:hover {
    color: var(--color-text);
}

.comment-action--delete:hover {
    color: #c0392b;
}

.comment-actions form {
    display: flex;
}

/* Threaded replies */
.comment--reply {
    margin-top: var(--space-md);
}

.comment-avatar--sm {
    width: 32px;
    height: 32px;
    font-size: var(--text-xs);
}

/* Comment form */
.comment-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.comment-form-row {
    display: flex;
    gap: var(--space-md);
    align-items: flex-start;
}

.comment-form-row textarea {
    flex: 1;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: var(--space-sm) var(--space-md);
    font-family: inherit;
    font-size: var(--text-sm);
    line-height: 1.6;
    resize: vertical;
    background: var(--color-bg);
    color: var(--color-text);
}

.comment-form-row textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.comment-form-actions {
    display: flex;
    justify-content: flex-end;
}

.btn-comment {
    background: var(--color-primary);
    color: var(--color-bg);
    border: none;
    border-radius: 8px;
    padding: var(--space-xs) var(--space-lg);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}

.btn-comment:hover {
    opacity: 0.9;
}

/* Reply form — hidden until toggled */
.comment-form--reply {
    display: none;
    margin-top: var(--space-md);
}

.comment-form--reply.open {
    display: flex;
}

/* Login Page */
.login-page {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--topbar-height));
    padding: var(--space-xl);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-2xl) var(--space-xl);
}

.login-title {
    font-family: var(--font-brand);
    font-weight: 300;
    font-size: var(--text-2xl);
    text-align: center;
    margin-bottom: var(--space-xs);
}

.login-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    margin-bottom: var(--space-xl);
}

.login-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--text-sm);
    margin-bottom: var(--space-lg);
}

@media (prefers-color-scheme: dark) {
    .login-error {
        background: #451a1a;
        color: #fca5a5;
        border-color: #7f1d1d;
    }
}

.login-info {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--text-sm);
    margin-bottom: var(--space-lg);
}

@media (prefers-color-scheme: dark) {
    .login-info {
        background: #1e2a4a;
        color: #93c5fd;
        border-color: #1e3a5f;
    }
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: var(--text-sm);
    color: var(--color-text);
    cursor: pointer;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.form-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text);
}

.form-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.15s;
}

.form-input:hover {
    border-color: var(--color-text-muted);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(54, 40, 29, 0.1);
}

@media (prefers-color-scheme: dark) {
    .form-input:focus {
        box-shadow: 0 0 0 3px rgba(212, 196, 176, 0.15);
    }
}

.login-button {
    width: 100%;
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-primary);
    color: var(--color-bg);
    border: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

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

/* Shared: Tablet + Mobile (sidebar off-canvas, hamburger visible) */
@media (max-width: 1023px) {
    .topbar {
        padding: 0 var(--space-lg);
    }

    .hamburger {
        display: flex;
    }

    /* Hide desktop nav, show mobile nav element */
    .nav-links--desktop {
        display: none;
    }

    .nav-links--mobile {
        display: block;
        max-height: 0;
        overflow: hidden;
        background: var(--color-bg);
        border-bottom: 1px solid transparent;
        transition:
            max-height 0.3s ease,
            border-color 0.3s ease;
    }

    .nav-links--mobile.open {
        max-height: 300px;
        border-bottom-color: var(--color-border);
    }

    .nav-links--mobile .nav-link {
        display: block;
        padding: var(--space-md) var(--space-lg);
        border-bottom: 1px solid var(--color-border);
    }

    .nav-links--mobile .nav-link:last-of-type {
        border-bottom: none;
    }

    .nav-links--mobile .user-avatar {
        margin: var(--space-md) var(--space-lg);
    }

    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        width: min(var(--sidebar-width), 90vw);
        height: calc(100vh - var(--topbar-height));
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: var(--z-sidebar);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
    }

    .course-nav-mobile {
        display: flex;
    }

    .content {
        padding: var(--space-lg);
    }

    .lesson-info {
        flex-direction: column;
    }

    .lesson-info-right {
        margin-top: var(--space-sm);
        padding-top: var(--space-sm);
        width: 100%;
    }

    .btn-save,
    .btn-next {
        flex: 1;
    }

    .tabs {
        overflow-x: auto;
    }

    .tab {
        white-space: nowrap;
    }
}

/* Tablet Overrides */
@media (max-width: 1023px) and (min-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    .lesson-heading {
        font-size: var(--text-xl);
    }
}

/* Mobile Overrides */
@media (max-width: 767px) {
    :root {
        --sidebar-width: 320px;
    }

    .topbar .logo {
        font-size: var(--text-lg);
    }

    .lesson-heading {
        font-size: var(--text-lg);
    }

    .lesson-meta .lesson-meta-sep {
        display: none;
    }

    .lesson-meta .lesson-meta-duration {
        margin-top: -0.5em;
    }

    .content {
        padding: var(--space-md);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}