/* ==========================================================================
   Classroom & Exam Bank – main stylesheet (Bootstrap 5.3 + custom tokens)
   ========================================================================== */

:root,
[data-bs-theme="light"] {
    --app-bg: #f4f6fb;
    --app-surface: #ffffff;
    --app-surface-2: #f8f9fc;
    --app-border: #e5e8f0;
    --app-text: #1f2433;
    --app-muted: #6b7286;
    --app-primary: #4f46e5;
    --app-primary-rgb: 79, 70, 229;
    --app-primary-soft: #eef0ff;
    --app-accent: #0ea5e9;
    --app-success: #16a34a;
    --app-warning: #f59e0b;
    --app-danger: #e11d48;
    --app-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
    --app-shadow-lg: 0 10px 40px rgba(16, 24, 40, .12);
    --topbar-h: 64px;
    --sidebar-w: 264px;
    --radius: 14px;

    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-text);
    --bs-border-color: var(--app-border);
    --bs-primary: var(--app-primary);
    --bs-primary-rgb: var(--app-primary-rgb);
    --bs-link-color: var(--app-primary);
    --bs-link-color-rgb: var(--app-primary-rgb);
    --bs-link-hover-color: #4338ca;
}

[data-bs-theme="dark"] {
    --app-bg: #0f1220;
    --app-surface: #171b2e;
    --app-surface-2: #1d2238;
    --app-border: #2a3050;
    --app-text: #e6e8f2;
    --app-muted: #9aa1bb;
    --app-primary: #818cf8;
    --app-primary-rgb: 129, 140, 248;
    --app-primary-soft: rgba(129, 140, 248, .14);
    --app-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 18px rgba(0, 0, 0, .25);
    --app-shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);

    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-text);
    --bs-border-color: var(--app-border);
    --bs-secondary-bg: var(--app-surface-2);
    --bs-tertiary-bg: var(--app-surface-2);
    --bs-link-hover-color: #a5b4fc;
}

:root { --bs-font-sans-serif: "Noto Sans Thai", "Noto Sans Lao", system-ui, -apple-system, "Segoe UI", sans-serif; } /* Bootstrap's tooltips / popovers use this */
html, body {
    font-family: "Noto Sans Thai", "Noto Sans Lao", system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--app-bg);
    color: var(--app-text);
}

body { min-height: 100vh; }

/* -------- buttons ---------------------------------------------------------- */
.btn { border-radius: 10px; font-weight: 500; }
.btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: #4338ca;
    --bs-btn-hover-border-color: #4338ca;
    --bs-btn-active-bg: #3730a3;
    --bs-btn-disabled-bg: var(--app-primary);
    --bs-btn-disabled-border-color: var(--app-primary);
}
[data-bs-theme="dark"] .btn-primary {
    --bs-btn-color: #0f1220;
    --bs-btn-hover-color: #0f1220;
    --bs-btn-active-color: #0f1220;
    --bs-btn-disabled-color: #0f1220;
    --bs-btn-hover-bg: #a5b4fc;
    --bs-btn-hover-border-color: #a5b4fc;
}
.btn-outline-primary {
    --bs-btn-color: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary);
    --bs-btn-hover-border-color: var(--app-primary);
    --bs-btn-active-bg: var(--app-primary);
}
.btn-soft {
    background: var(--app-primary-soft);
    color: var(--app-primary);
    border: 0;
}
.btn-soft:hover { background: var(--app-primary); color: #fff; }
.btn-light {
    background: var(--app-surface-2);
    border-color: var(--app-border);
    color: var(--app-text);
}
.btn-light:hover { background: var(--app-border); color: var(--app-text); border-color: var(--app-border); }
.btn-icon {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%; border: 0; color: var(--app-text); background: transparent;
    font-size: 1.25rem; padding: 0;
}
.btn-icon:hover, .btn-icon:focus-visible { background: var(--app-surface-2); }
.btn-icon.btn-sm { width: 32px; height: 32px; font-size: 1rem; }
.text-primary { color: var(--app-primary) !important; }
.bg-primary { background-color: var(--app-primary) !important; }

/* -------- topbar ----------------------------------------------------------- */
.topbar {
    position: sticky; top: 0; z-index: 1030;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: .5rem;
    padding: 0 1rem;
    background: color-mix(in srgb, var(--app-surface) 88%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--app-border);
}
.brand {
    display: inline-flex; align-items: center; gap: .6rem;
    text-decoration: none; color: var(--app-text); font-weight: 600;
}
.brand:hover { color: var(--app-text); }
.brand-logo {
    width: 36px; height: 36px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #6366f1, #0ea5e9);
    color: #fff; font-size: 1.15rem; flex-shrink: 0;
}
.brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.user-btn {
    display: inline-flex; align-items: center; gap: .5rem;
    border: 1px solid var(--app-border); border-radius: 999px;
    padding: 3px 12px 3px 3px; background: var(--app-surface); color: var(--app-text);
}
.user-btn:hover { background: var(--app-surface-2); color: var(--app-text); }
@media (max-width: 767.98px) { .user-btn { padding: 3px; } }
.user-menu { min-width: 250px; }
.lang-btn { font-size: .85rem; border: 1px solid var(--app-border); }

[data-bs-theme="light"] .theme-icon-light, [data-bs-theme="light"] .theme-label-light { display: none; }
[data-bs-theme="dark"] .theme-icon-dark, [data-bs-theme="dark"] .theme-label-dark { display: none; }

.dropdown-menu {
    --bs-dropdown-bg: var(--app-surface);
    --bs-dropdown-border-color: var(--app-border);
    --bs-dropdown-link-active-bg: var(--app-primary);
    border-radius: 12px; padding: .4rem;
}
.dropdown-item { border-radius: 8px; padding: .5rem .75rem; }

/* -------- sidebar ---------------------------------------------------------- */
.sidebar {
    --bs-offcanvas-width: var(--sidebar-w);
    --bs-offcanvas-bg: var(--app-surface);
    background: var(--app-surface);
}
@media (min-width: 992px) {
    .sidebar {
        position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
        width: var(--sidebar-w);
        border-right: 1px solid var(--app-border);
        overflow-y: auto;
    }
    .main { margin-left: var(--sidebar-w); }
}
.sidebar-body { padding: .75rem .75rem 2rem; width: 100%; }
.side-link {
    display: flex; align-items: center; gap: .85rem;
    padding: .6rem .9rem; margin-bottom: 2px;
    border-radius: 0 999px 999px 0; margin-left: -.75rem; padding-left: 1.5rem;
    color: var(--app-text); text-decoration: none; font-size: .95rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-link i { font-size: 1.1rem; color: var(--app-muted); }
.side-link:hover { background: var(--app-surface-2); color: var(--app-text); }
.side-link.active { background: var(--app-primary-soft); color: var(--app-primary); font-weight: 600; }
.side-link.active i { color: var(--app-primary); }
.side-link span { overflow: hidden; text-overflow: ellipsis; }
.side-title {
    font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--app-muted); padding: 1rem .75rem .35rem; font-weight: 600;
    border-top: 1px solid var(--app-border); margin-top: .5rem;
}
.side-class-dot {
    width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-size: .8rem; font-weight: 600;
}

/* -------- main ------------------------------------------------------------- */
.main {
    padding: 1.5rem;
    min-height: calc(100vh - var(--topbar-h));
}
@media (max-width: 575.98px) { .main { padding: 1rem; } }
.page-head {
    display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
    margin-bottom: 1.25rem;
}
.page-head h1, .page-head .h4 { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.page-sub { color: var(--app-muted); font-size: .9rem; }

.card {
    --bs-card-bg: var(--app-surface);
    --bs-card-border-color: var(--app-border);
    --bs-card-cap-bg: transparent;
    border-radius: var(--radius);
    box-shadow: var(--app-shadow);
}
.card-header { padding: 1rem 1.25rem; font-weight: 600; }
.card-body { padding: 1.25rem; }

.modal-content {
    --bs-modal-bg: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 18px;
    box-shadow: var(--app-shadow-lg);
}
.modal-header, .modal-footer { border-color: var(--app-border); }

.form-control, .form-select {
    border-radius: 10px;
    background-color: var(--app-surface);
    border-color: var(--app-border);
    padding: .55rem .85rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 .2rem rgba(var(--app-primary-rgb), .18);
}
.form-check-input:checked { background-color: var(--app-primary); border-color: var(--app-primary); }
.form-label { font-weight: 500; font-size: .9rem; margin-bottom: .35rem; }
.input-group-text { background: var(--app-surface-2); border-color: var(--app-border); }

.table { --bs-table-bg: transparent; --bs-table-hover-bg: var(--app-surface-2); }
.table > :not(caption) > * > * { padding: .75rem .85rem; border-color: var(--app-border); }
.table thead th {
    font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
    color: var(--app-muted); background: var(--app-surface-2); white-space: nowrap;
}
.nav-tabs { border-color: var(--app-border); }
.nav-underline .nav-link { color: var(--app-muted); font-weight: 500; padding: .8rem .25rem; }
.nav-underline .nav-link.active { color: var(--app-primary); border-bottom-color: var(--app-primary); }

.badge-soft {
    background: var(--app-primary-soft); color: var(--app-primary);
    font-weight: 500; border-radius: 999px; padding: .35em .7em;
}
.badge { font-weight: 500; }

/* -------- avatars ---------------------------------------------------------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-sm { width: 32px; height: 32px; font-size: .85rem; }
.avatar-lg { width: 96px; height: 96px; font-size: 2.2rem; }
.avatar-letter {
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-weight: 600;
}

/* -------- stat tiles ------------------------------------------------------- */
.stat {
    display: flex; align-items: center; gap: 1rem;
    padding: 1.1rem 1.25rem;
}
.stat-icon {
    width: 48px; height: 48px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 1.35rem;
    background: var(--app-primary-soft); color: var(--app-primary);
}
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--app-muted); font-size: .85rem; }

/* -------- class cards (Google-Classroom-like) ------------------------------ */
.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; }
.class-card {
    position: relative; overflow: hidden; display: flex; flex-direction: column;
    border-radius: var(--radius); background: var(--app-surface);
    border: 1px solid var(--app-border); box-shadow: var(--app-shadow);
    transition: box-shadow .15s ease;
    min-height: 260px;
}
/* no transform on hover: a transformed card becomes the box of its fixed ⋮ menu, so Popper places
   the menu against the card and overflow: hidden clips it (removing it via :has came too late) */
.class-card:hover { box-shadow: var(--app-shadow-lg); }
.class-card .card-chat-badge { position: absolute; top: -3px; right: -5px; font-size: .65rem; }
.class-card .cover {
    position: relative; padding: 1rem 1.1rem 1.4rem; color: #fff; min-height: 104px;
    background-image: radial-gradient(circle at 85% 20%, rgba(255,255,255,.25) 0, rgba(255,255,255,0) 45%),
                      linear-gradient(135deg, rgba(255,255,255,.08), rgba(0,0,0,.15));
}
.class-card .cover a:not(.dropdown-item) { color: #fff; text-decoration: none; } /* the ⋮ menu keeps its theme colours */
.class-card .cover .name { font-size: 1.2rem; font-weight: 600; display: block; line-height: 1.3;
    overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.class-card .cover .name:hover { text-decoration: underline; }
.class-card .cover .sec { opacity: .92; font-size: .9rem; }
.class-card .cover .owner { font-size: .85rem; opacity: .9; margin-top: .25rem; }
.class-card .owner-avatar {
    position: absolute; right: 1rem; bottom: -30px; width: 64px; height: 64px;
    border: 3px solid var(--app-surface); border-radius: 50%; font-size: 1.5rem;
}
/* Blockly tasks (blockly_kit.js) */
.bk-ws { height: 480px; border: 1px solid var(--app-border); border-radius: .6rem; overflow: hidden; }
#bkModal .bk-ws { height: calc(100vh - 230px); min-height: 360px; }
.bk-panel { border: 1px solid var(--app-border); border-radius: .6rem; padding: .75rem; background: var(--app-surface-2); height: 100%; }
.bk-out { background: #0f172a; color: #e2e8f0; border-radius: .5rem; padding: .6rem .8rem; min-height: 6rem; max-height: 18rem; overflow: auto; white-space: pre-wrap; margin: 0; font-size: .9rem; }
.bk-code { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: .5rem; padding: .5rem .7rem; max-height: 16rem; overflow: auto; font-size: .8rem; margin: 0; white-space: pre; }
.bk-canvas { max-width: 100%; height: auto; border: 1px solid var(--app-border); border-radius: .5rem; background: #fff; display: block; }
.bk-test { width: 11rem; }
.bk-input { font-size: .85rem; }
.bk-box { border: 1px dashed var(--app-border); border-radius: .6rem; padding: .75rem 1rem; }
/* programming work in the post editor: the Blockly / language panels inside #progBox, their own switch + hint driven from outside */
.prog-inner > .d-flex:first-child .form-switch, .prog-inner > .d-flex:first-child + .form-text { display: none !important; }
.prog-inner > .d-flex:first-child { min-height: 0; }
.tl-sub { border-top: 1px dashed var(--app-border); padding-top: .75rem; }
.prog-inner > [data-bk="opts"], .prog-inner > [data-py="opts"] { margin-top: .5rem !important; }
/* Python tasks (pycode.js) */
.py-cm.CodeMirror { border: 1px solid var(--app-border); border-radius: .5rem; height: auto; font-size: .9rem; }
.py-cm .CodeMirror-scroll { min-height: 14rem; max-height: 60vh; }
.py-cm-sm .CodeMirror-scroll { min-height: 6rem; max-height: 40vh; }
textarea.py-plain { width: 100%; min-height: 10rem; font-size: .9rem; }
.py-out { background: var(--bs-tertiary-bg); border: 1px solid var(--app-border); border-radius: .5rem; padding: .5rem .75rem; min-height: 6.6rem; max-height: 40vh; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.py-tests pre { white-space: pre-wrap; word-break: break-word; max-height: 8rem; overflow: auto; }
.rl-pre { background: var(--bs-tertiary-bg); border: 1px solid var(--app-border); border-radius: .4rem; padding: .4rem .55rem; max-height: 16rem; overflow: auto; white-space: pre-wrap; word-break: break-word; margin-bottom: .5rem; }
.py-test { border: 1px dashed var(--app-border); border-radius: .5rem; padding: .5rem; }
[data-bs-theme=dark] .py-cm.CodeMirror { background: var(--app-surface); color: var(--bs-body-color); }
[data-bs-theme=dark] .py-cm .CodeMirror-gutters { background: var(--bs-tertiary-bg); border-color: var(--app-border); }
[data-bs-theme=dark] .py-cm .CodeMirror-linenumber { color: #8b949e; }
[data-bs-theme=dark] .py-cm .CodeMirror-cursor { border-left-color: #e6edf3; }
[data-bs-theme=dark] .py-cm .CodeMirror-selected, [data-bs-theme=dark] .py-cm.CodeMirror-focused .CodeMirror-selected { background: #33415e; }
[data-bs-theme=dark] .py-cm .cm-keyword { color: #c792ea; }
[data-bs-theme=dark] .py-cm .cm-def, [data-bs-theme=dark] .py-cm .cm-variable-2 { color: #82aaff; }
[data-bs-theme=dark] .py-cm .cm-string { color: #c3e88d; }
[data-bs-theme=dark] .py-cm .cm-number { color: #f78c6c; }
[data-bs-theme=dark] .py-cm .cm-comment { color: #8b949e; }
[data-bs-theme=dark] .py-cm .cm-builtin { color: #ffcb6b; }
[data-bs-theme=dark] .py-cm .cm-operator, [data-bs-theme=dark] .py-cm .cm-variable { color: var(--bs-body-color); }
/* task library hub (task_lib.php) + Python library cards (py_lib.js) */
/* classwork: missing work / missed exams per student */
.miss-chip { display: inline-block; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; padding: .15rem .55rem; border-radius: 1rem;
    border: 1px solid var(--bs-danger-border-subtle); background: var(--bs-danger-bg-subtle); color: var(--bs-danger-text-emphasis); text-decoration: none; }
.miss-chip:hover { border-color: var(--bs-danger); }
.miss-table td:first-child { min-width: 12rem; width: 28%; }
.miss-table th:nth-child(2) { width: 6rem; }
.tl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr)); gap: 1rem; align-items: start; }
.tl-card .form-switch .form-check-label { white-space: nowrap; }
.tl-card .tl-count { flex: 1 1 0; min-width: 5.5rem; }
.tl-card { border: 1px solid var(--app-border); border-radius: .9rem; padding: 1.1rem; background: var(--app-surface); transition: opacity .15s; }
.tl-card.tl-off { opacity: .6; }
.tl-card .tl-state { color: var(--bs-success); }
.tl-card.tl-off .tl-state { color: var(--bs-secondary-color); }
.tl-icon { width: 3rem; height: 3rem; border-radius: .8rem; display: grid; place-items: center; font-size: 1.5rem; flex: none; }
.tl-count { display: flex; flex-direction: column; min-width: 6.5rem; padding: .45rem .7rem; border: 1px solid var(--app-border); border-radius: .6rem; text-decoration: none; color: inherit; }
.tl-count:hover { border-color: var(--bs-primary); }
.pyl-code { background: var(--bs-tertiary-bg); border: 1px solid var(--app-border); border-radius: .5rem; padding: .5rem .65rem; height: 7.5rem; overflow: hidden; white-space: pre; font-size: .8rem; }
.pyl-code-empty { display: grid; place-items: center; font-size: 2rem; color: var(--bs-secondary-color); }
.bkl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem; }
.bkl-card { display: flex; flex-direction: column; gap: .5rem; border: 1px solid var(--app-border); border-radius: .75rem; padding: .75rem; background: var(--app-surface); text-align: left; color: inherit; }
button.bkl-card:hover, .bkl-card:hover { border-color: var(--bs-primary); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.bkl-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: .5rem; border: 1px solid var(--app-border); background: #fff; cursor: pointer; display: block; }
.bkl-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bk-maze-grid { display: grid; gap: 2px; width: max-content; }
.bk-cell { width: 1.6rem; height: 1.6rem; border: 0; border-radius: 3px; font-size: .8rem; line-height: 1; padding: 0; }
.bk-wall { background: #475569; } .bk-path { background: #e2e8f0; } .bk-start { background: #bfdbfe; } .bk-goal { background: #bbf7d0; }
.blocklyWidgetDiv, .blocklyDropDownDiv, .blocklyTooltipDiv { z-index: 1100 !important; } /* above the dialogs */
/* toolbox (side menu): clear text in the page's colours, white on the chosen category */
.blocklyToolbox { background: var(--app-surface-2) !important; border-right: 1px solid var(--app-border); padding: 4px 0; }
.blocklyToolboxCategory { margin: 2px 4px 2px 0; border-radius: 0 .5rem .5rem 0; }
.blocklyToolboxCategoryLabel { color: var(--app-text) !important; font-family: inherit !important; font-size: .95rem !important; font-weight: 600; padding: 6px 10px 6px 6px; }
.blocklyToolboxCategory:hover { background: rgba(var(--app-primary-rgb), .1); }
.blocklyToolboxSelected .blocklyToolboxCategoryLabel { color: #fff !important; }
.blocklyFlyoutBackground { fill: var(--app-surface) !important; fill-opacity: .97 !important; }
/* Blockly card in full screen (post.js) */
.bk-full-only { display: none; }
#bkCard.bk-full, #pyCard.bk-full { position: fixed; inset: 0; z-index: 1040; margin: 0 !important; border-radius: 0; overflow: auto; }
#bkCard.bk-full .bk-full-only, #pyCard.bk-full .bk-full-only { display: inline-flex; }
#pyCard.bk-full .py-cm .CodeMirror-scroll { min-height: max(360px, calc(100vh - 420px)); max-height: none; } /* full screen: a tall editor, input / output / tests below */
#bkCard.bk-full .bk-ws { height: calc(100vh - 150px); min-height: 360px; }
#bkCard.bk-full .bk-panel { max-height: calc(100vh - 150px); overflow: auto; }
html.bk-full-page { overflow: hidden; }
/* science work (science.js): a simulation frame / 3D molecule, the PhET picker, full screen on the post page */
.sci-stage { position: relative; width: 100%; aspect-ratio: 16 / 10; max-height: 78vh; border: 1px solid var(--app-border); border-radius: .5rem; overflow: hidden; background: #fff; }
.sci-stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.sci-stage.sci-mol { aspect-ratio: 4 / 3; max-height: 60vh; }
[data-bs-theme="dark"] .sci-stage.sci-mol { background: #1e2227; }
.sci-mol-load { position: absolute; inset: 0; display: grid; place-items: center; }
#sciCard.bk-full { position: fixed; inset: 0; z-index: 1040; margin: 0 !important; border-radius: 0; overflow: auto; }
#sciCard.bk-full .bk-full-only { display: inline-flex; }
#sciCard.bk-full .sci-stage { aspect-ratio: auto; height: calc(100vh - 110px); max-height: none; }
.sci-sims { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; max-height: 340px; overflow: auto; padding: 2px; }
.sci-sim { display: flex; flex-direction: column; text-align: left; gap: .15rem; padding: .35rem; border: 1px solid var(--app-border); border-radius: .5rem; background: var(--app-surface); color: inherit; }
.sci-sim:hover { border-color: var(--bs-primary); }
.sci-sim.active { border-color: var(--bs-primary); box-shadow: 0 0 0 2px var(--bs-primary); }
.sci-sim img { width: 100%; aspect-ratio: 420 / 272; object-fit: cover; border-radius: .35rem; background: var(--bs-tertiary-bg); }
.sci-sim-t { font-size: .8rem; font-weight: 600; line-height: 1.25; }
.sci-sim-e { font-size: .7rem; color: var(--bs-secondary-color); line-height: 1.2; }
.sci-card-img { height: 7.5rem; border: 1px solid var(--app-border); border-radius: .5rem; overflow: hidden; background: var(--bs-tertiary-bg); }
.sci-card-img img { width: 100%; height: 100%; object-fit: cover; }
.sci-num-list { padding-left: 1.4rem; margin-bottom: .5rem; }
.sci-num-item { padding: .5rem 0; border-bottom: 1px dashed var(--app-border); }
.sci-num-item:last-child { border-bottom: 0; }
.sci-num-in { width: 10rem; font-variant-numeric: tabular-nums; }
.sci-num-unit { width: 7rem; }
.sci-num-u { font-weight: 600; }
.sci-num-edit .sci-var input { min-width: 0; }
/* chemistry (science.js): equations with coefficient boxes, JSME drawings */
.sci-eq { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .5rem; font-size: 1.05rem; }
.sci-eq-sp { display: inline-flex; align-items: center; gap: .25rem; }
.sci-eq-co { width: 3.2rem; text-align: center; font-variant-numeric: tabular-nums; }
.sci-eq-op { font-weight: 600; color: var(--bs-secondary-color); }
.sci-eq-f, .sci-f-prev { font-weight: 500; }
.sci-draw { max-width: 100%; overflow-x: auto; }
.sci-jsme { border: 1px solid var(--app-border); border-radius: .5rem; overflow: hidden; display: inline-block; background: #fff; }
.sci-card-eq { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; text-align: left; place-items: center start; padding: .5rem; }
/* label the parts (science.js): markers on an image */
.sci-lbl-stage { position: relative; display: inline-block; max-width: 100%; line-height: 0; border: 1px solid var(--app-border); border-radius: .5rem; overflow: hidden; background: #fff; user-select: none; touch-action: none; }
.sci-lbl-stage img { max-width: 100%; max-height: 70vh; display: block; }
.sci-lbl-small img { max-height: 280px; }
.sci-lbl-editing { cursor: crosshair; }
.sci-mark { position: absolute; transform: translate(-50%, -50%); min-width: 1.6rem; height: 1.6rem; padding: 0 .3rem; border-radius: 1rem; background: #dc3545; color: #fff; font: 600 .8rem/1.6rem system-ui, sans-serif; text-align: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); cursor: pointer; }
.sci-lbl-editing .sci-mark { cursor: grab; }
.sci-mark.active { background: var(--bs-primary); transform: translate(-50%, -50%) scale(1.25); z-index: 2; }
.sci-mark-static { position: static; transform: none; display: inline-block; flex: none; cursor: default; }
.sci-lbl-answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .4rem .9rem; }
.sci-lbl-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.sci-lbl-row [data-a] { flex: 1 1 140px; min-width: 0; }
.sci-lbl-empty { display: grid; place-items: center; min-height: 180px; border: 2px dashed var(--app-border); border-radius: .5rem; color: var(--bs-secondary-color); line-height: 1.4; }
.sci-lbl-key { columns: 2; padding-left: 1.6rem; }
.sci-card-fit img { object-fit: contain; background: #fff; }
.sci-help { background: var(--bs-tertiary-bg); border: 1px solid var(--app-border); border-radius: .5rem; padding: .5rem .75rem; }
.sci-help code, .sci-num-list code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", "Noto Sans Thai", "Noto Sans Lao", monospace; }
html.bk-full-page #toastArea { top: 3.25rem !important; } /* keep the header buttons clickable */
/* matching questions (bank_more.js editor + list, exam.js) */
.match-no { min-width: 1.6rem; text-align: right; color: var(--app-muted); font-variant-numeric: tabular-nums; }
.match-edit-row textarea { resize: vertical; }
.match-table td { vertical-align: middle; }
.match-q { padding: .5rem .6rem; border: 1px solid var(--app-border); border-radius: .6rem; background: var(--app-surface); }
.match-q.done { border-color: rgba(var(--app-primary-rgb), .45); background: var(--app-primary-soft); }
.match-pick { width: 4.5rem; flex-shrink: 0; font-weight: 600; }
.match-options { display: flex; flex-direction: column; gap: .4rem; }
.match-opt { display: flex; gap: .6rem; align-items: flex-start; padding: .45rem .6rem; border: 1px dashed var(--app-border); border-radius: .6rem; }
.match-opt .key { font-weight: 700; color: var(--app-primary); min-width: 1.2rem; }
.match-opt.used { opacity: .55; }
.tf-choices { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.tf-choices .choice { justify-content: center; font-size: 1.15rem; font-weight: 600; padding: 1rem; }
.tf-choices .tf-1 .key { color: var(--app-success); }
.tf-choices .tf-2 .key { color: var(--app-danger); }
/* teaching evaluation (class_eval.js) */
.ev-dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: var(--app-danger); margin-left: .35rem; vertical-align: super; }
.ev-no { min-width: 1.6rem; text-align: right; color: var(--app-muted); font-variant-numeric: tabular-nums; }
.ev-item textarea { resize: none; overflow: hidden; }
.ev-legend { display: flex; flex-wrap: wrap; gap: .35rem 1rem; padding: .5rem .75rem; border-radius: .5rem; background: var(--app-surface-2); }
.ev-instructions { padding: .75rem 1rem; border-left: 3px solid var(--app-primary); background: var(--app-primary-soft); border-radius: .35rem; }
.ev-q { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; padding: .6rem .25rem; border-bottom: 1px solid var(--app-border); }
.ev-q-text { flex: 1 1 320px; }
.ev-scale .btn { min-width: 2.75rem; font-weight: 600; }
.ev-q.ev-missing { background: rgba(225, 29, 72, .07); border-radius: .35rem; }
.ev-q.ev-missing .ev-q-text::after { content: " *"; color: var(--app-danger); font-weight: 700; }
.ev-stat { padding: .6rem 1rem; border: 1px solid var(--app-border); border-radius: .75rem; background: var(--app-surface); min-width: 9rem; }
.ev-stat-n { font-size: 1.6rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.ev-stat-n small { font-size: 1rem; color: var(--app-muted); font-weight: 600; }
.ev-table td, .ev-table th { font-variant-numeric: tabular-nums; }
.ev-dist { min-width: 3.25rem; }
.ev-bar { height: .3rem; background: var(--app-surface-2); border-radius: 1rem; margin-top: .15rem; overflow: hidden; }
.ev-bar span { display: block; height: 100%; background: var(--app-primary); }
.ev-lv { font-weight: 600; }
.ev-eval_lv_5 { background: #15803d; color: #fff; }
.ev-eval_lv_4 { background: #65a30d; color: #fff; }
.ev-eval_lv_3 { background: #ca8a04; color: #fff; }
.ev-eval_lv_2 { background: #ea580c; color: #fff; }
.ev-eval_lv_1 { background: #dc2626; color: #fff; }
@media (max-width: 575.98px) { .ev-scale { width: 100%; } .ev-scale .btn { flex: 1; } }
/* class code shown huge (App.showBigCode), readable from the back of the room */
.big-code .modal-body { gap: .5rem; }
.big-code-label { font-size: clamp(1.25rem, 3vw, 2.25rem); color: var(--app-muted); font-weight: 600; }
.big-code-value { font-size: clamp(3.5rem, 16vw, 15rem); font-weight: 700; line-height: 1.05; letter-spacing: .12em; color: var(--app-primary);
    overflow-wrap: anywhere; user-select: all; }
.big-code-hint { font-size: clamp(1rem, 2.2vw, 1.6rem); color: var(--app-muted); }
#bcTitle { font-size: clamp(1.1rem, 2.5vw, 1.8rem); font-weight: 700; }
.class-card .body { flex: 1; padding: 2.25rem 1.1rem .75rem; color: var(--app-muted); font-size: .9rem; }
.class-card .foot {
    border-top: 1px solid var(--app-border); padding: .4rem .6rem;
    display: flex; justify-content: flex-end; gap: .25rem;
}
.class-banner {
    border-radius: var(--radius); color: #fff; padding: 1.05rem 1.75rem .9rem;
    min-height: 108px; display: flex; flex-direction: column; justify-content: flex-end;
    background-image: radial-gradient(circle at 90% 10%, rgba(255,255,255,.28) 0, rgba(255,255,255,0) 40%),
                      radial-gradient(circle at 10% 120%, rgba(0,0,0,.25) 0, rgba(0,0,0,0) 50%);
    position: relative; overflow: hidden;
}
.class-banner h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 700; margin: 0; }
.class-banner .meta { opacity: .95; }
.class-banner .banner-icon { position: absolute; right: 1.5rem; top: .6rem; font-size: 3rem; opacity: .18; }

.class-code-box { font-size: 1.6rem; font-weight: 700; letter-spacing: .08em; color: var(--app-primary); }

/* -------- stream ----------------------------------------------------------- */
.post-card { border-radius: var(--radius); }
.post-icon {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.1rem;
}
.post-icon.t-announcement { background: #64748b; }
.post-icon.t-material { background: #0ea5e9; }
.post-icon.t-assignment { background: var(--app-primary); }
.post-icon.t-exam { background: #f97316; }
.post-content { white-space: pre-wrap; word-break: break-word; }
.attach-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem; }
.attach {
    display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem;
    border: 1px solid var(--app-border); border-radius: 10px; background: var(--app-surface);
    text-decoration: none; color: var(--app-text); min-width: 0;
}
.attach:hover { border-color: var(--app-primary); color: var(--app-text); }
.attach .ico { width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 1.15rem; }
.attach .t { font-size: .9rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach .p { font-size: .75rem; color: var(--app-muted); }
.attach .thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.ico-youtube { background: #fee2e2; color: #dc2626; }
.ico-gdrive { background: #dcfce7; color: #16a34a; }
.ico-dropbox { background: #dbeafe; color: #2563eb; }
.ico-onedrive { background: #e0f2fe; color: #0284c7; }
.ico-github { background: #e5e7eb; color: #111827; }
.ico-canva { background: #ede9fe; color: #7c3aed; }
.ico-link { background: var(--app-primary-soft); color: var(--app-primary); }
.ico-pdf { background: #fee2e2; color: #dc2626; }
[data-bs-theme="dark"] .ico-youtube { background: rgba(220,38,38,.18); }
[data-bs-theme="dark"] .ico-gdrive { background: rgba(22,163,74,.18); }
[data-bs-theme="dark"] .ico-dropbox { background: rgba(37,99,235,.2); }
[data-bs-theme="dark"] .ico-onedrive { background: rgba(2,132,199,.2); }
[data-bs-theme="dark"] .ico-github { background: rgba(255,255,255,.1); color: #e5e7eb; }
[data-bs-theme="dark"] .ico-canva { background: rgba(124,58,237,.2); }
[data-bs-theme="dark"] .ico-pdf { background: rgba(220,38,38,.2); color: #f87171; }

.work-item {
    display: flex; align-items: center; gap: .9rem; padding: .85rem 1rem;
    border-bottom: 1px solid var(--app-border); text-decoration: none; color: var(--app-text);
}
.work-item:last-child { border-bottom: 0; }
.work-item:hover { background: var(--app-surface-2); color: var(--app-text); }
.work-meta { display: flex; align-items: center; gap: .9rem; flex-shrink: 0; }
.work-stats { display: flex; gap: .25rem; flex-shrink: 0; text-align: center; }
.work-stats > div { min-width: 4.25rem; padding: 0 .35rem; }
.work-stats > div + div { border-left: 1px solid var(--app-border); }
.work-stat-n { font-size: 1.15rem; font-weight: 600; line-height: 1.2; }
.work-stat-l { font-size: .72rem; color: var(--app-muted); white-space: nowrap; }
.topic-title { font-size: 1.35rem; font-weight: 600; color: var(--app-primary); padding-bottom: .5rem;
    border-bottom: 1px solid var(--app-primary); margin: 1.5rem 0 .5rem; }

.comment { display: flex; gap: .7rem; padding: .6rem 0; }
.comment .bubble { flex: 1; min-width: 0; }
/* the user's own comment: on the right, in a bubble the size of the message */
.comment.comment-mine { flex-direction: row-reverse; }
.comment.comment-mine .bubble { flex: 0 1 auto; max-width: 85%; text-align: right; background: var(--bs-primary-bg-subtle); border-radius: .9rem .25rem .9rem .9rem; padding: .4rem .75rem; }
.comment.comment-mine .bubble .ws-pre { text-align: left; }

/* -------- empty / loading -------------------------------------------------- */
.empty {
    text-align: center; padding: 3rem 1rem; color: var(--app-muted);
}
.empty i { font-size: 3rem; display: block; margin-bottom: .75rem; opacity: .5; }
.skeleton {
    background: linear-gradient(90deg, var(--app-surface-2) 25%, var(--app-border) 37%, var(--app-surface-2) 63%);
    background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: 10px;
}
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.confirm-icon i { font-size: 2.75rem; color: var(--app-warning); }

/* -------- question bank ---------------------------------------------------- */
.q-card { border-left: 4px solid var(--app-primary); }
.q-text { white-space: pre-wrap; word-break: break-word; font-weight: 500; }
.q-choices { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .25rem; }
.q-choices li { padding: .3rem .6rem; border-radius: 8px; font-size: .92rem; }
.q-choices li.correct { background: rgba(22, 163, 74, .12); color: var(--app-success); font-weight: 600; }
.q-choices li .lbl { display: inline-block; width: 1.6rem; font-weight: 600; }
.choice-row .input-group-text { min-width: 46px; justify-content: center; font-weight: 600; }
.qimg-preview { display: flex; gap: .75rem; align-items: flex-start; margin-bottom: .5rem; }
.qimg-preview img { max-width: min(100%, 320px); max-height: 200px; border-radius: 8px; border: 1px solid var(--app-border); background: #fff; }
.qi-text { font-size: .85rem; line-height: 1.45; }
.qi-preview { max-height: 62vh; overflow-y: auto; display: grid; gap: .5rem; align-content: start; }
.qi-item { border: 1px solid var(--app-border); border-left: 4px solid var(--app-success); border-radius: 10px; padding: .6rem .75rem; background: var(--app-surface); }
.qi-item.has-warn { border-left-color: var(--app-danger); }
.qi-choices { display: grid; gap: .15rem; margin-top: .4rem; }
.qi-choice { display: flex; gap: .5rem; align-items: flex-start; padding: .2rem .5rem; border-radius: 8px; font-size: .9rem; cursor: pointer; }
.qi-choice .form-check-input { margin-top: .2rem; flex-shrink: 0; }
.qi-choice .lbl { font-weight: 600; min-width: 1.2rem; }
.qi-choice.correct { background: rgba(22, 163, 74, .12); color: var(--app-success); font-weight: 600; }
.choice-row .form-check-input { margin: 0; cursor: pointer; }
.picker-list { max-height: 60vh; overflow-y: auto; }
.picker-item { display: flex; gap: .75rem; padding: .7rem .5rem; border-bottom: 1px solid var(--app-border); cursor: pointer; }
.picker-item:hover { background: var(--app-surface-2); }
.set-item { display: flex; gap: .75rem; align-items: flex-start; padding: .75rem; border: 1px solid var(--app-border);
    border-radius: 12px; background: var(--app-surface); margin-bottom: .5rem; }
.set-item .no { width: 32px; height: 32px; border-radius: 50%; background: var(--app-primary-soft); color: var(--app-primary);
    display: flex; align-items: center; justify-content: center; font-weight: 600; flex-shrink: 0; }
.set-item.dragging { opacity: .5; }
.drag-handle { cursor: grab; color: var(--app-muted); }

/* -------- exam taking ------------------------------------------------------ */
body.bare { background: var(--app-bg); }
.exam-top {
    position: sticky; top: 0; z-index: 20;
    background: var(--app-surface); border-bottom: 1px solid var(--app-border);
    padding: .6rem 1rem; box-shadow: var(--app-shadow);
}
.exam-wrap { max-width: 780px; margin: 0 auto; padding: 1rem 1rem 6rem; }
.timer {
    display: inline-flex; align-items: center; gap: .4rem; font-variant-numeric: tabular-nums;
    padding: .3rem .7rem; border-radius: 999px; font-weight: 600; font-size: .95rem;
    background: var(--app-surface-2); border: 1px solid var(--app-border);
}
.timer.warn { background: rgba(245, 158, 11, .15); color: #b45309; border-color: rgba(245, 158, 11, .5); }
.timer.danger { background: rgba(225, 29, 72, .14); color: var(--app-danger); border-color: rgba(225, 29, 72, .5); animation: pulse 1s infinite; }
[data-bs-theme="dark"] .timer.warn { color: #fbbf24; }
@keyframes pulse { 50% { opacity: .55; } }
.exam-progress { height: 6px; border-radius: 999px; background: var(--app-surface-2); overflow: hidden; }
.exam-progress > div { height: 100%; background: linear-gradient(90deg, #6366f1, #0ea5e9); transition: width .3s; }
.exam-q { font-size: 1.12rem; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.essay-answer { font-size: 1.05rem; line-height: 1.7; min-height: 14rem; resize: vertical; }
.essay-text { white-space: pre-wrap; word-break: break-word; background: var(--app-surface-2); border-radius: .5rem; padding: .75rem; }
.ai-box { background: var(--bs-primary-bg-subtle); border-left: 3px solid var(--bs-primary); border-radius: .5rem; padding: .5rem .75rem; }
.ai-box-error { background: var(--bs-danger-bg-subtle); border-left-color: var(--bs-danger); }
.exam-preview-bar { position: sticky; top: 0; z-index: 1030; padding: .4rem 1rem; text-align: center; font-size: .9rem; font-weight: 500;
    background: repeating-linear-gradient(45deg, #fef3c7, #fef3c7 12px, #fde68a 12px, #fde68a 24px); color: #78350f; }
.exam-preview-bar a { color: #78350f; font-weight: 600; }
.exam-q-img { max-width: 100%; max-height: 360px; border-radius: 12px; border: 1px solid var(--app-border); }
.exam-q-img-btn { position: relative; display: inline-block; max-width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.exam-q-img-btn .exam-q-img { display: block; }
.exam-q-img-btn .zoom-hint { position: absolute; right: .5rem; bottom: .5rem; width: 2rem; height: 2rem; display: grid; place-items: center;
    border-radius: 8px; background: rgba(0, 0, 0, .55); color: #fff; font-size: .9rem; }
.img-viewer .modal-content { background: #0b0d14; color: #fff; border: 0; border-radius: 0; }
.img-viewer-bar { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; background: rgba(0, 0, 0, .4); }
.img-viewer-bar .btn-icon { color: #fff; }
.img-viewer-bar .timer { background: rgba(255, 255, 255, .1); color: #fff; }
.img-viewer-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: .75rem; overflow: auto; cursor: zoom-out; }
.img-viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; background: #fff; border-radius: 4px; }
.img-viewer-body.zoomed { display: block; }
.img-viewer-body.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.choice {
    display: flex; align-items: flex-start; gap: .85rem; width: 100%;
    padding: .95rem 1rem; margin-bottom: .65rem; text-align: left;
    border: 2px solid var(--app-border); border-radius: 14px; background: var(--app-surface);
    color: var(--app-text); cursor: pointer; transition: border-color .12s, background .12s;
    font-size: 1rem;
}
.choice:hover:not(:disabled) { border-color: rgba(var(--app-primary-rgb), .55); }
.choice .key {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-weight: 700;
    background: var(--app-surface-2); border: 1px solid var(--app-border);
}
.choice .txt { padding-top: 4px; white-space: pre-wrap; word-break: break-word; }
.choice.selected { border-color: var(--app-primary); background: var(--app-primary-soft); }
.choice.selected .key { background: var(--app-primary); color: #fff; border-color: var(--app-primary); }
[data-bs-theme="dark"] .choice.selected .key { color: #0f1220; }
.choice:disabled { cursor: not-allowed; opacity: .75; }
.exam-bottom {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--app-surface); border-top: 1px solid var(--app-border);
    padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
}
.exam-bottom .inner { max-width: 780px; margin: 0 auto; display: flex; gap: .5rem; align-items: center; }
.qnav { display: flex; flex-wrap: wrap; gap: .4rem; }
.qnav button {
    width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--app-border);
    background: var(--app-surface); color: var(--app-text); font-weight: 600; font-size: .85rem;
}
.qnav button.answered { background: var(--app-primary-soft); border-color: var(--app-primary); color: var(--app-primary); }
.qnav button.current { outline: 2px solid var(--app-primary); outline-offset: 1px; }
.qnav button.locked { opacity: .45; }
.qnav-part { flex-basis: 100%; font-size: .8rem; font-weight: 600; color: var(--bs-secondary-color); margin-top: .35rem; }
.qnav-part:first-child { margin-top: 0; }
.exam-part { display: inline-block; font-size: .85rem; font-weight: 600; padding: .25rem .7rem; border-radius: 999px; background: var(--app-primary-soft); color: var(--app-primary); }
.save-state { font-size: .8rem; color: var(--app-muted); }
.result-ring {
    width: 160px; height: 160px; border-radius: 50%; margin: 0 auto;
    display: flex; align-items: center; justify-content: center; flex-direction: column;
    background: conic-gradient(var(--app-primary) calc(var(--p) * 1%), var(--app-surface-2) 0);
    position: relative;
}
.result-ring::before { content: ""; position: absolute; inset: 12px; background: var(--app-surface); border-radius: 50%; }
.result-ring > * { position: relative; }

/* -------- auth pages ------------------------------------------------------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem 1rem;
    background:
        radial-gradient(900px 500px at 0% 0%, rgba(99, 102, 241, .18), transparent 60%),
        radial-gradient(900px 500px at 100% 100%, rgba(14, 165, 233, .16), transparent 60%),
        var(--app-bg);
}
.auth-card { width: 100%; max-width: 440px; }
.auth-card.wide { max-width: 560px; }
.auth-card .card-body { padding: 2rem; }
@media (max-width: 575.98px) { .auth-card .card-body { padding: 1.4rem; } }
.auth-logo { width: 56px; height: 56px; border-radius: 16px; font-size: 1.7rem; }
.brand-logo-img { background: none; border-radius: 0; }
.brand-logo-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.auth-logo.brand-logo-img { width: 72px; height: 72px; }
.brand-preview { width: 72px; height: 72px; }
.brand-fav { width: 32px; height: 32px; border-radius: 6px; overflow: hidden; }
.brand-fav img, .brand-fav svg { width: 100%; height: 100%; display: block; }
.divider-text { display: flex; align-items: center; gap: .75rem; color: var(--app-muted); font-size: .85rem; margin: 1.25rem 0; }
.divider-text::before, .divider-text::after { content: ""; flex: 1; height: 1px; background: var(--app-border); }
.btn-google { background: var(--app-surface); border: 1px solid var(--app-border); color: var(--app-text); }
.btn-google:hover { background: var(--app-surface-2); color: var(--app-text); }
.auth-tools { position: fixed; top: 1rem; right: 1rem; display: flex; gap: .4rem; z-index: 5; }
.auth-tools .btn-icon { background: var(--app-surface); border: 1px solid var(--app-border); }

/* -------- flatpickr dark --------------------------------------------------- */
[data-bs-theme="dark"] .flatpickr-calendar { background: var(--app-surface); box-shadow: var(--app-shadow-lg); border: 1px solid var(--app-border); }
[data-bs-theme="dark"] .flatpickr-calendar.arrowTop::after { border-bottom-color: var(--app-surface); }
[data-bs-theme="dark"] .flatpickr-calendar.arrowBottom::after { border-top-color: var(--app-surface); }
[data-bs-theme="dark"] .flatpickr-months .flatpickr-month,
[data-bs-theme="dark"] .flatpickr-current-month .flatpickr-monthDropdown-months,
[data-bs-theme="dark"] span.flatpickr-weekday,
[data-bs-theme="dark"] .flatpickr-months .flatpickr-prev-month,
[data-bs-theme="dark"] .flatpickr-months .flatpickr-next-month { color: var(--app-text); fill: var(--app-text); background: transparent; }
[data-bs-theme="dark"] .flatpickr-current-month .flatpickr-monthDropdown-months option { background: var(--app-surface); }
[data-bs-theme="dark"] .flatpickr-day { color: var(--app-text); }
[data-bs-theme="dark"] .flatpickr-day:hover { background: var(--app-surface-2); border-color: var(--app-surface-2); }
[data-bs-theme="dark"] .flatpickr-day.prevMonthDay, [data-bs-theme="dark"] .flatpickr-day.nextMonthDay,
[data-bs-theme="dark"] .flatpickr-day.flatpickr-disabled { color: #5b6280; }
[data-bs-theme="dark"] .flatpickr-time input, [data-bs-theme="dark"] .flatpickr-time .flatpickr-am-pm,
[data-bs-theme="dark"] .flatpickr-time .flatpickr-time-separator { color: var(--app-text); }
[data-bs-theme="dark"] .flatpickr-time input:hover, [data-bs-theme="dark"] .flatpickr-time input:focus { background: var(--app-surface-2); }
[data-bs-theme="dark"] .flatpickr-calendar.hasTime .flatpickr-time { border-top-color: var(--app-border); }
[data-bs-theme="dark"] .numInputWrapper span.arrowUp::after { border-bottom-color: var(--app-text); }
[data-bs-theme="dark"] .numInputWrapper span.arrowDown::after { border-top-color: var(--app-text); }
.flatpickr-day.selected, .flatpickr-day.selected:hover, .flatpickr-day.today.selected { background: var(--app-primary); border-color: var(--app-primary); }
.flatpickr-input[readonly] { background-color: var(--app-surface); }

/* -------- misc ------------------------------------------------------------- */
.cursor-pointer { cursor: pointer; }
.text-muted, .text-body-secondary { color: var(--app-muted) !important; }
.min-w-0 { min-width: 0; }
.ws-pre { white-space: pre-wrap; word-break: break-word; }
.mono, .py-cm.CodeMirror { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", monospace, "Noto Sans Thai", "Noto Sans Lao"; }
.table-responsive { border-radius: var(--radius); }
.pagination { --bs-pagination-bg: var(--app-surface); --bs-pagination-border-color: var(--app-border);
    --bs-pagination-active-bg: var(--app-primary); --bs-pagination-active-border-color: var(--app-primary); }
.grade-input { width: 90px; }
.sticky-col { position: sticky; left: 0; background: var(--app-surface); z-index: 1; }
.list-group { --bs-list-group-bg: var(--app-surface); --bs-list-group-border-color: var(--app-border); }
.toast { border-radius: 12px; border: 0; box-shadow: var(--app-shadow-lg); }
@media (min-width: 992px) { .sidebar.offcanvas-lg { background-color: var(--app-surface) !important; } }
[data-bs-theme="dark"] .badge.text-bg-light { background-color: var(--app-surface-2) !important; color: var(--app-text) !important; }
[data-bs-theme="dark"] .badge.text-bg-light.border { border-color: var(--app-border) !important; }

/* -------- collapsible sidebar (desktop, icons only) ----------------------- */
@media (min-width: 992px) {
    .sidebar, .main { transition: width .2s ease, margin-left .2s ease; }
    .sidebar { overflow-x: hidden; }
    html.sidebar-collapsed { --sidebar-w: 76px; }
    html.sidebar-collapsed .sidebar-body { padding: .75rem .5rem 2rem; }
    html.sidebar-collapsed .side-link {
        justify-content: center; margin-left: 0; padding: .65rem 0; border-radius: 12px; gap: 0;
    }
    html.sidebar-collapsed .side-link > span { display: none; }
    html.sidebar-collapsed .side-link i { font-size: 1.25rem; }
    html.sidebar-collapsed .side-title { font-size: 0; padding: 0; margin: .6rem .25rem; height: 0; }
    html.sidebar-collapsed .side-classes > .small { display: none; }
}

/* -------- dashboard charts ------------------------------------------------- */
.colchart { --cc-h: 180px; }
.cc-plot { position: relative; height: var(--cc-h); margin-left: 28px; }
.cc-grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--app-border); }
.cc-grid span { position: absolute; right: calc(100% + 6px); top: -.6em; font-size: .7rem; color: var(--app-muted); font-variant-numeric: tabular-nums; }
.cc-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.cc-cols.dense { gap: 1px; }
.cc-col { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: crosshair; min-width: 0; }
.cc-bar { width: 100%; background: var(--app-primary); border-radius: 4px 4px 0 0; min-height: 0; transition: opacity .1s; }
.cc-cols.dense .cc-bar { border-radius: 2px 2px 0 0; }
.cc-bar.zero { height: 0 !important; }
.cc-cols:hover .cc-col:not(.hover) .cc-bar { opacity: .45; }
.cc-col.hover { background: var(--app-primary-soft); border-radius: 4px 4px 0 0; }
.cc-x { display: flex; justify-content: space-between; margin: .4rem 0 0 28px; font-size: .72rem; color: var(--app-muted); }
.chart-tip {
    position: fixed; z-index: 2000; display: none; pointer-events: none;
    background: var(--app-surface); color: var(--app-text); border: 1px solid var(--app-border);
    border-radius: 10px; box-shadow: var(--app-shadow-lg); padding: .45rem .7rem; font-size: .85rem;
}
.tip-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--app-primary); margin-right: .4rem; }
.hbar-row { display: grid; grid-template-columns: minmax(0, 42%) 1fr 36px; align-items: center; gap: .75rem; padding: .3rem 0; font-size: .9rem; }
.hbar-label { display: flex; align-items: center; }
.hbar-track { height: 10px; border-radius: 999px; background: var(--app-surface-2); overflow: hidden; }
.hbar-fill { height: 100%; background: var(--app-primary); border-radius: 999px; }
.hbar-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--app-success); box-shadow: 0 0 0 3px rgba(22,163,74,.2); vertical-align: middle; }
#rangePick .btn.active { background: var(--app-primary-soft); color: var(--app-primary); border-color: var(--app-primary); }

/* -------- content viewer ---------------------------------------------------- */
.clamp-4 { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-4:hover { color: var(--app-primary); }
#viewModal .modal-content { border-radius: 0; border: 0; }
#viewModal .modal-header { position: sticky; top: 0; background: var(--app-surface); }
#viewModal .modal-body { background: var(--app-bg); }
.viewer-wrap { max-width: 920px; margin: 0 auto; padding: .5rem 0 2rem; }
.viewer-text { font-size: 1.05rem; line-height: 1.8; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius); padding: 1.25rem 1.5rem; }
.viewer-embed iframe { border: 0; border-radius: 12px; background: #000; }

.focus-flash { outline: 3px solid var(--app-primary); outline-offset: 4px; border-radius: 12px; transition: outline-color 1s; }

/* -------- in-app link viewer (stacks above other modals) ------------------- */
#linkViewer { z-index: 1070; }
.modal-backdrop.lv-backdrop { z-index: 1065; }
/* a dialog opened from inside another one (e.g. AI try over the essay editor) */
.modal.modal-over { z-index: 1060; }
.qr-box { width: min(420px, 100%); aspect-ratio: 1; padding: 14px; background: #fff; border-radius: 12px; border: 1px solid var(--app-border); }
.qr-box img, .qr-box canvas { width: 100% !important; height: auto !important; display: block; }
.modal-fullscreen .qr-box { width: min(72vh, 100%); }
.qr-turn { height: 6px; width: min(420px, 100%); }
.qr-list { max-height: 60vh; overflow-y: auto; }
.sa-results { max-height: 280px; overflow-y: auto; }
.sa-results .list-group-item { cursor: pointer; }
.i2p-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.i2p-item { border: 1px solid var(--app-border); border-radius: .6rem; padding: .4rem; background: var(--app-surface); }
.i2p-thumb { aspect-ratio: 3 / 4; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--app-surface-2); border-radius: .4rem; }
.i2p-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .2s; }
.modal-backdrop.over-backdrop { z-index: 1058; }
#linkViewer .modal-content { border-radius: 0; border: 0; }
#linkViewer .modal-body { background: var(--app-bg); display: flex; }
.lv-ico { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.lv-ico-lg { width: 72px; height: 72px; border-radius: 18px; display: inline-flex; align-items: center; justify-content: center; font-size: 2rem; }
.lv-stage { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; min-height: 60vh; }
.lv-stage iframe { width: 100%; height: 100%; min-height: 70vh; border: 0; border-radius: 12px; background: var(--app-surface); }
.lv-stage.lv-video { display: flex; align-items: center; }
.lv-stage.lv-video iframe { height: auto; min-height: 0; aspect-ratio: 16 / 9; background: #000; }
.lv-card { margin: auto; max-width: 520px; padding: 2.5rem 1.5rem; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius); }

/* -------- attendance ------------------------------------------------------- */
.att-table { font-size: .88rem; }
.att-table th, .att-table td { white-space: nowrap; }
.att-table .att-week { min-width: 66px; }
.att-table .sticky-col.att-no { left: 0; width: 44px; min-width: 44px; max-width: 44px; }
.att-table .sticky-col.att-code { left: 44px; min-width: 104px; }
.att-table .sticky-col.att-name { left: 148px; min-width: 180px; box-shadow: 1px 0 0 var(--app-border); }
.att-table thead .sticky-col { background: var(--app-surface-2); z-index: 2; }
.att-sel {
    width: 60px; padding: .2rem .25rem; font-size: .82rem; text-align: center; text-align-last: center;
    border-radius: 8px; border: 1px solid var(--app-border); background: var(--app-surface); color: var(--app-text); cursor: pointer;
}
.att-sel:focus { outline: 2px solid var(--app-primary); outline-offset: 1px; }
.att-chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-weight: 600; font-size: .8rem; border: 1px solid transparent; }
.att-present { background: rgba(22,163,74,.14); color: #15803d; border-color: rgba(22,163,74,.35); }
.att-absent { background: rgba(225,29,72,.12); color: #be123c; border-color: rgba(225,29,72,.35); }
.att-leave { background: rgba(245,158,11,.16); color: #b45309; border-color: rgba(245,158,11,.4); }
.att-none { color: var(--app-muted); }
[data-bs-theme="dark"] .att-present { color: #4ade80; }
[data-bs-theme="dark"] .att-absent { color: #fb7185; }
[data-bs-theme="dark"] .att-leave { color: #fbbf24; }

/* -------- score type --------------------------------------------------------- */
.score-cw { background: var(--app-primary-soft); color: var(--app-primary); font-weight: 500; }
.score-final { background: rgba(249,115,22,.15); color: #c2410c; font-weight: 500; }
/* "?" help next to a label (help_tip(), app.js helpTips) */
.help-tip { display: inline-flex; align-items: center; justify-content: center; width: 1.15rem; height: 1.15rem; margin-left: .2rem; padding: 0; border: 1px solid var(--app-border);
    border-radius: 50%; background: var(--app-surface); color: var(--bs-secondary-color); font-size: .72rem; font-weight: 700; line-height: 1; vertical-align: .1em; cursor: help; }
.help-tip:hover, .help-tip:focus-visible { color: var(--bs-primary); border-color: var(--bs-primary); }
.help-tooltip .tooltip-inner { max-width: 300px; text-align: left; }
.score-pre { background: rgba(100,116,139,.15); color: #475569; font-weight: 500; }
[data-bs-theme="dark"] .score-pre { color: #cbd5e1; }
.grades-table thead th.grp-pre { box-shadow: inset 0 -2px 0 #64748b; }
[data-bs-theme="dark"] .score-final { color: #fdba74; }
.grades-table thead th.grp-coursework { box-shadow: inset 0 -2px 0 var(--app-primary); }
.grades-table thead th.grp-final { box-shadow: inset 0 -2px 0 #f97316; }
.grades-table .subtotal { background: var(--app-surface-2); }
.grades-table .sticky-col.gb-no { left: 0; width: 44px; min-width: 44px; max-width: 44px; }
.grades-table .sticky-col.gb-student { left: 44px; box-shadow: 1px 0 0 var(--app-border); }

/* -------- grade cut ---------------------------------------------------------- */
.crit-table input { max-width: 110px; }
.grade-pill { display: inline-block; min-width: 2.4rem; text-align: center; padding: .15rem .45rem; border-radius: 8px; font-weight: 700; font-size: .85rem;
    background: var(--app-surface-2); border: 1px solid var(--app-border); color: var(--app-text); }
.grade-pill.g-A, .grade-pill.g-Bp { background: rgba(22,163,74,.14); border-color: rgba(22,163,74,.35); color: #15803d; }
.grade-pill.g-B, .grade-pill.g-Cp, .grade-pill.g-C { background: var(--app-primary-soft); border-color: rgba(var(--app-primary-rgb),.35); color: var(--app-primary); }
.grade-pill.g-Dp, .grade-pill.g-D { background: rgba(245,158,11,.16); border-color: rgba(245,158,11,.4); color: #b45309; }
.grade-pill.g-E { background: rgba(225,29,72,.12); border-color: rgba(225,29,72,.35); color: #be123c; }
[data-bs-theme="dark"] .grade-pill.g-A, [data-bs-theme="dark"] .grade-pill.g-Bp { color: #4ade80; }
[data-bs-theme="dark"] .grade-pill.g-Dp, [data-bs-theme="dark"] .grade-pill.g-D { color: #fbbf24; }
[data-bs-theme="dark"] .grade-pill.g-E { color: #fb7185; }
.gc-table td { white-space: nowrap; }
.gc-input { width: 160px; margin: 0 auto; }
.gc-input.overridden input, .gc-grade.overridden { border-color: var(--app-warning); background-color: rgba(245,158,11,.08); }
.gc-grade { width: 150px; }

.card.border-dashed { border-style: dashed; }

/* question number in the bottom-right corner of each bank card */
.q-card-body { position: relative; padding-bottom: 2rem !important; }
.q-no { position: absolute; right: .9rem; bottom: .55rem; font-size: .75rem; color: var(--app-muted); font-variant-numeric: tabular-nums;
    background: var(--app-surface-2); border: 1px solid var(--app-border); border-radius: 999px; padding: .05rem .55rem; }

/* -------- exam roll call ------------------------------------------------------ */
.start-conds li.ok { color: var(--app-success); }
.start-conds li.no { color: var(--app-muted); }
.table-success-soft > td { background: rgba(22,163,74,.06) !important; }
.exam-closed-overlay { position: fixed; inset: 0; z-index: 1080; display: flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--app-bg) 92%, transparent); backdrop-filter: blur(6px); }

.server-clock { font-size: .9rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--app-text); line-height: 1.2; }
.server-clock i { color: var(--app-muted); }

.score-box { background: var(--app-surface-2); }

/* exam console: one "screen" per student; the state colours the screen, the label says it in words */
.xc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.xc-card {
    --xc-bg: var(--bs-tertiary-bg); --xc-fg: var(--bs-body-color); --xc-dot: var(--bs-secondary-color);
    display: flex; flex-direction: column; gap: .4rem; padding: .6rem; min-width: 0;
    background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: .75rem;
}
.xc-open { cursor: pointer; }
.xc-open:hover { border-color: var(--app-primary); }
.xc-open:focus-visible { outline: 2px solid var(--app-primary); outline-offset: 2px; }
.xc-name { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.xc-screen { background: var(--xc-bg); color: var(--xc-fg); border-radius: .5rem; padding: .5rem .6rem; height: 7rem; overflow: hidden; }
.xc-state { font-size: .8rem; font-weight: 600; }
.xc-where { font-size: .75rem; margin-top: .15rem; opacity: .85; }
.xc-q { font-size: .8rem; margin-top: .25rem; overflow-wrap: anywhere; }
.xc-clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
.xc-big { font-size: 1.6rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.xc-bar { height: .3rem; }
.xc-foot { display: flex; flex-wrap: wrap; gap: .15rem .6rem; font-size: .75rem; color: var(--bs-secondary-color); font-variant-numeric: tabular-nums; }
.xc-ok { --xc-bg: rgba(22,163,74,.13); --xc-dot: #16a34a; }
.xc-warned { --xc-bg: rgba(245,158,11,.25); --xc-dot: #f59e0b; }
.xc-away { --xc-bg: #dc2626; --xc-fg: #fff; --xc-dot: #dc2626; }
.xc-device { --xc-bg: #c2410c; --xc-fg: #fff; --xc-dot: #ea580c; }
.xc-offline { --xc-bg: #4b5563; --xc-fg: #fff; --xc-dot: #6b7280; }
.xc-finished { --xc-bg: rgba(37,99,235,.15); --xc-dot: #2563eb; }
.xc-not_started { --xc-dot: var(--bs-secondary-color); }
.xc-card.xc-not_started { opacity: .6; }
.xc-card.xc-away { border-color: #dc2626; animation: xc-blink 1.2s ease-in-out infinite; }
@keyframes xc-blink { 50% { box-shadow: 0 0 0 3px rgba(220,38,38,.45); } }
@media (prefers-reduced-motion: reduce) { .xc-card.xc-away { animation: none; box-shadow: 0 0 0 3px rgba(220,38,38,.45); } }
.xc-chip { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--bs-border-color); background: var(--bs-body-bg); color: var(--bs-body-color); }
.xc-chip:hover { border-color: var(--app-primary); color: var(--bs-body-color); background: var(--bs-body-bg); }
.xc-chip.active, .xc-chip.active:hover { border-color: var(--app-primary); box-shadow: inset 0 0 0 1px var(--app-primary); background: var(--app-primary-soft); color: var(--bs-body-color); }
.xc-dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--xc-dot); }
/* consoles in full screen (App.fullscreenButton): only the console is left */
html.console-fs .topbar, html.console-fs .sidebar, html.console-fs .fs-hide, html.console-fs #classTabs, html.console-fs #banner { display: none !important; }
html.console-fs .main { margin-left: 0 !important; min-height: 100vh; padding: 1rem 1.25rem; }
html.console-fs body { background: var(--app-bg); }
.fs-only { display: none !important; }
html.console-fs .fs-only { display: inline !important; }
html.console-fs .xc-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
/* classroom console (classroom.js Console): same cards, its own statuses */
.lc-screen { height: auto; min-height: 5.5rem; }
.lc-learning { --xc-bg: rgba(22,163,74,.15); --xc-dot: #16a34a; }
.lc-in_class { --xc-bg: rgba(37,99,235,.13); --xc-dot: #2563eb; }
.lc-blur { --xc-bg: rgba(245,158,11,.28); --xc-dot: #f59e0b; }
.lc-hidden { --xc-bg: #c2410c; --xc-fg: #fff; --xc-dot: #ea580c; }
.lc-closed { --xc-bg: rgba(225,29,72,.14); --xc-dot: #e11d48; }
.lc-elsewhere { --xc-bg: rgba(139,92,246,.15); --xc-dot: #8b5cf6; }
.lc-offline { --xc-dot: var(--bs-secondary-color); }
.xc-card.lc-offline { opacity: .6; }
.xc-card.lc-learning { border-color: rgba(22,163,74,.55); }

/* group work chat (post page: student card, teacher modal) */
.chat-list { height: 360px; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .6rem; }
.modal .chat-list { height: min(60vh, 520px); }
.chat-msg { display: flex; gap: .5rem; align-items: flex-start; max-width: 92%; }
.chat-msg.mine { flex-direction: row-reverse; align-self: flex-end; }
.chat-bubble { background: var(--bs-tertiary-bg); border-radius: .75rem; padding: .4rem .65rem; min-width: 0; word-break: break-word; }
.chat-msg.mine .chat-bubble { background: var(--app-primary-soft); }
.chat-meta { font-size: .75rem; margin-bottom: .1rem; }
.chat-views { font-size: .72rem; color: var(--bs-secondary-color); margin-top: .2rem; }
.chat-bubble .attach { max-width: 280px; }
.chat-list .empty { margin: auto; }
[data-chat-form] textarea { resize: none; max-height: 120px; }
.group-report td, .group-report th { vertical-align: middle; }

/* class chat: floating button + panel (bottom right) */
.dm-fab { position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 1040;
    width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
.dm-fab .badge { position: absolute; top: -4px; right: -4px; font-size: .7rem; }
.dm-fab { touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; } /* dragged with mouse or finger (classroom.js) */
.dm-fab.dm-fab-drag { cursor: grabbing; transform: scale(1.08); box-shadow: 0 10px 24px rgba(0,0,0,.3) !important; }
.dm-fab.dm-fab-snap { transition: left .22s ease, top .22s ease; }
.dm-panel { position: fixed; right: 20px; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 1045;
    width: 380px; height: min(560px, calc(100vh - 120px)); display: flex; flex-direction: column; overflow: hidden; }
.dm-panel.d-none { display: none !important; }
.dm-panel.dm-teacher { width: 720px; max-width: calc(100vw - 40px); }
.dm-main { flex: 1; min-height: 0; display: flex; }
.dm-side { width: 240px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0; }
.dm-side.d-none { display: none !important; }
.dm-threads { flex: 1; overflow-y: auto; }
.dm-threads .list-group-item { border-left: 0; border-right: 0; }
.dm-threads .list-group-item.active .opacity-75 { opacity: .9 !important; }
.dm-when, .dm-last { font-size: .75rem; }
.dm-chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dm-head { min-height: 46px; }
.dm-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.dm-body .chat-list { flex: 1; height: auto; min-height: 0; }
@media (max-width: 575.98px) {
    .dm-fab { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
    .dm-panel, .dm-panel.dm-teacher { left: 16px; right: 16px; width: auto; max-width: none; bottom: calc(80px + env(safe-area-inset-bottom)); height: calc(100vh - 110px); }
    /* phones: the list, or the open conversation */
    .dm-panel.dm-teacher .dm-side { width: 100%; border-right: 0 !important; }
    .dm-panel.dm-teacher.dm-has-thread .dm-side { display: none !important; }
    .dm-panel.dm-teacher:not(.dm-has-thread) .dm-chat { display: none; }
}

/* lesson plan */
.plan-table td, .plan-table th { vertical-align: top; }
/* materials / work: long titles end with "…" inside the column instead of running over the next columns and the buttons */
.plan-table .pl-mats { min-width: 200px; max-width: 340px; }
.plan-table .pl-mats > .attach-list, .plan-table .pl-mats > a { max-width: 320px; }
.plan-table .pl-mats .attach-list.compact { grid-template-columns: minmax(0, 1fr); }
.plan-table .pl-mats .attach .min-w-0, .plan-table .pl-mats > a > .text-truncate { min-width: 0; }
.plan-table .pl-topic { overflow-wrap: anywhere; }
.plan-table .pl-topic .ws-pre, .plan-table .pl-note { overflow-wrap: anywhere; }
.plan-table .pl-note { min-width: 120px; }

/* phones: classwork rows and lesson-plan rows become cards */
@media (max-width: 767.98px) {
    .work-list.card { background: transparent; border: 0; box-shadow: none; }
    .work-list .work-item { flex-wrap: wrap; gap: .5rem .75rem; margin-bottom: .6rem; padding: .85rem;
        background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius); box-shadow: var(--app-shadow); }
    .work-list .work-item:last-child { border-bottom: 1px solid var(--app-border); margin-bottom: 0; }
    .work-list .work-item > a { flex: 1 1 0; }
    .work-list .work-meta { order: 3; flex: 1 0 100%; flex-wrap: wrap; gap: .4rem; }
    .work-list .work-stats { flex: 1 0 100%; justify-content: space-around; padding: .5rem 0; margin-bottom: .1rem;
        background: var(--app-surface-2); border-radius: calc(var(--radius) * .6); }
    .work-list .work-stats > div { flex: 1; min-width: 0; }

    .plan-table thead { display: none; }
    .plan-table, .plan-table tbody, .plan-table td { display: block; width: 100%; }
    .plan-table tbody { padding: .75rem; }
    .plan-table tr { display: grid; grid-template-columns: auto 1fr auto; gap: .35rem .75rem; align-items: start;
        padding: .85rem; margin-bottom: .75rem; border: 1px solid var(--app-border); border-radius: var(--radius); background: var(--app-surface); }
    .plan-table tr:last-child { margin-bottom: 0; }
    .plan-table td { padding: 0; border: 0; min-width: 0; max-width: none; background: transparent; box-shadow: none; }
    .plan-table .pl-no { grid-column: 1; text-align: left !important; white-space: nowrap; }
    .plan-table .pl-no::before { content: attr(data-label) " "; font-weight: 600; }
    .plan-table .pl-date { grid-column: 2; }
    .plan-table .pl-actions { grid-column: 3; grid-row: 1; }
    .plan-table .pl-topic, .plan-table .pl-mats, .plan-table .pl-post, .plan-table .pl-note { grid-column: 1 / -1; }
    .plan-table .pl-topic { font-weight: 500; }
    .plan-table .pl-mats::before, .plan-table .pl-post::before, .plan-table .pl-note::before {
        content: attr(data-label); display: block; font-size: .75rem; color: var(--app-muted); margin-top: .35rem; }
    .plan-table .pl-empty { display: none; }
}
.attach-list.compact { grid-template-columns: 1fr; gap: .35rem; }
.attach-list.compact .attach { padding: .3rem .5rem; gap: .45rem; font-size: .875rem; }

/* confirm dialog: messages may span lines */
#confirmText { white-space: pre-line; }

/* question import (PDF / text): almost the whole screen width, the preview needs the room */
@media (min-width: 992px) {
    .modal-import { --bs-modal-width: min(96vw, 1680px); }
}

/* math formulas (KaTeX): toolbar + live preview in the question editors */
.math-bar { position: sticky; top: -1rem; z-index: 3; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem;
    margin: 0 0 .4rem; padding: .35rem .4rem; background: var(--app-surface-2); border: 1px solid var(--app-border); border-radius: calc(var(--radius) * .6); }
.math-bar .btn { min-width: 2rem; padding: .1rem .45rem; font-size: .85rem; line-height: 1.5; }
.math-bar-title { font-size: .8rem; color: var(--app-muted); margin-right: .25rem; }
.math-help { flex: 1 0 100%; padding: .25rem .35rem 0; color: var(--app-muted); }
.math-preview { margin: .35rem 0 .5rem; padding: .45rem .65rem; border: 1px dashed var(--app-border); border-radius: calc(var(--radius) * .6);
    background: var(--app-surface); white-space: pre-wrap; overflow-x: auto; }
.math-preview-label { display: block; font-size: .72rem; color: var(--app-muted); margin-bottom: .1rem; }
.katex { font-size: 1.1em; }
.katex-display { margin: .4em 0; overflow-x: auto; overflow-y: hidden; }
.text-truncate .katex-display, .xc-clamp .katex-display { display: inline; margin: 0; }

/* "My menu" → use CLO off (users.use_clo = 0): CLO fields and CLO parts of the exam report are not shown */
.no-clo .clo-only { display: none !important; }

/* "เต็มจอ" of an embedded PDF / Drive / Docs / YouTube (app.js data-embed-fs): Fullscreen API, or .embed-max where it is missing (iPhone) */
.embed-box:fullscreen, .lv-stage:fullscreen { background: #000; padding: 0; max-width: none; }
.embed-box:fullscreen iframe, .lv-stage:fullscreen iframe { width: 100%; height: 100%; min-height: 0; border-radius: 0; aspect-ratio: auto; }
.embed-box:-webkit-full-screen, .lv-stage:-webkit-full-screen { background: #000; width: 100%; height: 100%; }
.embed-max { position: fixed !important; inset: 0; z-index: 2000; max-width: none !important; margin: 0 !important; background: #000; --bs-aspect-ratio: auto; }
.embed-max::before { display: none !important; }
.embed-max iframe { position: absolute; inset: 0; width: 100% !important; height: 100% !important; min-height: 0 !important; border-radius: 0 !important; aspect-ratio: auto !important; }
.embed-max-exit { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 10px; z-index: 1; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
html.embed-max-on, html.embed-max-on body { overflow: hidden; }

/* content viewer: one item at a time (classroom.js viewerShow), the PDF / video gets the whole height of the body */
.viewer-wrap.vm-media { max-width: 1400px; height: 100%; display: flex; flex-direction: column; padding-bottom: 0; }
.vm-media > .vm-item:not(.d-none) { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.vm-item .embed-box { position: relative; flex: 1; min-height: 320px; }
.vm-item .embed-box iframe { position: absolute; inset: 0; width: 100%; height: 100%; }
.vm-picker { border-top: 1px solid var(--app-border); background: var(--app-surface); padding: .5rem .75rem; }
.vm-picker-list { display: flex; gap: .5rem; overflow-x: auto; max-width: 1400px; margin: 0 auto; scrollbar-width: thin; }
.vm-pick { display: inline-flex; align-items: center; gap: .4rem; flex: 0 0 auto; max-width: 16rem; padding: .4rem .8rem; border-radius: 999px;
  border: 1px solid var(--app-border); background: var(--app-surface); color: var(--app-text); font-size: .875rem; }
.vm-pick:hover { border-color: var(--app-primary); }
.vm-pick.active { background: var(--app-primary); border-color: var(--app-primary); color: #fff; }

/* content viewer title bar: name of the item on screen + full screen; on phones the name is left to the picker bar */
.vm-item-bar { max-width: 40%; }
@media (max-width: 767.98px) { #viewModal #vmFs [data-embed-fs] { font-size: 0; padding: .2rem .5rem; } #viewModal #vmFs [data-embed-fs] i { font-size: .95rem; margin: 0 !important; } }
/* content viewer: a slim title bar (more room for the PDF / video) */
#viewModal .modal-header { padding: .3rem .75rem; gap: .6rem !important; min-height: 0; }
#viewModal #vmIcon { width: 28px; height: 28px; font-size: .85rem; }
#viewModal .modal-title { font-size: 1rem; line-height: 1.3; }
#viewModal .modal-header .btn { padding: .2rem .6rem; font-size: .875rem; }

/* content viewer: picker + views + buttons in one bottom row (picker scrolls sideways) */
#viewModal .vm-footer { flex-wrap: nowrap; justify-content: flex-start; gap: .75rem; padding: .4rem .75rem; }
#viewModal .vm-footer > * { margin: 0; }
#viewModal .vm-footer .vm-picker { flex: 1 1 auto; min-width: 0; border: 0; background: none; padding: 0; }
#viewModal .vm-footer .vm-picker-list { margin: 0; max-width: none; padding: 2px 0; }
#viewModal .vm-footer .btn { padding: .3rem .7rem; font-size: .875rem; }
@media (max-width: 767.98px) {
  #viewModal .vm-footer .vm-picker:not(.d-none) ~ .vm-count { display: none; }  /* phones: room for the picker */
  #viewModal .vm-footer .vm-picker:not(.d-none) ~ div .btn span { display: none; }
  #viewModal .vm-footer .vm-picker:not(.d-none) ~ div .btn i { margin: 0 !important; }
}

/* the confirm dialog is always above any other dialog it is asked from (comments, link viewer…) */
#confirmModal { z-index: 1080; }
.modal-backdrop.confirm-backdrop { z-index: 1075; }
