/* ==========================================================================
   EduSpace — E-learning Stylesheet
   Light, modern, simple. Bootstrap 5 (grid-free) + custom nested CSS
   Structure: section > .section-header / .section-content > .card-list > .card-item
   Panel: .card-wrapper > .card-title + .card-content
   ========================================================================== */

:root {
    /* -- Brand -- */
    --theme-color: #4f46e5;
    --theme-color-hover: #4338ca;
    --theme-soft: #eef2ff;
    --theme-softer: #f5f7ff;

    /* -- Text & Surface -- */
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;
    --bg-color: #f5f7fb;
    --white: #ffffff;
    --border-color: #e7e9f0;
    --border-soft: #f0f2f7;

    /* -- Tones (ใช้ผ่านคลาส .is-{tone} ที่ตั้ง --tone / --tone-soft ให้ลูก) -- */
    --tone-indigo: #4f46e5;
    --tone-indigo-soft: #eef2ff;
    --tone-teal: #0d9488;
    --tone-teal-soft: #ecfdf8;
    --tone-rose: #e11d48;
    --tone-rose-soft: #fff1f3;
    --tone-amber: #d97706;
    --tone-amber-soft: #fff8e6;
    --tone-sky: #0284c7;
    --tone-sky-soft: #eef8ff;
    --tone-violet: #7c3aed;
    --tone-violet-soft: #f4f0ff;
    --tone-emerald: #059669;
    --tone-emerald-soft: #ecfdf3;
    --tone-orange: #ea580c;
    --tone-orange-soft: #fff4ec;
    --tone-green: #16a34a;
    --tone-green-soft: #edfcf2;
    --tone-red: #dc2626;
    --tone-red-soft: #fef1f1;
    --tone-muted: #6b7280;
    --tone-muted-soft: #f2f4f7;

    /* -- Typography -- */
    --font-body: "Noto Sans Thai", "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --fs-xs: 0.75rem;
    --fs-sm: 0.8125rem;
    --fs-base: 0.9375rem;
    --fs-md: 1.0625rem;
    --fs-lg: 1.25rem;
    --fs-xl: 1.5rem;
    --fs-xxl: 2rem;
    --fs-title: 1.625rem;
    --fw-md: 500;
    --fw-lg: 600;
    --fw-bold: 700;

    /* -- Radius & Shadow -- */
    --rd-sm: 8px;
    --rd-md: 12px;
    --rd-lg: 16px;
    --rd-xl: 22px;
    --rd-pill: 999px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 10px 30px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 20px 50px rgba(16, 24, 40, 0.14);

    /* -- Layout -- */
    --sidebar-width: 256px;
    --topbar-height: 64px;
    --bottom-nav-height: 64px;
    --max-width: 1320px;
    --page-pad: 28px;
}

/* ==========================================================================
   Tone Classes
   ========================================================================== */

.is-indigo { --tone: var(--tone-indigo); --tone-soft: var(--tone-indigo-soft); }
.is-teal { --tone: var(--tone-teal); --tone-soft: var(--tone-teal-soft); }
.is-rose { --tone: var(--tone-rose); --tone-soft: var(--tone-rose-soft); }
.is-amber { --tone: var(--tone-amber); --tone-soft: var(--tone-amber-soft); }
.is-sky { --tone: var(--tone-sky); --tone-soft: var(--tone-sky-soft); }
.is-violet { --tone: var(--tone-violet); --tone-soft: var(--tone-violet-soft); }
.is-emerald { --tone: var(--tone-emerald); --tone-soft: var(--tone-emerald-soft); }
.is-orange { --tone: var(--tone-orange); --tone-soft: var(--tone-orange-soft); }
.is-green { --tone: var(--tone-green); --tone-soft: var(--tone-green-soft); }
.is-red { --tone: var(--tone-red); --tone-soft: var(--tone-red-soft); }
.is-muted { --tone: var(--tone-muted); --tone-soft: var(--tone-muted-soft); }

/* ==========================================================================
   Base
   ========================================================================== */

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: var(--fs-base);
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg-color);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--theme-color);
    text-decoration: none;

    &:hover {
        color: var(--theme-color-hover);
    }
}

h1, h2, h3, h4, h5 {
    font-weight: var(--fw-bold);
    color: var(--text-color);
    line-height: 1.35;
}

img,
video {
    max-width: 100%;
}

code {
    color: var(--theme-color);
    background: var(--theme-soft);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 0.85em;
}

.text-muted {
    color: var(--text-muted) !important;
}

/* ==========================================================================
   Bootstrap Overrides (ปุ่ม / ฟอร์ม / dropdown / modal ให้เข้าธีม)
   ========================================================================== */

.btn {
    --bs-btn-padding-x: 16px;
    --bs-btn-padding-y: 9px;
    --bs-btn-font-size: var(--fs-base);
    --bs-btn-font-weight: var(--fw-lg);
    --bs-btn-border-radius: var(--rd-md);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;

    &.btn-sm {
        --bs-btn-padding-x: 12px;
        --bs-btn-padding-y: 6px;
        --bs-btn-font-size: var(--fs-sm);
        --bs-btn-border-radius: var(--rd-sm);
    }

    &.btn-lg {
        --bs-btn-padding-x: 22px;
        --bs-btn-padding-y: 12px;
        --bs-btn-font-size: var(--fs-md);
    }
}

.btn-primary {
    --bs-btn-bg: var(--theme-color);
    --bs-btn-border-color: var(--theme-color);
    --bs-btn-hover-bg: var(--theme-color-hover);
    --bs-btn-hover-border-color: var(--theme-color-hover);
    --bs-btn-active-bg: var(--theme-color-hover);
    --bs-btn-active-border-color: var(--theme-color-hover);
    --bs-btn-disabled-bg: var(--theme-color);
    --bs-btn-disabled-border-color: var(--theme-color);

    box-shadow: 0 6px 14px -6px rgba(79, 70, 229, 0.6);
}

.btn-light {
    --bs-btn-bg: var(--white);
    --bs-btn-border-color: var(--border-color);
    --bs-btn-color: var(--text-color);
    --bs-btn-hover-bg: var(--theme-softer);
    --bs-btn-hover-border-color: #d6dbf5;
    --bs-btn-hover-color: var(--theme-color);
    --bs-btn-active-bg: var(--theme-soft);
    --bs-btn-active-border-color: #c7d2fe;
}

.btn-soft {
    --bs-btn-bg: var(--theme-soft);
    --bs-btn-border-color: var(--theme-soft);
    --bs-btn-color: var(--theme-color);
    --bs-btn-hover-bg: #e0e7ff;
    --bs-btn-hover-border-color: #e0e7ff;
    --bs-btn-hover-color: var(--theme-color-hover);
    --bs-btn-active-bg: #c7d2fe;
    --bs-btn-active-border-color: #c7d2fe;
}

.btn-success {
    --bs-btn-bg: var(--tone-green);
    --bs-btn-border-color: var(--tone-green);
}

.btn-danger-soft {
    --bs-btn-bg: var(--tone-red-soft);
    --bs-btn-border-color: var(--tone-red-soft);
    --bs-btn-color: var(--tone-red);
    --bs-btn-hover-bg: #fde2e2;
    --bs-btn-hover-border-color: #fde2e2;
    --bs-btn-hover-color: #b91c1c;
}

.btn-icon {
    --bs-btn-padding-x: 0;
    --bs-btn-padding-y: 0;

    width: 36px;
    height: 36px;
    flex-shrink: 0;

    &.btn-sm {
        width: 30px;
        height: 30px;
    }
}

.form-label {
    font-size: var(--fs-sm);
    font-weight: var(--fw-lg);
    color: var(--text-color);
    margin-bottom: 6px;
}

.form-control,
.form-select {
    font-size: var(--fs-base);
    border-color: var(--border-color);
    border-radius: var(--rd-md);
    padding: 10px 14px;
    color: var(--text-color);

    &:focus {
        border-color: #a5b4fc;
        box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.14);
    }
}

.form-select {
    padding-right: 36px;
}

.form-control-sm,
.form-select-sm {
    padding: 6px 10px;
    font-size: var(--fs-sm);
    border-radius: var(--rd-sm);
}

.form-select-sm {
    padding-right: 30px;
}

.form-check-input {
    &:checked {
        background-color: var(--theme-color);
        border-color: var(--theme-color);
    }

    &:focus {
        box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.14);
        border-color: #a5b4fc;
    }
}

.form-hint {
    display: block;
    margin-top: 6px;
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

.dropdown-menu {
    --bs-dropdown-border-color: var(--border-color);
    --bs-dropdown-border-radius: var(--rd-md);
    --bs-dropdown-link-active-bg: var(--theme-soft);
    --bs-dropdown-link-active-color: var(--theme-color);
    --bs-dropdown-font-size: var(--fs-base);

    padding: 6px;
    box-shadow: var(--shadow-md);

    .dropdown-item {
        display: flex;
        align-items: center;
        gap: 10px;
        border-radius: var(--rd-sm);
        padding: 8px 12px;

        &.is-danger {
            color: var(--tone-red);
        }
    }
}

.modal {
    --bs-modal-border-radius: var(--rd-lg);
    --bs-modal-border-color: transparent;
    --bs-modal-padding: 24px;
    --bs-modal-header-padding: 20px 24px;

    .modal-header {
        border-bottom-color: var(--border-soft);

        .modal-title {
            font-size: var(--fs-lg);
            font-weight: var(--fw-bold);
        }
    }

    .modal-footer {
        border-top-color: var(--border-soft);
        gap: 8px;
    }
}

/* ==========================================================================
   App Shell: Sidebar + Topbar + Main + Bottom Nav
   ========================================================================== */

.app-body {
    min-height: 100vh;
    padding-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;

    @media (max-width: 992px) {
        & {
            padding-left: 0;
        }
    }

    @media (max-width: 768px) {
        & {
            padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
        }
    }
}

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1045;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--white);
    border-right: 1px solid var(--border-color);
    transition: transform 0.25s ease;

    .sidebar-brand {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        height: var(--topbar-height);
        padding: 0 18px;
        border-bottom: 1px solid var(--border-soft);
    }

    .brand-link {
        display: flex;
        align-items: center;
        gap: 10px;
        min-width: 0;
        color: var(--text-color);
    }

    .brand-text {
        display: flex;
        flex-direction: column;
        min-width: 0;
        line-height: 1.25;

        strong {
            font-size: var(--fs-md);
            font-weight: var(--fw-bold);
        }

        small {
            font-size: var(--fs-xs);
            color: var(--text-muted);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }

    .sidebar-close {
        display: none;
        border: 0;
        background: none;
        font-size: 1.1rem;
        color: var(--text-muted);
        padding: 6px;
    }

    .sidebar-nav {
        flex: 1;
        overflow-y: auto;
        padding: 16px 14px;
    }

    .nav-title {
        margin: 18px 10px 8px;
        font-size: var(--fs-xs);
        font-weight: var(--fw-lg);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--text-faint);
    }

    .nav-list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: grid;
        gap: 2px;
    }

    .nav-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        border-radius: var(--rd-md);
        color: var(--text-muted);
        font-weight: var(--fw-md);
        transition: background 0.15s, color 0.15s;

        .bi {
            font-size: 1.15rem;
        }

        span {
            flex: 1;
        }

        &:hover {
            background: var(--bg-color);
            color: var(--text-color);
        }

        &.active {
            background: var(--theme-soft);
            color: var(--theme-color);
            font-weight: var(--fw-lg);
        }
    }

    .nav-badge {
        font-style: normal;
        font-size: var(--fs-xs);
        font-weight: var(--fw-bold);
        color: var(--white);
        background: var(--tone-rose);
        border-radius: var(--rd-pill);
        padding: 0 7px;
        line-height: 20px;
    }

    .sidebar-user {
        display: flex;
        align-items: center;
        gap: 10px;
        margin: 12px;
        padding: 10px 12px;
        border-radius: var(--rd-md);
        background: var(--bg-color);
        color: var(--text-color);

        &:hover {
            background: var(--theme-softer);
        }
    }

    .user-text {
        display: flex;
        flex-direction: column;
        min-width: 0;
        line-height: 1.3;

        strong {
            font-size: var(--fs-sm);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        small {
            font-size: var(--fs-xs);
            color: var(--text-muted);
        }
    }

    @media (max-width: 992px) {
        & {
            transform: translateX(-100%);
        }

        &.active {
            transform: none;
            box-shadow: var(--shadow-lg);
        }

        .sidebar-close {
            display: block;
        }
    }
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(17, 24, 39, 0.35);
    backdrop-filter: blur(2px);

    &.active {
        display: block;
    }
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 var(--page-pad);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border-color);

    .topbar-toggle {
        display: none;
        border: 0;
        background: none;
        font-size: 1.4rem;
        color: var(--text-color);
        padding: 4px;
    }

    .topbar-title {
        flex: 1;
        min-width: 0;

        strong {
            display: block;
            font-size: var(--fs-md);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }

    .topbar-actions {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .topbar-button {
        position: relative;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        height: 40px;
        min-width: 40px;
        justify-content: center;
        padding: 0 10px;
        border: 1px solid transparent;
        border-radius: var(--rd-md);
        background: none;
        color: var(--text-muted);
        font-weight: var(--fw-lg);
        font-size: var(--fs-sm);

        .bi {
            font-size: 1.2rem;
        }

        &:hover,
        &[aria-expanded="true"] {
            background: var(--bg-color);
            color: var(--text-color);
        }
    }

    .button-badge {
        position: absolute;
        top: 3px;
        left: 50%;
        margin-left: 3px;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: var(--rd-pill);
        background: var(--tone-rose);
        color: var(--white);
        font-style: normal;
        font-size: 0.6875rem;
        font-weight: var(--fw-bold);
        line-height: 18px;
        border: 2px solid var(--white);
        box-sizing: content-box;
    }

    .topbar-user {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 4px 8px 4px 4px;
        border: 1px solid var(--border-color);
        border-radius: var(--rd-pill);
        background: var(--white);
        font-weight: var(--fw-lg);
        font-size: var(--fs-sm);
        color: var(--text-color);

        .user-caret {
            font-size: 0.75rem;
            color: var(--text-muted);
        }
    }

    .menu-header {
        display: flex;
        flex-direction: column;
        padding: 8px 12px 10px;

        small {
            color: var(--text-muted);
            font-size: var(--fs-xs);
        }
    }

    .notification-menu {
        .topbar-button {
            min-width: 46px;
        }

        .dropdown-menu {
            width: 360px;
            max-width: calc(100vw - 24px);
            padding: 8px;
        }

        .item-list {
            max-height: 360px;
            overflow-y: auto;
        }

        .menu-footer {
            display: block;
            text-align: center;
            padding: 10px;
            margin-top: 4px;
            border-top: 1px solid var(--border-soft);
            font-size: var(--fs-sm);
            font-weight: var(--fw-lg);
        }

        .empty-state {
            padding: 24px 12px;
        }
    }

    @media (max-width: 992px) {
        & {
            --page-pad: 20px;
        }

        .topbar-toggle {
            display: block;
        }
    }

    @media (max-width: 576px) {
        & {
            --page-pad: 14px;
        }

        .button-label {
            display: none;
        }

        .topbar-user {
            padding: 3px;

            .user-caret {
                display: none;
            }
        }
    }
}

.app-main {
    flex: 1;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--page-pad);

    @media (max-width: 992px) {
        & {
            --page-pad: 20px;
        }
    }

    @media (max-width: 576px) {
        & {
            --page-pad: 14px;
        }
    }
}

.app-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 18px var(--page-pad);
    font-size: var(--fs-xs);
    color: var(--text-faint);

    @media (max-width: 768px) {
        & {
            display: none;
        }
    }
}

.app-bottom-nav {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1035;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);

    .bottom-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: 0;
        background: none;
        color: var(--text-faint);
        font-size: 0.6875rem;
        font-weight: var(--fw-lg);

        .bi {
            font-size: 1.3rem;
        }

        &.active {
            color: var(--theme-color);
        }
    }

    @media (max-width: 768px) {
        & {
            display: flex;
        }
    }
}

/* ==========================================================================
   Flash Message
   ========================================================================== */

.flash-stack {
    position: fixed;
    top: calc(var(--topbar-height) + 12px);
    right: 20px;
    z-index: 1090;
    display: grid;
    gap: 10px;
    width: 380px;
    max-width: calc(100vw - 28px);

    .flash-item {
        display: flex;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
        border-radius: var(--rd-md);
        background: var(--white);
        border: 1px solid var(--border-color);
        border-left: 4px solid var(--tone);
        box-shadow: var(--shadow-md);
        animation: flash-in 0.25s ease;

        > .bi {
            color: var(--tone);
            font-size: 1.15rem;
            line-height: 1.4;
        }

        span {
            flex: 1;
            font-weight: var(--fw-md);
        }

        &.is-hiding {
            opacity: 0;
            transform: translateX(16px);
            transition: 0.25s ease;
        }
    }

    .flash-close {
        border: 0;
        background: none;
        color: var(--text-faint);
        padding: 0;
        font-size: 1.1rem;
    }

    @media (max-width: 576px) {
        & {
            right: 14px;
            top: calc(var(--topbar-height) + 8px);
        }
    }
}

@keyframes flash-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* ==========================================================================
   Page Header
   ========================================================================== */

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;

    .header-back {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        margin-bottom: 6px;
        font-size: var(--fs-sm);
        font-weight: var(--fw-lg);
        color: var(--text-muted);

        &:hover {
            color: var(--theme-color);
        }
    }

    .header-text {
        min-width: 0;

        h1 {
            margin: 0;
            font-size: var(--fs-title);
        }

        p {
            margin: 4px 0 0;
            color: var(--text-muted);
        }
    }

    .header-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    @media (max-width: 768px) {
        & {
            align-items: stretch;
            flex-direction: column;
        }

        .header-text h1 {
            font-size: var(--fs-xl);
        }

        .header-actions > * {
            flex: 1;
        }
    }
}

/* ==========================================================================
   Panel: .card-wrapper > .card-title + .card-content
   ========================================================================== */

.card-wrapper {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--rd-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;

    .card-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 12px;
        padding: 18px 22px;
        border-bottom: 1px solid var(--border-soft);

        h2 {
            display: flex;
            flex-direction: column;
            margin: 0;
            font-size: var(--fs-md);

            span {
                font-size: var(--fs-sm);
                font-weight: 400;
                color: var(--text-muted);
                margin-top: 2px;
            }
        }

        .title-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }
    }

    .card-content {
        padding: 22px;
    }

    &.is-flush .card-content {
        padding: 0;
    }

    @media (max-width: 576px) {
        & {
            border-radius: var(--rd-md);
            margin-bottom: 16px;
        }

        .card-title {
            padding: 14px 16px;
        }

        .card-content {
            padding: 16px;
        }
    }
}

/* ==========================================================================
   Shared Components
   ========================================================================== */

/* -- Item List: แถวรายการ (ไอคอน + ข้อความ + ด้านขวา) ใช้ทั้งระบบ -- */
.item-list {
    list-style: none;
    margin: 0;
    padding: 0;

    > li + li {
        border-top: 1px solid var(--border-soft);
    }

    .item-row {
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 14px 22px;
        color: var(--text-color);

        &:is(a):hover {
            background: var(--theme-softer);
        }

        &.is-unread {
            background: linear-gradient(90deg, var(--theme-softer), transparent);

            .item-title::after {
                content: "";
                display: inline-block;
                width: 8px;
                height: 8px;
                margin-left: 8px;
                border-radius: 50%;
                background: var(--theme-color);
                vertical-align: middle;
            }
        }

        &.is-done .item-title {
            color: var(--text-muted);
        }
    }

    .item-icon {
        flex-shrink: 0;
        display: grid;
        place-items: center;
        width: 42px;
        height: 42px;
        border-radius: var(--rd-md);
        background: var(--tone-soft, var(--theme-soft));
        color: var(--tone, var(--theme-color));
        font-size: 1.15rem;
    }

    .item-body {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
    }

    .item-title {
        font-weight: var(--fw-lg);
        line-height: 1.4;
    }

    .item-meta {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px 12px;
        margin-top: 2px;
        font-size: var(--fs-sm);
        color: var(--text-muted);

        > span {
            display: inline-flex;
            align-items: center;
            gap: 5px;
        }
    }

    .item-side {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }

    @media (max-width: 576px) {
        .item-row {
            padding: 12px 16px;
            gap: 12px;
            flex-wrap: wrap;
        }

        .item-icon {
            width: 38px;
            height: 38px;
        }

        .item-side {
            width: 100%;
            padding-left: 50px;
        }
    }
}

.dropdown-menu .item-list .item-row {
    padding: 10px;
    border-radius: var(--rd-sm);

    .item-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .item-title {
        font-size: var(--fs-sm);
    }

    .item-meta {
        font-size: var(--fs-xs);
    }

    @media (max-width: 576px) {
        & {
            flex-wrap: nowrap;
        }
    }
}

/* -- Status Chip -- */
.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: var(--rd-pill);
    background: var(--tone-soft);
    color: var(--tone);
    font-size: var(--fs-xs);
    font-weight: var(--fw-lg);
    white-space: nowrap;
    line-height: 1.6;

    .bi {
        font-size: 0.8rem;
    }
}

/* -- Avatar -- */
.user-avatar {
    --avatar-size: 40px;

    flex-shrink: 0;
    display: inline-grid;
    place-items: center;
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    background: var(--tone-soft);
    color: var(--tone);
    font-size: calc(var(--avatar-size) * 0.38);
    font-weight: var(--fw-bold);

    &.is-sm {
        --avatar-size: 32px;
    }

    &.is-xs {
        --avatar-size: 28px;
    }

    &.is-lg {
        --avatar-size: 72px;
    }
}

/* -- Progress Line -- */
.progress-line {
    --progress-color: var(--theme-color);

    height: 8px;
    border-radius: var(--rd-pill);
    background: var(--border-soft);
    overflow: hidden;

    span {
        display: block;
        height: 100%;
        border-radius: inherit;
        background: var(--progress-color);
        transition: width 0.4s ease;
    }

    &.is-green {
        --progress-color: var(--tone-green);
    }
}

/* -- Empty State -- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
    padding: 40px 20px;
    color: var(--text-muted);

    .empty-icon {
        display: grid;
        place-items: center;
        width: 56px;
        height: 56px;
        margin-bottom: 6px;
        border-radius: 50%;
        background: var(--bg-color);
        font-size: 1.5rem;
        color: var(--text-faint);
    }

    strong {
        color: var(--text-color);
        font-weight: var(--fw-lg);
    }

    p {
        margin: 0;
        font-size: var(--fs-sm);
    }
}

/* -- Stat List -- */
.stat-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;

    .stat-item {
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 18px;
        background: var(--white);
        border: 1px solid var(--border-color);
        border-radius: var(--rd-lg);
        box-shadow: var(--shadow-sm);
        color: var(--text-color);
    }

    .stat-icon {
        display: grid;
        place-items: center;
        width: 48px;
        height: 48px;
        flex-shrink: 0;
        border-radius: var(--rd-md);
        background: var(--tone-soft);
        color: var(--tone);
        font-size: 1.35rem;
    }

    .stat-text {
        display: flex;
        flex-direction: column;
        min-width: 0;
        line-height: 1.3;

        strong {
            font-size: var(--fs-xl);
            font-weight: var(--fw-bold);
        }

        span {
            font-size: var(--fs-sm);
            color: var(--text-muted);
        }
    }

    @media (max-width: 1200px) {
        & {
            grid-template-columns: repeat(2, 1fr);
        }
    }

    @media (max-width: 576px) {
        & {
            gap: 10px;
            margin-bottom: 16px;
        }

        .stat-item {
            flex-direction: column;
            align-items: flex-start;
            gap: 10px;
            padding: 14px;
        }

        .stat-icon {
            width: 40px;
            height: 40px;
            font-size: 1.15rem;
        }

        .stat-text strong {
            font-size: var(--fs-lg);
        }
    }
}

/* -- Info List: คู่ หัวข้อ/ค่า -- */
.info-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    margin: 0;

    .info-item {
        display: flex;
        flex-direction: column;
        padding: 12px 14px;
        border-radius: var(--rd-md);
        background: var(--bg-color);

        dt {
            font-size: var(--fs-xs);
            font-weight: var(--fw-md);
            color: var(--text-muted);
        }

        dd {
            margin: 2px 0 0;
            font-weight: var(--fw-lg);
        }
    }
}

/* -- Tab Navigation -- */
.tab-nav {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    padding: 4px;
    overflow-x: auto;
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--rd-md);
    scrollbar-width: none;

    &::-webkit-scrollbar {
        display: none;
    }

    .tab-link {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 8px 14px;
        border-radius: var(--rd-sm);
        color: var(--text-muted);
        font-weight: var(--fw-lg);
        font-size: var(--fs-sm);
        white-space: nowrap;

        &:hover {
            color: var(--text-color);
            background: var(--bg-color);
        }

        &.active {
            color: var(--theme-color);
            background: var(--theme-soft);
        }
    }

    .tab-count {
        font-style: normal;
        font-size: var(--fs-xs);
        padding: 0 7px;
        border-radius: var(--rd-pill);
        background: var(--border-soft);
        color: var(--text-muted);
    }

    @media (max-width: 576px) {
        & {
            margin-bottom: 16px;
        }
    }
}

/* -- Filter Bar -- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;

    .form-select,
    .form-control {
        width: auto;
        min-width: 180px;
    }

    @media (max-width: 576px) {
        .form-select,
        .form-control {
            flex: 1;
            min-width: 0;
        }
    }
}

/* -- Table -- */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-sm);

    th {
        padding: 12px 16px;
        background: #f8fafc;
        color: var(--text-muted);
        font-size: var(--fs-xs);
        font-weight: var(--fw-lg);
        text-transform: uppercase;
        letter-spacing: 0.03em;
        white-space: nowrap;
        border-bottom: 1px solid var(--border-color);
        text-align: left;
    }

    td {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-soft);
        vertical-align: middle;
    }

    tbody tr:hover td {
        background: var(--theme-softer);
    }

    tbody tr:last-child td {
        border-bottom: 0;
    }

    .cell-num {
        text-align: center;
        white-space: nowrap;
    }

    .cell-actions {
        text-align: right;
        white-space: nowrap;
    }

    .cell-student {
        display: flex;
        align-items: center;
        gap: 10px;
        min-width: 180px;

        span {
            display: flex;
            flex-direction: column;
            line-height: 1.3;
        }

        strong {
            font-weight: var(--fw-lg);
        }

        small {
            color: var(--text-muted);
            font-size: var(--fs-xs);
        }
    }

    .is-sticky {
        position: sticky;
        left: 0;
        z-index: 1;
        background: var(--white);
        box-shadow: 1px 0 0 var(--border-soft);
    }

    th.is-sticky {
        background: #f8fafc;
        z-index: 2;
    }

    .is-total {
        font-weight: var(--fw-bold);
        background: var(--theme-softer);
    }
}

/* -- Matrix Mark: ช่องสถานะเข้าเรียน / คะแนน -- */
.mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: var(--rd-sm);
    background: var(--tone-soft, var(--border-soft));
    color: var(--tone, var(--text-faint));
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);

    &.is-pending::after {
        content: "*";
        margin-left: 1px;
    }
}

/* -- Form Layout -- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px 18px;

    .is-full {
        grid-column: 1 / -1;
    }

    @media (max-width: 576px) {
        & {
            grid-template-columns: 1fr;
        }
    }
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;

    @media (max-width: 576px) {
        > * {
            flex: 1;
        }
    }
}

.switch-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--rd-md);

    .switch-text {
        display: flex;
        flex-direction: column;

        strong {
            font-size: var(--fs-sm);
            font-weight: var(--fw-lg);
        }

        small {
            font-size: var(--fs-xs);
            color: var(--text-muted);
        }
    }

    .form-check-input {
        width: 2.6em;
        height: 1.4em;
        margin: 0;
        flex-shrink: 0;
        cursor: pointer;
    }
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;

    .check-item {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 12px;
        border: 1px solid var(--border-color);
        border-radius: var(--rd-md);
        cursor: pointer;
        font-weight: var(--fw-md);

        &:has(input:checked) {
            border-color: #a5b4fc;
            background: var(--theme-softer);
            color: var(--theme-color);
        }

        .form-check-input {
            margin: 0;
        }
    }
}

/* -- Upload Field -- */
.upload-field {
    .upload-drop {
        position: relative;
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 16px;
        border: 1.5px dashed #cdd3e3;
        border-radius: var(--rd-md);
        background: var(--theme-softer);
        cursor: pointer;
        transition: border-color 0.15s, background 0.15s;

        input[type="file"] {
            position: absolute;
            inset: 0;
            opacity: 0;
            cursor: pointer;
        }

        &:hover,
        &.is-dragging {
            border-color: var(--theme-color);
            background: var(--theme-soft);
        }
    }

    .upload-icon {
        display: grid;
        place-items: center;
        width: 42px;
        height: 42px;
        flex-shrink: 0;
        border-radius: var(--rd-md);
        background: var(--white);
        color: var(--theme-color);
        font-size: 1.3rem;
        box-shadow: var(--shadow-sm);
    }

    .upload-text {
        display: flex;
        flex-direction: column;
        min-width: 0;

        strong {
            font-size: var(--fs-sm);
        }

        small {
            font-size: var(--fs-xs);
            color: var(--text-muted);
            word-break: break-word;
        }
    }

    .upload-status {
        display: none;
        margin-top: 10px;

        .upload-name {
            display: block;
            font-size: var(--fs-sm);
            font-weight: var(--fw-md);
            margin-bottom: 6px;
            word-break: break-all;
        }
    }

    .upload-progress {
        height: 6px;
        border-radius: var(--rd-pill);
        background: var(--border-soft);
        overflow: hidden;

        span {
            display: block;
            width: 0;
            height: 100%;
            background: var(--theme-color);
            transition: width 0.2s;
        }
    }

    &.is-uploading,
    &.is-done,
    &.is-error {
        .upload-status {
            display: block;
        }
    }

    &.is-done {
        .upload-progress span {
            background: var(--tone-green);
        }

        .upload-name {
            color: var(--tone-green);
        }
    }

    &.is-error {
        .upload-progress span {
            background: var(--tone-red);
        }

        .upload-name {
            color: var(--tone-red);
        }
    }
}

/* -- Post List: ประกาศ -- */
.post-list {
    display: grid;
    gap: 16px;

    .post-item {
        padding: 18px 20px;
        background: var(--white);
        border: 1px solid var(--border-color);
        border-radius: var(--rd-lg);
    }

    .post-head {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 10px;
    }

    .post-author {
        flex: 1;
        display: flex;
        flex-direction: column;
        line-height: 1.35;

        strong {
            font-size: var(--fs-sm);
        }

        small {
            color: var(--text-muted);
            font-size: var(--fs-xs);
        }
    }

    .post-title {
        margin: 0 0 6px;
        font-size: var(--fs-md);
    }

    .post-body {
        margin: 0;
        color: #374151;
        white-space: pre-line;
    }

    &.is-compact .post-item {
        padding: 14px 16px;
        border-radius: var(--rd-md);
    }
}

/* -- Score Box -- */
.score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 22px;
    border-radius: var(--rd-lg);
    background: linear-gradient(135deg, var(--theme-soft), #f5f3ff);
    text-align: center;

    strong {
        font-size: 2.5rem;
        line-height: 1.1;
        color: var(--theme-color);
    }

    span {
        color: var(--text-muted);
        font-size: var(--fs-sm);
    }
}

/* -- Inline Form: ช่องกรอก + ปุ่ม -- */
.inline-form {
    display: flex;
    gap: 8px;

    .form-control {
        flex: 1;
        min-width: 0;
    }
}

/* -- Rich Text Block -- */
.text-block {
    white-space: pre-line;
    color: #374151;
    margin: 0;
}

/* ==========================================================================
   Layout Grids
   ========================================================================== */

.dashboard-grid,
.split-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 24px;
    align-items: start;

    @media (max-width: 1200px) {
        & {
            grid-template-columns: minmax(0, 1fr) 320px;
        }
    }

    @media (max-width: 992px) {
        & {
            grid-template-columns: minmax(0, 1fr);
            gap: 0;
        }
    }
}

/* ==========================================================================
   Dashboard
   ========================================================================== */

.hero-banner {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
    padding: 28px 32px;
    border-radius: var(--rd-xl);
    background: linear-gradient(120deg, #4f46e5 0%, #6d5dfc 55%, #8b7cff 100%);
    color: var(--white);

    &::after {
        content: "";
        position: absolute;
        right: -60px;
        top: -80px;
        width: 260px;
        height: 260px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.1);
    }

    .hero-text {
        position: relative;
        z-index: 1;

        small {
            display: block;
            opacity: 0.85;
            font-weight: var(--fw-md);
        }

        h1 {
            margin: 4px 0 6px;
            color: var(--white);
            font-size: var(--fs-xxl);
        }

        p {
            margin: 0;
            opacity: 0.9;
        }
    }

    .hero-actions {
        position: relative;
        z-index: 1;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;

        .btn-light {
            --bs-btn-border-color: transparent;
        }
    }

    @media (max-width: 768px) {
        & {
            flex-direction: column;
            align-items: flex-start;
            padding: 22px 20px;
            border-radius: var(--rd-lg);
        }

        .hero-text h1 {
            font-size: var(--fs-xl);
        }
    }
}

/* -- Today's classes -- */
.today-list {
    display: grid;
    gap: 12px;

    .today-item {
        display: flex;
        align-items: center;
        gap: 16px;
        padding: 14px 16px;
        border: 1px solid var(--border-color);
        border-left: 4px solid var(--tone);
        border-radius: var(--rd-md);
        background: var(--white);

        &.is-live {
            background: linear-gradient(90deg, var(--tone-green-soft), var(--white) 60%);
            border-color: #bbf7d0;
            border-left-color: var(--tone-green);
        }
    }

    .today-time {
        display: flex;
        flex-direction: column;
        align-items: center;
        min-width: 64px;
        line-height: 1.25;

        strong {
            font-size: var(--fs-md);
        }

        small {
            color: var(--text-muted);
            font-size: var(--fs-xs);
        }
    }

    .today-body {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;

        strong {
            font-weight: var(--fw-lg);
        }

        small {
            color: var(--text-muted);
        }
    }

    .today-side {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    @media (max-width: 576px) {
        .today-item {
            flex-wrap: wrap;
            gap: 10px 14px;
        }

        .today-side {
            width: 100%;
            justify-content: space-between;
        }
    }
}

.live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--tone-green);
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.6);
    animation: live-pulse 1.6s infinite;
}

@keyframes live-pulse {
    70% {
        box-shadow: 0 0 0 8px rgba(22, 163, 74, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(22, 163, 74, 0);
    }
}

/* ==========================================================================
   Courses
   ========================================================================== */

.course-section {
    .card-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 20px;
    }

    .card-item {
        display: flex;
        flex-direction: column;
        overflow: hidden;
        background: var(--white);
        border: 1px solid var(--border-color);
        border-radius: var(--rd-lg);
        box-shadow: var(--shadow-sm);
        color: var(--text-color);
        transition: transform 0.2s, box-shadow 0.2s;

        &:hover {
            transform: translateY(-3px);
            box-shadow: var(--shadow-md);
            color: var(--text-color);
        }
    }

    .card-image {
        position: relative;
        height: 112px;
        padding: 16px 18px;
        background:
            radial-gradient(circle at 85% 20%, rgba(255, 255, 255, 0.28) 0 38px, transparent 39px),
            radial-gradient(circle at 70% 120%, rgba(255, 255, 255, 0.16) 0 60px, transparent 61px),
            var(--tone);
        color: var(--white);

        .card-code {
            display: inline-block;
            padding: 2px 10px;
            border-radius: var(--rd-pill);
            background: rgba(255, 255, 255, 0.22);
            font-size: var(--fs-xs);
            font-weight: var(--fw-bold);
            letter-spacing: 0.03em;
        }

        .bi {
            position: absolute;
            right: 18px;
            bottom: 12px;
            font-size: 2.4rem;
            opacity: 0.9;
        }
    }

    .card-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 16px 18px 18px;

        h3 {
            margin: 0;
            font-size: var(--fs-md);
        }
    }

    .card-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 4px 14px;
        font-size: var(--fs-sm);
        color: var(--text-muted);

        span {
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }
    }

    .card-progress {
        margin-top: auto;

        small {
            display: flex;
            justify-content: space-between;
            margin-bottom: 6px;
            font-size: var(--fs-xs);
            color: var(--text-muted);
        }
    }

    .card-footer {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 12px 18px;
        border-top: 1px solid var(--border-soft);
        font-size: var(--fs-sm);
        color: var(--text-muted);
    }

    @media (max-width: 576px) {
        .card-list {
            grid-template-columns: 1fr;
            gap: 14px;
        }

        .card-image {
            height: 96px;
        }
    }
}

.course-hero {
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
    padding: 26px 28px;
    border-radius: var(--rd-xl);
    background:
        radial-gradient(circle at 92% 10%, rgba(255, 255, 255, 0.22) 0 70px, transparent 71px),
        radial-gradient(circle at 78% 130%, rgba(255, 255, 255, 0.14) 0 110px, transparent 111px),
        var(--tone);
    color: var(--white);

    .header-back {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        margin-bottom: 10px;
        font-size: var(--fs-sm);
        font-weight: var(--fw-lg);
        color: rgba(255, 255, 255, 0.85);

        &:hover {
            color: var(--white);
        }
    }

    .hero-code {
        display: inline-block;
        padding: 2px 10px;
        border-radius: var(--rd-pill);
        background: rgba(255, 255, 255, 0.22);
        font-size: var(--fs-xs);
        font-weight: var(--fw-bold);
    }

    h1 {
        margin: 10px 0 8px;
        color: var(--white);
        font-size: var(--fs-xxl);
    }

    .hero-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 6px 18px;
        opacity: 0.92;
        font-size: var(--fs-sm);

        span {
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }
    }

    .hero-join {
        position: absolute;
        right: 28px;
        bottom: 24px;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 8px 8px 14px;
        border-radius: var(--rd-md);
        background: rgba(255, 255, 255, 0.18);
        backdrop-filter: blur(4px);

        small {
            display: block;
            font-size: var(--fs-xs);
            opacity: 0.85;
        }

        strong {
            font-size: var(--fs-lg);
            letter-spacing: 0.12em;
        }

        .btn {
            --bs-btn-bg: var(--white);
            --bs-btn-color: var(--tone);
            --bs-btn-border-color: var(--white);
            --bs-btn-hover-bg: var(--white);
            --bs-btn-hover-color: var(--tone);
        }
    }

    @media (max-width: 768px) {
        & {
            padding: 20px;
            border-radius: var(--rd-lg);
        }

        h1 {
            font-size: var(--fs-xl);
        }

        .hero-join {
            position: static;
            margin-top: 16px;
            width: fit-content;
        }
    }
}

/* ==========================================================================
   Class Session (ห้องเรียนรายคาบ)
   ========================================================================== */

.session-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
    padding: 20px 24px;
    border-radius: var(--rd-lg);
    background: var(--white);
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--tone);

    .hero-state {
        display: flex;
        align-items: center;
        gap: 14px;
    }

    .state-icon {
        display: grid;
        place-items: center;
        width: 52px;
        height: 52px;
        border-radius: 50%;
        background: var(--tone-soft);
        color: var(--tone);
        font-size: 1.5rem;
    }

    .state-text {
        display: flex;
        flex-direction: column;
        line-height: 1.35;

        strong {
            font-size: var(--fs-md);
        }

        small {
            color: var(--text-muted);
        }
    }

    .hero-countdown {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        line-height: 1.2;

        small {
            color: var(--text-muted);
            font-size: var(--fs-xs);
        }

        strong {
            font-size: var(--fs-xl);
            font-variant-numeric: tabular-nums;
            color: var(--tone);
        }
    }

    .hero-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    @media (max-width: 576px) {
        & {
            padding: 16px;
        }

        .hero-countdown {
            align-items: flex-start;
        }

        .hero-actions {
            width: 100%;

            > * {
                flex: 1;
            }
        }
    }
}

.content-list {
    list-style: none;
    margin: 0;
    padding: 8px;

    .content-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        border-radius: var(--rd-md);
        color: var(--text-color);

        &:hover {
            background: var(--bg-color);
        }

        &.active {
            background: var(--theme-soft);

            .content-title {
                color: var(--theme-color);
            }
        }
    }

    .content-icon {
        display: grid;
        place-items: center;
        width: 38px;
        height: 38px;
        flex-shrink: 0;
        border-radius: var(--rd-sm);
        background: var(--tone-soft);
        color: var(--tone);
    }

    .content-body {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        line-height: 1.35;
    }

    .content-title {
        font-weight: var(--fw-lg);
        font-size: var(--fs-sm);
    }

    .content-meta {
        font-size: var(--fs-xs);
        color: var(--text-muted);
    }

    .content-check {
        font-size: 1.15rem;
        color: var(--border-color);

        &.is-done {
            color: var(--tone-green);
        }
    }
}

.lesson-viewer {
    .viewer-frame {
        position: relative;
        overflow: hidden;
        border-radius: var(--rd-lg) var(--rd-lg) 0 0;
        background: #0f172a;

        video,
        iframe {
            display: block;
            width: 100%;
            border: 0;
        }

        video,
        .is-youtube {
            aspect-ratio: 16 / 9;
            height: auto;
        }

        .is-document {
            height: 74vh;
            min-height: 420px;
            background: #525659;
        }

        img {
            display: block;
            margin: 0 auto;
            max-height: 74vh;
        }

        &.is-download {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 12px;
            min-height: 280px;
            padding: 32px;
            background: linear-gradient(135deg, var(--theme-soft), #f5f3ff);
            color: var(--text-color);
            text-align: center;

            .bi {
                font-size: 3rem;
                color: var(--theme-color);
            }
        }
    }

    .viewer-info {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 14px;
        padding: 18px 22px;

        h2 {
            margin: 0 0 4px;
            font-size: var(--fs-lg);
        }

        p {
            margin: 0;
            color: var(--text-muted);
        }
    }

    .viewer-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    @media (max-width: 576px) {
        .viewer-frame {
            border-radius: var(--rd-md) var(--rd-md) 0 0;

            .is-document {
                height: 62vh;
                min-height: 320px;
            }
        }

        .viewer-info {
            padding: 14px 16px;
        }
    }
}

.attendance-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-soft);

    .summary-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 8px 4px;
        border-radius: var(--rd-md);
        background: var(--tone-soft);
        color: var(--tone);
        line-height: 1.25;

        strong {
            font-size: var(--fs-lg);
        }

        small {
            font-size: var(--fs-xs);
            font-weight: var(--fw-lg);
        }
    }
}

.attendance-list {
    list-style: none;
    margin: 0;
    padding: 6px 0;
    max-height: 560px;
    overflow-y: auto;

    .attendance-row {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 18px;
    }

    .row-name {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        line-height: 1.3;

        strong {
            font-size: var(--fs-sm);
            font-weight: var(--fw-lg);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        small {
            font-size: var(--fs-xs);
            color: var(--text-muted);
        }
    }

    form {
        flex-shrink: 0;
    }

    .form-select {
        width: 112px;
    }
}

/* ==========================================================================
   Exam
   ========================================================================== */

.question-list {
    display: grid;
    gap: 16px;

    .question-item {
        padding: 20px 22px;
        background: var(--white);
        border: 1px solid var(--border-color);
        border-radius: var(--rd-lg);

        &.is-answered {
            border-color: #c7d2fe;
        }
    }

    .question-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 10px;
    }

    .question-number {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        font-weight: var(--fw-bold);
        color: var(--theme-color);
    }

    .question-points {
        font-size: var(--fs-xs);
        font-weight: var(--fw-lg);
        color: var(--text-muted);
    }

    .question-text {
        margin: 0 0 14px;
        font-size: var(--fs-md);
        font-weight: var(--fw-md);
        white-space: pre-line;
    }

    .option-list {
        display: grid;
        gap: 8px;
    }

    .option-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 14px;
        border: 1.5px solid var(--border-color);
        border-radius: var(--rd-md);
        cursor: pointer;
        transition: border-color 0.15s, background 0.15s;

        .form-check-input {
            margin: 0;
            flex-shrink: 0;
        }

        .option-letter {
            display: grid;
            place-items: center;
            width: 28px;
            height: 28px;
            flex-shrink: 0;
            border-radius: 50%;
            background: var(--bg-color);
            font-size: var(--fs-sm);
            font-weight: var(--fw-bold);
            color: var(--text-muted);
        }

        &:hover {
            border-color: #c7d2fe;
        }

        &:has(input:checked),
        &.is-chosen {
            border-color: var(--theme-color);
            background: var(--theme-softer);

            .option-letter {
                background: var(--theme-color);
                color: var(--white);
            }
        }

        &.is-correct {
            border-color: var(--tone-green);
            background: var(--tone-green-soft);

            .option-letter {
                background: var(--tone-green);
                color: var(--white);
            }
        }

        &.is-wrong {
            border-color: var(--tone-red);
            background: var(--tone-red-soft);

            .option-letter {
                background: var(--tone-red);
                color: var(--white);
            }
        }
    }

    .answer-box {
        padding: 12px 14px;
        border-radius: var(--rd-md);
        background: var(--bg-color);
        white-space: pre-line;

        &.is-correct {
            background: var(--tone-green-soft);
        }

        &.is-wrong {
            background: var(--tone-red-soft);
        }
    }

    .answer-key {
        margin-top: 10px;
        font-size: var(--fs-sm);
        color: var(--tone-green);
        font-weight: var(--fw-md);
    }

    @media (max-width: 576px) {
        .question-item {
            padding: 16px;
        }
    }
}

.exam-timer {
    position: sticky;
    top: calc(var(--topbar-height) + 12px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px 18px;
    border-radius: var(--rd-md);
    background: var(--white);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);

    .timer-value {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        font-size: var(--fs-lg);
        font-weight: var(--fw-bold);
        font-variant-numeric: tabular-nums;
        color: var(--theme-color);

        &.is-warning {
            color: var(--tone-red);
        }
    }

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

    .save-state {
        font-size: var(--fs-xs);
        color: var(--text-faint);
    }
}

.builder-choice {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;

    .form-check-input {
        margin: 0;
        flex-shrink: 0;
    }
}

/* ==========================================================================
   Recorder
   ========================================================================== */

.recorder-stage {
    position: relative;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    border-radius: var(--rd-lg);
    background: #0f172a;

    video {
        width: 100%;
        height: 100%;
        object-fit: contain;
        display: block;
    }

    .stage-placeholder {
        position: absolute;
        inset: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 10px;
        color: #94a3b8;
        text-align: center;
        padding: 20px;

        .bi {
            font-size: 3rem;
        }
    }

    .rec-badge {
        position: absolute;
        top: 14px;
        left: 14px;
        display: none;
        align-items: center;
        gap: 8px;
        padding: 6px 12px;
        border-radius: var(--rd-pill);
        background: rgba(220, 38, 38, 0.92);
        color: var(--white);
        font-weight: var(--fw-bold);
        font-variant-numeric: tabular-nums;

        &::before {
            content: "";
            width: 9px;
            height: 9px;
            border-radius: 50%;
            background: var(--white);
            animation: rec-blink 1s infinite;
        }
    }

    &.is-recording .rec-badge {
        display: inline-flex;
    }

    &.is-live .stage-placeholder {
        display: none;
    }
}

@keyframes rec-blink {
    50% {
        opacity: 0.2;
    }
}

.recorder-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 16px;

    .control-spacer {
        flex: 1;
    }

    @media (max-width: 576px) {
        .btn {
            flex: 1;
        }

        .control-spacer {
            display: none;
        }
    }
}

.mode-switch {
    display: inline-flex;
    padding: 4px;
    border-radius: var(--rd-md);
    background: var(--bg-color);

    label {
        padding: 6px 12px;
        border-radius: var(--rd-sm);
        font-size: var(--fs-sm);
        font-weight: var(--fw-lg);
        color: var(--text-muted);
        cursor: pointer;

        &:has(input:checked) {
            background: var(--white);
            color: var(--theme-color);
            box-shadow: var(--shadow-sm);
        }

        input {
            display: none;
        }
    }
}

/* ==========================================================================
   Auth (Login / Install)
   ========================================================================== */

.auth-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 10% 10%, #e0e7ff 0, transparent 40%),
        radial-gradient(circle at 90% 90%, #ede9fe 0, transparent 40%),
        var(--bg-color);
}

.auth-section {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.05fr 1fr;

    .auth-brand {
        position: relative;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 48px 56px;
        background: linear-gradient(150deg, #4f46e5 0%, #6d5dfc 60%, #8b7cff 100%);
        color: var(--white);

        &::before,
        &::after {
            content: "";
            position: absolute;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.08);
        }

        &::before {
            width: 420px;
            height: 420px;
            right: -140px;
            top: -120px;
        }

        &::after {
            width: 300px;
            height: 300px;
            left: -100px;
            bottom: -110px;
        }
    }

    .brand-head {
        position: relative;
        z-index: 1;
        display: flex;
        align-items: center;
        gap: 12px;

        img {
            border-radius: 14px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
        }

        strong {
            display: block;
            font-size: var(--fs-lg);
        }

        small {
            opacity: 0.85;
        }
    }

    .brand-body {
        position: relative;
        z-index: 1;

        h1 {
            margin: 0 0 12px;
            color: var(--white);
            font-size: 2.4rem;
        }

        p {
            margin: 0 0 28px;
            opacity: 0.9;
            font-size: var(--fs-md);
            max-width: 460px;
        }
    }

    .feature-list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: grid;
        gap: 12px;

        li {
            display: flex;
            align-items: center;
            gap: 12px;
            font-weight: var(--fw-md);
        }

        .bi {
            display: grid;
            place-items: center;
            width: 36px;
            height: 36px;
            border-radius: var(--rd-md);
            background: rgba(255, 255, 255, 0.16);
        }
    }

    .brand-foot {
        position: relative;
        z-index: 1;
        font-size: var(--fs-sm);
        opacity: 0.75;
    }

    .auth-form {
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 48px 24px;
    }

    .form-box {
        width: 100%;
        max-width: 420px;
        margin: 0 auto;

        h2 {
            margin: 0 0 6px;
            font-size: var(--fs-xl);
        }

        > p {
            margin: 0 0 28px;
            color: var(--text-muted);
        }
    }

    .form-top {
        display: flex;
        justify-content: flex-end;
        margin-bottom: 32px;
    }

    .password-field {
        position: relative;

        .form-control {
            padding-right: 46px;
        }

        button {
            position: absolute;
            right: 6px;
            top: 50%;
            transform: translateY(-50%);
            border: 0;
            background: none;
            color: var(--text-muted);
            padding: 6px 10px;
        }
    }

    .demo-box {
        margin-top: 28px;
        padding: 16px;
        border-radius: var(--rd-md);
        background: var(--white);
        border: 1px dashed #c7d2fe;

        > strong {
            display: block;
            margin-bottom: 8px;
            font-size: var(--fs-sm);
        }
    }

    @media (max-width: 992px) {
        & {
            grid-template-columns: 1fr;
        }

        .auth-brand {
            padding: 28px 24px;
            gap: 20px;
        }

        .brand-body {
            h1 {
                font-size: var(--fs-xl);
            }

            p {
                margin-bottom: 0;
            }
        }

        .feature-list,
        .brand-foot {
            display: none;
        }

        .auth-form {
            padding: 28px 20px 40px;
        }

        .form-top {
            margin-bottom: 16px;
        }
    }
}

.demo-list {
    list-style: none;
    margin: 0 0 4px;
    padding: 0;
    display: grid;
    gap: 6px;

    li {
        display: grid;
        grid-template-columns: 80px 1fr auto;
        align-items: center;
        gap: 8px;
        font-size: var(--fs-sm);
    }

    button {
        border: 0;
        background: none;
        padding: 0;
        text-align: left;
        color: var(--theme-color);
        font-weight: var(--fw-lg);
    }

    span {
        color: var(--text-muted);
    }
}

.install-section {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;

    .card-wrapper {
        width: 100%;
        max-width: 480px;
    }

    .demo-list {
        margin-bottom: 20px;
    }
}

/* ==========================================================================
   Landing (หน้าแรกก่อน login)
   โทนโมเดิร์นเรียบ: พื้นขาวสลับเทาอ่อน การ์ดขอบบาง สีหลักใช้เฉพาะจุดที่ต้องการให้เห็น
   ========================================================================== */

html:has(.landing-body) {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
}

.landing-body {
    --landing-width: 1160px;
    --landing-gap: 112px;
    --landing-pad: 32px;
    --landing-nav-height: 68px;
    --landing-card-pad: 28px;

    background: var(--white);

    .container {
        max-width: calc(var(--landing-width) + var(--landing-pad) * 2);
        padding-inline: var(--landing-pad);
    }

    @media (max-width: 1200px) {
        & {
            --landing-gap: 96px;
        }
    }

    @media (max-width: 992px) {
        & {
            --landing-gap: 80px;
            --landing-pad: 28px;
            --landing-card-pad: 24px;
        }
    }

    @media (max-width: 576px) {
        & {
            --landing-gap: 64px;
            --landing-pad: 16px;
            --landing-nav-height: 60px;
            --landing-card-pad: 20px;
        }
    }
}

/* -- Navbar -- */
.landing-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-soft);

    /* 3 ช่อง (โลโก้ | เมนู | ปุ่ม) ช่องข้างกว้างเท่ากัน เมนูจึงอยู่กึ่งกลางจอพอดี */
    .container {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: center;
        gap: 32px;
        height: var(--landing-nav-height);
    }

    .nav-brand {
        justify-self: start;
        display: flex;
        align-items: center;
        gap: 10px;
        color: var(--text-color);
        font-size: var(--fs-md);
        letter-spacing: -0.01em;

        img {
            border-radius: 9px;
        }
    }

    .nav-links {
        display: flex;
        justify-content: center;
        gap: 28px;

        a {
            color: var(--text-muted);
            font-size: var(--fs-sm);
            font-weight: var(--fw-md);
            transition: color 0.15s;

            &:hover {
                color: var(--theme-color);
            }
        }
    }

    .nav-actions {
        justify-self: end;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .nav-language {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        height: 38px;
        padding: 0 12px;
        border: 0;
        border-radius: var(--rd-sm);
        background: none;
        color: var(--text-muted);
        font-size: var(--fs-sm);
        font-weight: var(--fw-lg);

        &:hover {
            background: var(--bg-color);
            color: var(--text-color);
        }
    }

    .nav-sign-in {
        --bs-btn-padding-x: 16px;
        --bs-btn-padding-y: 8px;
        --bs-btn-font-size: var(--fs-sm);
        --bs-btn-border-radius: var(--rd-sm);
    }

    /* แท็บเล็ต: พื้นที่ไม่พอให้ช่องข้างเท่ากัน เมนูอยู่กึ่งกลางระหว่างโลโก้กับปุ่มแทน */
    @media (max-width: 992px) {
        .container {
            grid-template-columns: auto minmax(0, 1fr) auto;
            gap: 24px;
        }

        .nav-links {
            gap: 20px;
        }
    }

    @media (max-width: 768px) {
        .container {
            grid-template-columns: minmax(0, 1fr) auto;
        }

        .nav-links {
            display: none;
        }
    }

    @media (max-width: 576px) {
        .nav-language {
            padding: 0 8px;
        }

        .nav-sign-in {
            --bs-btn-padding-x: 12px;
        }
    }
}

/* -- ส่วนที่ทุก section ของ landing ใช้ร่วมกัน (หัว section จาก require/landing-head.php) -- */
.feature-section,
.step-section,
.role-section,
.faq-section {
    padding: var(--landing-gap) 0;

    .section-header {
        max-width: 720px;
        margin: 0 auto 56px;
        text-align: center;

        h2 {
            margin: 0 0 14px;
            font-size: 2.5rem;
            line-height: 1.3;
            letter-spacing: -0.02em;
            text-wrap: balance;
        }

        > p {
            margin: 0;
            color: var(--text-muted);
            font-size: var(--fs-md);
            line-height: 1.75;
        }
    }

    .section-label {
        display: inline-flex;
        margin-bottom: 16px;
        padding: 4px 14px;
        border-radius: var(--rd-pill);
        background: var(--theme-soft);
        color: var(--theme-color);
        font-size: var(--fs-xs);
        font-weight: var(--fw-lg);
        letter-spacing: 0.02em;
    }

    .card-list {
        list-style: none;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 20px;
        margin: 0;
        padding: 0;
    }

    .card-icon {
        display: grid;
        place-items: center;
        flex-shrink: 0;
        width: 48px;
        height: 48px;
        border-radius: var(--rd-md);
        background: var(--tone-soft);
        color: var(--tone);
        font-size: 1.375rem;
    }

    h3 {
        margin: 0 0 8px;
        font-size: var(--fs-md);
        font-weight: var(--fw-bold);
    }

    p {
        margin: 0;
        color: var(--text-muted);
        line-height: 1.7;
    }

    @media (max-width: 1200px) {
        .section-header h2 {
            font-size: 2.25rem;
        }
    }

    @media (max-width: 992px) {
        .section-header {
            margin-bottom: 44px;

            h2 {
                font-size: var(--fs-xxl);
            }
        }

        .card-list {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
    }

    @media (max-width: 576px) {
        .section-header {
            margin-bottom: 32px;

            h2 {
                font-size: 1.625rem;
            }

            > p {
                font-size: var(--fs-base);
            }
        }

        .card-list {
            grid-template-columns: 1fr;
            gap: 12px;
        }
    }
}

/* -- Hero -- */
.hero-section {
    padding: 88px 0 var(--landing-gap);
    background:
        radial-gradient(ellipse 70% 55% at 50% 0%, var(--theme-soft), transparent 70%),
        var(--white);
    overflow: hidden;

    /* กว้างพอให้หัวข้อภาษาอังกฤษจบใน 1 บรรทัด (ภาษาไทย/จีนสั้นกว่าอยู่แล้ว) */
    .hero-text {
        max-width: 920px;
        margin: 0 auto;
        text-align: center;
    }

    .hero-badge {
        display: inline-flex;
        align-items: center;
        gap: 10px;
        margin: 0 0 28px;
        padding: 6px 16px;
        border-radius: var(--rd-pill);
        border: 1px solid var(--border-color);
        background: var(--white);
        color: var(--text-muted);
        font-size: var(--fs-sm);
        font-weight: var(--fw-md);
        box-shadow: var(--shadow-sm);

        i {
            flex-shrink: 0;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: var(--tone-green);
            box-shadow: 0 0 0 4px var(--tone-green-soft);
        }
    }

    h1 {
        margin: 0 0 24px;
        font-size: 3.5rem;
        line-height: 1.25;
        letter-spacing: -0.025em;
        text-wrap: balance;

        span {
            display: block;
            margin-top: 8px;
            color: var(--theme-color);
            font-size: 0.64em;
            line-height: 1.35;
            letter-spacing: -0.01em;
        }
    }

    .hero-intro {
        max-width: 640px;
        margin: 0 auto 36px;
        color: var(--text-muted);
        font-size: var(--fs-md);
        line-height: 1.8;
    }

    .hero-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 12px;
    }

    /* ป้าย "เร็วๆ นี้" แทนปุ่มเข้าสู่ระบบ (โหมด landing) */
    .hero-soon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        height: 50px;
        padding: 0 18px;
        border-radius: var(--rd-md);
        border: 1px dashed var(--border-color);
        background: var(--white);
        color: var(--text-muted);
        font-weight: var(--fw-md);
    }

    .hero-points {
        list-style: none;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px 24px;
        margin: 28px 0 0;
        padding: 0;
        color: var(--text-muted);
        font-size: var(--fs-sm);

        li {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .bi {
            color: var(--theme-color);
        }
    }

    .hero-facts {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        max-width: 820px;
        margin: 64px auto 0;

        div {
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 4px 16px;

            & + div {
                border-left: 1px solid var(--border-color);
            }
        }

        dd {
            margin: 0;
            font-size: var(--fs-xxl);
            font-weight: var(--fw-bold);
            line-height: 1.2;
            letter-spacing: -0.02em;
            font-variant-numeric: tabular-nums;
        }

        dt {
            color: var(--text-muted);
            font-size: var(--fs-sm);
            font-weight: var(--fw-md);
        }
    }

    @media (max-width: 1200px) {
        h1 {
            font-size: 3.125rem;
        }
    }

    @media (max-width: 992px) {
        & {
            padding-top: 72px;
        }

        h1 {
            font-size: 2.75rem;
        }
    }

    @media (max-width: 576px) {
        & {
            padding-top: 44px;
        }

        .hero-badge {
            margin-bottom: 20px;
            padding: 5px 12px;
            font-size: var(--fs-xs);
        }

        h1 {
            margin-bottom: 18px;
            font-size: 2.125rem;

            span {
                font-size: 0.68em;
            }
        }

        .hero-intro {
            margin-bottom: 28px;
            font-size: var(--fs-base);
        }

        .hero-actions .btn,
        .hero-soon {
            flex: 1 1 100%;
        }

        .hero-points {
            flex-direction: column;
            align-items: center;
            margin-top: 22px;
        }

        .hero-facts {
            grid-template-columns: repeat(2, minmax(0, 1fr));
            row-gap: 20px;
            margin-top: 44px;

            div:nth-child(3) {
                border-left: 0;
            }

            dd {
                font-size: var(--fs-xl);
            }
        }
    }
}

/* -- App Preview (ภาพตัวอย่างหน้า Dashboard ใน hero) -- */
.app-preview {
    --preview-menu-width: 68px;
    --preview-pad: 28px;

    max-width: 1000px;
    margin: 64px auto 0;
    border-radius: var(--rd-xl);
    border: 1px solid var(--border-color);
    background: var(--white);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 40px 80px -32px rgba(16, 24, 40, 0.22);
    overflow: hidden;
    text-align: left;

    .preview-bar {
        display: flex;
        align-items: center;
        height: 44px;
        padding: 0 16px;
        border-bottom: 1px solid var(--border-soft);
        background: var(--bg-color);
    }

    .bar-dots {
        display: flex;
        gap: 6px;

        i {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: var(--tone-red);
            opacity: 0.55;

            &:nth-child(2) {
                background: var(--tone-amber);
            }

            &:nth-child(3) {
                background: var(--tone-green);
            }
        }
    }

    .bar-address {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-width: 220px;
        margin-inline: auto;
        padding: 3px 16px;
        border-radius: var(--rd-pill);
        background: var(--white);
        color: var(--text-muted);
        font-size: var(--fs-xs);

        .bi {
            color: var(--tone-green);
            font-size: 0.7rem;
        }
    }

    .preview-body {
        display: grid;
        grid-template-columns: var(--preview-menu-width) minmax(0, 1fr);
    }

    .preview-menu {
        list-style: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        margin: 0;
        padding: 18px 0;
        border-right: 1px solid var(--border-soft);

        li {
            display: grid;
            place-items: center;
            width: 40px;
            height: 40px;
            border-radius: var(--rd-sm);
            color: var(--text-faint);
            font-size: 1.125rem;

            &.active {
                background: var(--theme-soft);
                color: var(--theme-color);
            }
        }

        .menu-brand {
            margin-bottom: 10px;
        }

        img {
            border-radius: 8px;
        }
    }

    .preview-main {
        padding: var(--preview-pad);
    }

    .preview-head {
        display: flex;
        align-items: flex-end;
        justify-content: space-between;
        gap: 16px;
        margin-bottom: 20px;

        small,
        strong {
            display: block;
        }

        small {
            color: var(--text-faint);
            font-size: var(--fs-xs);
            font-weight: var(--fw-md);
        }

        strong {
            font-size: var(--fs-lg);
            line-height: 1.3;
        }
    }

    .head-date {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 4px 12px;
        border-radius: var(--rd-pill);
        border: 1px solid var(--border-color);
        color: var(--text-muted);
        font-size: var(--fs-xs);
        white-space: nowrap;
    }

    .preview-classes {
        list-style: none;
        display: grid;
        gap: 10px;
        margin: 0 0 16px;
        padding: 0;
    }

    .class-item {
        position: relative;
        display: grid;
        grid-template-columns: 56px minmax(0, 1fr) auto auto;
        align-items: center;
        gap: 16px;
        padding: 14px 16px 14px 20px;
        border-radius: var(--rd-md);
        border: 1px solid var(--border-color);

        &::before {
            content: "";
            position: absolute;
            left: 8px;
            top: 14px;
            bottom: 14px;
            width: 3px;
            border-radius: var(--rd-pill);
            background: var(--tone);
        }

        &.is-open {
            border-color: var(--theme-color);
            background: var(--theme-softer);
            box-shadow: 0 0 0 4px var(--theme-soft);
        }
    }

    .class-time {
        color: var(--text-muted);
        font-size: var(--fs-sm);
        font-weight: var(--fw-lg);
        font-variant-numeric: tabular-nums;
    }

    .class-name {
        min-width: 0;

        strong,
        small {
            display: block;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        strong {
            font-size: var(--fs-base);
        }

        small {
            color: var(--text-faint);
            font-size: var(--fs-xs);
        }
    }

    .class-enter {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
        border-radius: var(--rd-sm);
        background: var(--theme-color);
        color: var(--white);
        font-size: var(--fs-xs);
        font-weight: var(--fw-lg);
        white-space: nowrap;
    }

    .preview-stats {
        list-style: none;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 10px;
        margin: 0;
        padding: 0;

        li {
            display: flex;
            align-items: center;
            gap: 12px;
            min-width: 0;
            padding: 14px 16px;
            border-radius: var(--rd-md);
            background: var(--bg-color);
        }

        small,
        strong {
            display: block;
        }

        small {
            color: var(--text-muted);
            font-size: var(--fs-xs);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        strong {
            font-size: var(--fs-lg);
            line-height: 1.3;
            font-variant-numeric: tabular-nums;
        }
    }

    .stat-icon {
        display: grid;
        place-items: center;
        flex-shrink: 0;
        width: 40px;
        height: 40px;
        border-radius: var(--rd-sm);
        background: var(--white);
        color: var(--tone);
        font-size: 1.125rem;
    }

    @media (max-width: 1200px) {
        & {
            margin-top: 56px;
        }
    }

    @media (max-width: 768px) {
        & {
            --preview-pad: 20px;

            border-radius: var(--rd-lg);
        }

        .preview-body {
            grid-template-columns: minmax(0, 1fr);
        }

        .preview-menu,
        .class-enter {
            display: none;
        }

        .class-item {
            grid-template-columns: 48px minmax(0, 1fr) auto;
            gap: 12px;
        }

        .preview-stats li {
            flex-direction: column;
            align-items: flex-start;
            gap: 10px;
        }
    }

    @media (max-width: 576px) {
        & {
            --preview-pad: 14px;

            margin-top: 44px;
        }

        .bar-address {
            min-width: 0;
        }

        .head-date {
            display: none;
        }

        .preview-head {
            margin-bottom: 14px;
        }

        .class-item {
            grid-template-columns: minmax(0, 1fr) auto;
            gap: 4px 10px;
            padding: 12px 12px 12px 18px;
        }

        .class-time {
            grid-column: 1;
            font-size: var(--fs-xs);
        }

        .class-name {
            grid-column: 1;
        }

        .status-chip {
            grid-column: 2;
            grid-row: 1 / span 2;
        }

        .preview-stats {
            gap: 8px;

            li {
                padding: 12px 10px;
            }
        }

        .stat-icon {
            display: none;
        }

        .preview-stats strong {
            font-size: var(--fs-md);
        }
    }
}

/* -- Features: การ์ด 6 ระบบหลักในเว็บ -- */
.feature-section {
    background: var(--bg-color);

    .card-item {
        padding: var(--landing-card-pad);
        border-radius: var(--rd-lg);
        border: 1px solid var(--border-color);
        background: var(--white);
        transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;

        &:hover {
            transform: translateY(-4px);
            border-color: transparent;
            box-shadow: var(--shadow-md);
        }
    }

    .card-icon {
        margin-bottom: 20px;
    }

    @media (max-width: 576px) {
        .card-item {
            display: grid;
            grid-template-columns: 44px minmax(0, 1fr);
            column-gap: 16px;

            h3,
            p {
                grid-column: 2;
            }
        }

        .card-icon {
            grid-row: 1 / span 2;
            width: 44px;
            height: 44px;
            margin: 0;
            font-size: 1.25rem;
        }
    }
}

/* -- Steps: 3 ขั้นตอนเริ่มใช้งาน จัดกึ่งกลางรับกับหัว section ต่อกันด้วยเส้นประ -- */
.step-section {
    --step-size: 48px;
    --step-gap: 32px;
    --step-space: 12px;
    /* ระยะจากกึ่งกลางการ์ดถึงจุดเริ่มเส้น = ครึ่งกลุ่มวงกลม (2 วง + ช่อง 10px) + ระยะเว้น */
    --step-reach: calc(var(--step-size) + 5px + var(--step-space));

    .card-list {
        position: relative;
        gap: var(--step-gap);
    }

    .card-item {
        position: relative;
        text-align: center;
    }

    .card-top {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin-bottom: 24px;
    }

    /* เส้นประจากกลุ่มวงกลมนี้ไปยังขั้นถัดไป (ขั้นสุดท้ายไม่มี) */
    .card-item:not(:last-child)::after {
        content: "";
        position: absolute;
        top: calc(var(--step-size) / 2 - 1px);
        left: calc(50% + var(--step-reach));
        width: calc(100% + var(--step-gap) - var(--step-reach) * 2);
        border-top: 2px dashed var(--border-color);
    }

    .card-number,
    .card-icon {
        width: var(--step-size);
        height: var(--step-size);
    }

    .card-number {
        position: relative;
        z-index: 1;
        display: grid;
        place-items: center;
        flex-shrink: 0;
        border-radius: 50%;
        background: var(--theme-color);
        color: var(--white);
        font-size: var(--fs-md);
        font-weight: var(--fw-bold);
        box-shadow: 0 0 0 6px var(--theme-soft);
    }

    .card-icon {
        border-radius: 50%;
        border: 1px solid var(--border-color);
        background: var(--white);
        color: var(--theme-color);
        font-size: 1.25rem;
    }

    .card-item p {
        max-width: 320px;
        margin-inline: auto;
    }

    @media (max-width: 992px) {
        & {
            --step-gap: 24px;
            --step-space: 8px;
        }

        .card-list {
            grid-template-columns: repeat(3, minmax(0, 1fr));
        }
    }

    /* มือถือ: เรียงแนวตั้ง ชิดซ้าย เส้นประแนวตั้ง */
    @media (max-width: 768px) {
        & {
            --step-gap: 32px;
        }

        .card-list {
            grid-template-columns: 1fr;

            &::before {
                content: "";
                position: absolute;
                left: calc(var(--step-size) / 2 - 1px);
                top: var(--step-size);
                bottom: var(--step-size);
                border-left: 2px dashed var(--border-color);
            }
        }

        .card-item {
            display: grid;
            grid-template-columns: var(--step-size) minmax(0, 1fr);
            column-gap: 20px;
            text-align: left;

            h3,
            p {
                grid-column: 2;
            }

            p {
                max-width: none;
                margin-inline: 0;
            }
        }

        .card-top {
            grid-row: 1 / span 2;
            align-self: start;
            margin: 0;
        }

        .card-item:not(:last-child)::after,
        .card-icon {
            display: none;
        }

        h3 {
            margin-top: 10px;
        }
    }
}

/* -- Roles: การ์ดแยกตามบทบาท สีตาม $_roles -- */
.role-section {
    background: var(--bg-color);

    /* subgrid: หัวการ์ด (แถว 1) และรายการ (แถว 2) สูงเท่ากันทุกใบ เส้นคั่นจึงอยู่ระดับเดียวกัน */
    .card-item {
        display: grid;
        grid-row: span 2;
        grid-template-rows: subgrid;
        row-gap: 0;
        align-content: start;
        padding: var(--landing-card-pad);
        border-radius: var(--rd-lg);
        border: 1px solid var(--border-color);
        border-top: 4px solid var(--tone);
        background: var(--white);
    }

    .card-head {
        display: flex;
        align-items: flex-start;
        gap: 14px;
        margin-bottom: 20px;
        padding-bottom: 20px;
        border-bottom: 1px solid var(--border-soft);

        h3 {
            margin: 0 0 2px;
            font-size: var(--fs-lg);
        }

        p {
            font-size: var(--fs-sm);
        }
    }

    .card-points {
        list-style: none;
        display: grid;
        gap: 12px;
        margin: 0;
        padding: 0;

        li {
            display: flex;
            align-items: flex-start;
            gap: 10px;
            font-size: var(--fs-sm);
            line-height: 1.6;
        }

        .bi {
            flex-shrink: 0;
            color: var(--tone);
            font-size: 1rem;
            line-height: 1.4;
        }
    }

    @media (max-width: 992px) {
        .card-list {
            grid-template-columns: 1fr;
            gap: 16px;
        }

        .card-item {
            grid-row: auto;
            grid-template-rows: none;
            grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
            column-gap: 32px;
        }

        .card-head {
            align-self: center;
            margin: 0;
            padding: 0;
            border-bottom: 0;
        }
    }

    @media (max-width: 576px) {
        .card-item {
            grid-template-columns: 1fr;
        }

        .card-head {
            margin-bottom: 18px;
            padding-bottom: 18px;
            border-bottom: 1px solid var(--border-soft);
        }

        .card-icon {
            width: 44px;
            height: 44px;
            font-size: 1.25rem;
        }
    }
}

/* -- FAQ: หัวกึ่งกลางเหมือน section อื่น รายการคำถาม (details) กว้างพอดีอ่าน -- */
.faq-section {
    .faq-list {
        display: grid;
        gap: 12px;
        max-width: 820px;
        margin: 0 auto;
    }

    .faq-item {
        padding: 0 20px;
        border-radius: var(--rd-md);
        border: 1px solid var(--border-color);
        background: var(--white);
        transition: background 0.15s, border-color 0.15s;

        summary {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 16px;
            padding: 18px 0;
            font-weight: var(--fw-lg);
            cursor: pointer;
            list-style: none;

            &::-webkit-details-marker {
                display: none;
            }

            .bi {
                flex-shrink: 0;
                color: var(--text-faint);
                transition: transform 0.2s, color 0.2s;
            }

            &:hover .bi {
                color: var(--theme-color);
            }
        }

        p {
            margin-bottom: 18px;
        }

        &[open] {
            border-color: var(--theme-soft);
            background: var(--theme-softer);

            summary .bi {
                color: var(--theme-color);
                transform: rotate(45deg);
            }
        }
    }

    @media (max-width: 576px) {
        .faq-item {
            padding: 0 16px;

            summary {
                padding: 16px 0;
            }

            p {
                font-size: var(--fs-sm);
            }
        }
    }
}

/* -- CTA -- */
.cta-section {
    padding-bottom: var(--landing-gap);

    .cta-banner {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 32px;
        padding: 56px 64px;
        border-radius: var(--rd-xl);
        background:
            radial-gradient(circle at 100% 0%, rgba(255, 255, 255, 0.18), transparent 45%),
            linear-gradient(135deg, var(--theme-color), var(--tone-violet));
        color: var(--white);
    }

    .cta-text {
        h2 {
            margin: 0 0 8px;
            color: var(--white);
            font-size: var(--fs-xxl);
            letter-spacing: -0.02em;
        }

        p {
            margin: 0;
            color: rgba(255, 255, 255, 0.8);
            font-size: var(--fs-md);
        }
    }

    .btn {
        flex-shrink: 0;
        --bs-btn-border-color: var(--white);
    }

    @media (max-width: 768px) {
        .cta-banner {
            flex-direction: column;
            align-items: flex-start;
            padding: 40px 32px;
        }
    }

    @media (max-width: 576px) {
        .cta-banner {
            padding: 32px 24px;
            border-radius: var(--rd-lg);
        }

        .cta-text h2 {
            font-size: var(--fs-xl);
        }

        .btn {
            width: 100%;
        }
    }
}

/* -- Footer -- */
.landing-footer {
    padding: 28px 0 36px;
    border-top: 1px solid var(--border-soft);
    color: var(--text-muted);
    font-size: var(--fs-sm);

    /* 3 ช่อง (แบรนด์ | ลิงก์ | ลิขสิทธิ์) ช่องข้างกว้างเท่ากัน ลิงก์จึงอยู่กึ่งกลางจอ */
    .container {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: center;
        gap: 16px 32px;

        > small {
            justify-self: end;
        }
    }

    .footer-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        color: var(--text-color);
        font-weight: var(--fw-md);

        img {
            border-radius: 7px;
        }
    }

    .footer-links {
        display: flex;
        flex-wrap: wrap;
        gap: 8px 24px;

        a {
            color: var(--text-muted);

            &:hover {
                color: var(--theme-color);
            }
        }
    }

    /* แท็บเล็ต: แบรนด์ + ลิขสิทธิ์บรรทัดแรก ลิงก์บรรทัดล่าง */
    @media (max-width: 992px) {
        .container {
            grid-template-columns: minmax(0, 1fr) auto;
        }

        .footer-links {
            grid-column: 1 / -1;
            grid-row: 2;
        }
    }

    @media (max-width: 576px) {
        .container {
            grid-template-columns: 1fr;

            > small {
                justify-self: start;
            }
        }
    }
}

/* ==========================================================================
   Error Page
   ========================================================================== */

.error-section {
    display: grid;
    place-items: center;
    min-height: 60vh;
    text-align: center;

    .error-code {
        font-size: 5rem;
        font-weight: var(--fw-bold);
        line-height: 1;
        color: var(--theme-color);
        opacity: 0.2;
    }

    h1 {
        margin: 12px 0 8px;
        font-size: var(--fs-xl);
    }

    p {
        color: var(--text-muted);
        margin-bottom: 20px;
    }
}

/* ==========================================================================
   Profile
   ========================================================================== */

.profile-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;

    h2 {
        margin: 10px 0 0;
        font-size: var(--fs-lg);
    }

    p {
        margin: 0;
        color: var(--text-muted);
    }
}

/* -- Color Picker (สีรายวิชา) -- */
.color-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;

    .color-swatch {
        cursor: pointer;

        input {
            display: none;
        }

        span {
            display: block;
            width: 34px;
            height: 34px;
            border-radius: 50%;
            background: var(--tone);
            border: 3px solid var(--white);
            box-shadow: 0 0 0 1px var(--border-color);
            transition: box-shadow 0.15s;
        }

        input:checked + span {
            box-shadow: 0 0 0 3px var(--tone);
        }
    }
}

/* -- Item Picker (เลือกเนื้อหาใส่ห้องเรียน) -- */
.item-picker {
    display: grid;
    gap: 16px;

    .check-grid.is-wide {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }

    .check-item span {
        font-size: var(--fs-sm);
        line-height: 1.35;
    }
}

/* -- Date Badge (รายการคาบเรียน) -- */
.date-badge {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 54px;
    border-radius: var(--rd-md);
    background: var(--tone-soft, var(--theme-soft));
    color: var(--tone, var(--theme-color));
    line-height: 1.1;

    small {
        font-size: 0.6875rem;
        font-weight: var(--fw-lg);
        text-transform: uppercase;
    }

    strong {
        font-size: var(--fs-lg);
    }
}

.list-heading {
    margin: 0;
    padding: 12px 22px 8px;
    font-size: var(--fs-xs);
    font-weight: var(--fw-lg);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    background: #fafbfd;
    border-bottom: 1px solid var(--border-soft);

    @media (max-width: 576px) {
        & {
            padding: 10px 16px 6px;
        }
    }
}

/* -- Card Note: แถบข้อความท้ายการ์ด (ใช้ได้ทั้งการ์ดปกติและ .is-flush) -- */
.card-wrapper .card-note {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    border-top: 1px solid var(--border-soft);
    font-size: var(--fs-sm);
    color: var(--text-muted);
}
