/* ==========================================================================
   ThaiStar Academy — Unified Design System (Web, Telegram Mini App & Admin)
   Palette anchored on ThaiStar teal (#4da4ab), warm gold (#b39359), and ink.
   Strict 3-step body type scale + tabular-nums for timers and metrics.
   ========================================================================== */

:root {
    --bg: #f5f6f3;
    --surface: #ffffff;
    --surface-subtle: #f0f2ee;
    --surface-dark: #15181a;
    --ink: #171a1c;
    --ink-muted: #525d63;
    --border: #dfe4de;
    --border-strong: #c8d0c7;

    --accent: #b39359;
    --accent-hover: #977941;
    --accent-soft: #f6f1e6;
    --teal: #34868d;
    --teal-soft: #e8f4f5;

    --ok: #1d7a46;
    --ok-soft: #e8f6ee;
    --warn: #b26308;
    --warn-soft: #fef3e2;
    --danger: #b92b27;
    --danger-soft: #fdecea;

    --font-sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    --text-display: clamp(1.5rem, 2.8vw, 2rem);
    --text-heading: 1.125rem;
    --text-body: 0.9375rem;
    --text-sm: 0.8125rem;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(21, 24, 26, 0.06);
    --shadow-md: 0 8px 24px rgba(21, 24, 26, 0.08);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);

    /* CSS-Driven Icon Design Tokens (modern-web-guidance: icons) */
    --icon-style-size: 1.125em;
    --icon-style-spacing: 0.45em;
    --icon-settings: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9c.26.6.85 1 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1Z'/%3E%3C/svg%3E");
    --icon-edit: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5Z'/%3E%3C/svg%3E");
    --icon-trash: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6'/%3E%3Cpath d='M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E");
    --icon-copy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2' ry='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E");
    --icon-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    --icon-back: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='19' y1='12' x2='5' y2='12'/%3E%3Cpolyline points='12 19 5 12 12 5'/%3E%3C/svg%3E");
    --icon-send: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='22' y1='2' x2='11' y2='13'/%3E%3Cpolygon points='22 2 15 22 11 13 2 9 22 2'/%3E%3C/svg%3E");
    --icon-plus: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='12' y1='5' x2='12' y2='19'/%3E%3Cline x1='5' y1='12' x2='19' y2='12'/%3E%3C/svg%3E");
}

@property --icon-start {
    syntax: "*";
    inherits: false;
}

@property --icon-end {
    syntax: "*";
    inherits: false;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-body);
    line-height: 1.55;
    color: var(--ink);
    background-color: var(--bg);
    min-height: 100dvh;
    font-variant-numeric: tabular-nums;
}

body.tma-mode {
    background-color: var(--tg-theme-secondary-bg-color, var(--bg));
}

h1, h2, h3, p, ul, ol {
    margin: 0;
}

h1 {
    font-size: var(--text-display);
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

h2 {
    font-size: var(--text-heading);
    font-weight: 700;
    letter-spacing: -0.015em;
    line-height: 1.3;
}

h3 {
    font-size: var(--text-body);
    font-weight: 700;
    line-height: 1.35;
}

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

a:hover {
    text-decoration: underline;
}

.visually-hidden:where(:not(:focus-within, :active)) {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
}

/* Top Navigation Shell */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--surface-dark);
    color: #ffffff;
    border-bottom: 2px solid var(--accent);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar-inner--narrow {
    max-width: 820px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
    text-decoration: none;
    min-width: 0;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
}

.brand-title {
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.brand-sub {
    font-size: var(--text-sm);
    color: rgba(255, 255, 255, 0.72);
    font-weight: 500;
}

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

.topbar-user {
    font-size: var(--text-sm);
    color: rgba(255, 255, 255, 0.85);
    text-align: right;
    line-height: 1.25;
}

.topbar-user strong {
    display: block;
    color: #ffffff;
    font-weight: 600;
}

/* Containers */
.shell {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

.shell--narrow {
    max-width: 780px;
}

.surface {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.surface + .surface,
.section + .section {
    margin-top: 20px;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.section-desc {
    color: var(--ink-muted);
    margin-top: 4px;
    max-width: 65ch;
}

.divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: var(--text-body);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 180ms var(--ease), border-color 180ms var(--ease), color 180ms var(--ease), transform 140ms var(--ease);
}

.btn:hover {
    text-decoration: none;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.52;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-dark {
    background: var(--surface-dark);
    color: #ffffff;
}

.btn-dark:hover:not(:disabled) {
    background: #282d31;
}

.btn-secondary {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-subtle);
}

.btn-ghost {
    background: transparent;
    color: var(--ink-muted);
    border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface-subtle);
    color: var(--ink);
}

.btn-ghost-dark {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    min-height: 36px;
    padding: 6px 12px;
    font-size: var(--text-sm);
}

.btn-ghost-dark:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.22);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: #f3c4c2;
}

.btn-danger:hover:not(:disabled) {
    background: #f9d8d5;
}

.btn-sm {
    min-height: 34px;
    padding: 6px 12px;
    font-size: var(--text-sm);
}

.btn-lg {
    min-height: 50px;
    padding: 13px 24px;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* Forms & Validation (modern-web-guidance: validate-input-after-interaction) */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.field label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink);
}

.field-hint {
    display: block;
    font-size: var(--text-sm);
    color: var(--ink-muted);
}

.input,
.select,
.textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    font-family: inherit;
    font-size: var(--text-body);
    color: var(--ink);
    background: var(--surface);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}

.textarea {
    min-height: 88px;
    resize: vertical;
    line-height: 1.5;
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(52, 134, 141, 0.14);
}

:is(.input, .select, .textarea):is(:user-invalid, .user-invalid-fallback) {
    border-color: var(--danger);
    background-color: #fff8f8;
}

.error-msg {
    display: none;
    font-size: var(--text-sm);
    color: var(--danger);
    font-weight: 500;
}

:is(.input, .select, .textarea):is(:user-invalid, .user-invalid-fallback) + .error-msg {
    display: block;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Inline Callouts & Alerts */
.callout {
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface-subtle);
}

.callout--warn {
    background: var(--warn-soft);
    border-color: #f3d2a2;
    color: #5d3605;
}

.callout--danger {
    background: var(--danger-soft);
    border-color: #f4c2c0;
    color: #6b1614;
}

.callout--ok {
    background: var(--ok-soft);
    border-color: #b7e2c8;
    color: #114c2b;
}

.callout--teal {
    background: var(--teal-soft);
    border-color: #b8dce0;
    color: #16474c;
}

/* Semantic Status Cells (Tables & Results) */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 6px;
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
}

.status-ok {
    background: var(--ok-soft);
    color: var(--ok);
}

.status-fail {
    background: var(--danger-soft);
    color: var(--danger);
}

.status-warn {
    background: var(--warn-soft);
    color: var(--warn);
}

.status-neutral {
    background: var(--surface-subtle);
    color: var(--ink-muted);
}

.delta-up {
    color: var(--ok);
    font-weight: 700;
}

.delta-down {
    color: var(--danger);
    font-weight: 700;
}

.delta-flat {
    color: var(--ink-muted);
    font-weight: 600;
}

/* Metrics Row */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
}

.metric-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
}

.metric-label {
    font-size: var(--text-sm);
    color: var(--ink-muted);
}

.metric-value {
    font-size: 1.625rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-top: 4px;
    line-height: 1.2;
}

.metric-sub {
    font-size: var(--text-sm);
    color: var(--ink-muted);
    margin-top: 4px;
}

/* Tabs (modern-web-guidance: tabs) */
.tablist {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    scrollbar-width: none;
    scroll-snap-type: inline proximity;
}

.tablist::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    position: relative;
    flex: none;
    scroll-snap-align: start;
    background: transparent;
    border: 0;
    padding: 12px 16px;
    font-family: inherit;
    font-size: var(--text-body);
    font-weight: 600;
    color: var(--ink-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color 160ms var(--ease);
}

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

.tab-btn[aria-selected="true"] {
    color: var(--ink);
}

.tab-btn[aria-selected="true"]::after {
    content: "";
    position: absolute;
    inset: auto 8px 0;
    border-block-end: 3px solid var(--accent);
}

.panel-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Responsive Data Tables (modern-web-guidance: responsive-table) */
.table-wrapper {
    overflow: auto;
    max-inline-size: 100%;
    max-block-size: min(560px, 72vh);
    container-type: inline-size;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}

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

.data-table thead {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
}

.data-table thead th {
    background: var(--surface-subtle);
    color: var(--ink-muted);
    font-weight: 600;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table tbody th,
.data-table tbody td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table tbody tr:last-child th,
.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.data-table tbody th {
    position: sticky;
    inset-inline-start: 0;
    background: var(--surface);
    font-weight: 600;
    color: var(--ink);
}

.data-table tbody tr:hover td,
.data-table tbody tr:hover th {
    background: #fafbf9;
}

@container (width < 620px) {
    .data-table--stack,
    .data-table--stack thead,
    .data-table--stack tbody,
    .data-table--stack tr,
    .data-table--stack th,
    .data-table--stack td {
        display: block;
    }

    .data-table--stack thead {
        display: none;
    }

    .data-table--stack tr {
        border-bottom: 2px solid var(--border);
        padding: 8px 0;
    }

    .data-table--stack tbody th {
        position: sticky;
        inset-block-start: 0;
        z-index: 2;
        background: var(--surface-subtle);
        border-bottom: 1px solid var(--border);
    }

    .data-table--stack tbody td {
        border-bottom: 0;
        padding: 6px 14px;
        display: flex;
        justify-content: space-between;
        gap: 12px;
    }

    .data-table--stack tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--ink-muted);
        flex-shrink: 0;
    }
}

/* Native Modal Dialogs (modern-web-guidance: dialog) */
dialog {
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 24px 64px rgba(21, 24, 26, 0.24);
    width: min(680px, calc(100vw - 24px));
    max-height: calc(100dvh - 32px);
}

dialog[open] {
    display: flex;
    flex-direction: column;
}

dialog:modal {
    overscroll-behavior: contain;
}

dialog::backdrop {
    background: rgba(21, 24, 26, 0.56);
    overflow: hidden;
    overscroll-behavior: contain;
}

.dialog-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dialog-header h1 {
    font-size: var(--text-heading);
}

.dialog-body {
    padding: 20px 22px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.dialog-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

/* Persistent Toast Notifications (modern-web-guidance: persistent-toast-notifications) */
.toast-region {
    position: fixed;
    inset-block-end: 20px;
    inset-inline-end: 20px;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(400px, calc(100vw - 32px));
    pointer-events: none;
}

.toast-item {
    pointer-events: auto;
    position: static;
    margin: 0;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background: var(--surface-dark);
    color: #ffffff;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    font-size: var(--text-sm);
    opacity: 1;
    transition: opacity 180ms var(--ease), transform 180ms var(--ease);
    transition-behavior: allow-discrete;
}

.toast-item--ok {
    background: #144d2e;
    border-color: #217347;
}

.toast-item--error {
    background: #7c1c19;
    border-color: #b92b27;
}

.toast-close {
    background: transparent;
    border: 0;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 1rem;
    line-height: 1;
}

.toast-close:hover {
    color: #ffffff;
}

/* Test Stage & Countdown Timer */
.test-progress-bar {
    height: 6px;
    width: 100%;
    background: var(--surface-subtle);
    border-radius: 999px;
    overflow: hidden;
}

.test-progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 220ms var(--ease);
}

.timer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.timer-readout {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ink);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-subtle);
    border: 1.5px solid var(--border);
}

.timer-readout--warn {
    background: var(--warn-soft);
    border-color: #e6a23c;
    color: var(--warn);
}

.timer-readout--danger {
    background: var(--danger-soft);
    border-color: var(--danger);
    color: var(--danger);
}

.timer-bar-track {
    height: 8px;
    width: 100%;
    background: var(--surface-subtle);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 20px;
}

.timer-bar-fill {
    height: 100%;
    background: var(--teal);
    transition: width 250ms linear, background-color 180ms var(--ease);
}

.timer-bar-fill--warn {
    background: var(--warn);
}

.timer-bar-fill--danger {
    background: var(--danger);
}

.question-text {
    font-size: 1.1875rem;
    font-weight: 700;
    line-height: 1.4;
    margin: 10px 0 20px;
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option-btn {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    text-align: left;
    padding: 14px 16px;
    background: var(--surface);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--text-body);
    line-height: 1.45;
    color: var(--ink);
    cursor: pointer;
    transition: border-color 160ms var(--ease), background-color 160ms var(--ease), transform 120ms var(--ease);
}

.option-btn:hover:not(:disabled) {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.option-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.option-btn:disabled {
    cursor: default;
    opacity: 0.72;
}

.option-key {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: var(--surface-subtle);
    color: var(--ink-muted);
    font-size: var(--text-sm);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.option-btn:hover:not(:disabled) .option-key {
    background: var(--accent);
    color: #ffffff;
}

/* Pre-start Briefing List */
.rules-checklist {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rules-checklist li {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-subtle);
}

.rules-bullet {
    color: var(--accent);
    font-weight: 700;
    flex-shrink: 0;
}

/* Topic Accordion List */
.topic-row {
    border-top: 1px solid var(--border);
    padding: 14px 0;
}

.topic-row:first-child {
    border-top: 0;
    padding-top: 0;
}

.topic-row summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topic-row summary::-webkit-details-marker {
    display: none;
}

.topic-meta {
    font-size: var(--text-sm);
    color: var(--ink-muted);
    margin-top: 2px;
}

.lesson-box {
    margin-top: 12px;
    padding: 14px 16px;
    background: var(--surface-subtle);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lesson-box p {
    max-width: 65ch;
}

/* Charts (Clean SVG containers) */
.chart-box {
    width: 100%;
    overflow-x: auto;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 10px;
    font-size: var(--text-sm);
    color: var(--ink-muted);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

/* Utility Helpers */
.row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.stack-sm {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stack-md {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.stack-lg {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

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

.copy-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: var(--text-sm);
    word-break: break-all;
}

.copy-box code {
    flex: 1;
    font-family: inherit;
}

.code-block {
    background: var(--surface-dark);
    color: #e4ebe6;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.portal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.portal-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 14px;
}

.portal-item--teal {
    border-top-color: var(--teal);
}

.empty-state {
    text-align: center;
    padding: 36px 16px;
    color: var(--ink-muted);
}

[hidden] {
    display: none !important;
}

@media (max-width: 640px) {
    .shell {
        padding: 16px 12px 48px;
    }

    .surface {
        padding: 18px 16px;
    }

    .topbar-inner {
        padding: 10px 14px;
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .brand-sub {
        display: none;
    }

    .topbar-user {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   CSS-Driven Icon Engine + Fallbacks & Safari Workarounds
   (modern-web-guidance: icons)
   ========================================================================== */
.icon:empty {
    --icon-start: var(--icon);
}

/* Class-hook fallback for browsers without Container Style Queries */
:where(.icon-start, .icon:empty)::before {
    content: "";
    content: "" / var(--icon-style-alt, "");
    display: inline-block;
    width: var(--icon-style-size, 1.125em);
    height: var(--icon-style-size, 1.125em);
    background-color: var(--icon-style-color, currentColor);
    mask: var(--icon-start) no-repeat center / contain;
    -webkit-mask: var(--icon-start) no-repeat center / contain;
    vertical-align: calc(0.5cap - var(--icon-style-size, 1.125em) / 2 + var(--icon-style-voffset, -0.02em));
    flex: none;
    pointer-events: none;
    forced-color-adjust: none;
}

:where(.icon-start)::before {
    --icon-start: inherit;
}

:where(.icon:empty)::before {
    --icon-start: var(--icon);
}

:where(.icon-start:not(.icon, :empty))::before {
    margin-inline-end: var(--icon-style-spacing, 0.45em);
}

/* Primary Container Style Query rules */
@container style(--icon-start) {
    ::before {
        --icon-start: inherit;
        content: "" / var(--icon-style-alt, "");
        display: inline-block;
        width: var(--icon-style-size, 1.125em);
        height: var(--icon-style-size, 1.125em);
        background-color: var(--icon-style-color, currentColor);
        mask: var(--icon-start) no-repeat center / contain;
        -webkit-mask: var(--icon-start) no-repeat center / contain;
        vertical-align: calc(0.5cap - var(--icon-style-size, 1.125em) / 2 + var(--icon-style-voffset, -0.02em));
        flex: none;
        pointer-events: none;
        forced-color-adjust: none;
    }

    :where(:not(.icon, :empty))::before {
        margin-inline-end: var(--icon-style-spacing, 0.45em);
    }
}

@container style(--icon-end) {
    ::after {
        --icon-end: inherit;
        content: "" / var(--icon-style-alt, "");
        display: inline-block;
        width: var(--icon-style-size, 1.125em);
        height: var(--icon-style-size, 1.125em);
        background-color: var(--icon-style-color, currentColor);
        mask: var(--icon-end) no-repeat center / contain;
        -webkit-mask: var(--icon-end) no-repeat center / contain;
        vertical-align: calc(0.5cap - var(--icon-style-size, 1.125em) / 2 + var(--icon-style-voffset, -0.02em));
        flex: none;
        pointer-events: none;
        forced-color-adjust: none;
    }

    :where(:not(.icon, :empty))::after {
        margin-inline-start: var(--icon-style-spacing, 0.45em);
    }
}

/* Safari WebKit #301609 & #325900 workarounds */
@keyframes webkit-301609 {}

@supports ((-webkit-nbsp-mode: normal) or (-webkit-touch-callout: none) or (font: -apple-system-body)) and (content-visibility: auto) {
    @layer webkit-301609-fix {
        ::before,
        ::after {
            animation: webkit-301609 0s;
        }
    }

    @property --icon-start {
        syntax: "*";
        inherits: true;
    }

    @layer webkit-325900-fix {
        @container style(--icon-start) {
            * {
                --icon-start: initial;
            }
        }
    }
}

/* Reusable icon semantic helpers */
.icon-settings {
    --icon: var(--icon-settings);
}

.icon-edit {
    --icon: var(--icon-edit);
}

.icon-trash {
    --icon: var(--icon-trash);
}

.icon-copy {
    --icon: var(--icon-copy);
}

.icon-back {
    --icon-start: var(--icon-back);
}

.icon-send {
    --icon-start: var(--icon-send);
}

/* Icon-only action buttons (minimum 34x34px target, crisp focus) */
.btn-icon {
    min-inline-size: 36px;
    min-block-size: 36px;
    padding: 6px;
    gap: 0;
    --icon-style-size: 18px;
}

.btn-sm.btn-icon {
    min-inline-size: 34px;
    min-block-size: 34px;
    padding: 6px;
    --icon-style-size: 16px;
}

.btn-icon:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

.btn-ghost-dark.btn-icon:focus-visible {
    outline-color: #ffffff;
}

.btn-icon-active {
    background: rgba(179, 147, 89, 0.28);
    border-color: var(--accent);
    color: #ffffff;
}

.btn-danger-ghost {
    background: transparent;
    color: var(--danger);
    border-color: transparent;
}

.btn-danger-ghost:hover:not(:disabled) {
    background: var(--danger-soft);
}

/* Accessible Switch Controls (modern-web-guidance: switch) */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    cursor: pointer;
}

.switch-row__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.switch-row__title {
    font-weight: 600;
    color: var(--ink);
}

.switch-row__desc {
    font-size: var(--text-sm);
    color: var(--ink-muted);
}

input[type="checkbox"][switch] {
    accent-color: var(--teal);
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

input[type="checkbox"][switch]:focus-visible {
    outline: 3px solid var(--teal);
    outline-offset: 4px;
}

/* Feature-detected fallback for browsers without native HTML switch */
input[type="checkbox"][switch].switch-fallback {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    inline-size: 46px;
    block-size: 26px;
    border-radius: 999px;
    background: var(--border-strong);
    border: 1px solid rgba(21, 24, 26, 0.14);
    transition: background-color 180ms var(--ease), border-color 180ms var(--ease);
}

input[type="checkbox"][switch].switch-fallback::after {
    content: "";
    position: absolute;
    inset-block-start: 2px;
    inset-inline-start: 2px;
    inline-size: 20px;
    block-size: 20px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(21, 24, 26, 0.28);
    transition: transform 180ms var(--ease);
}

input[type="checkbox"][switch].switch-fallback:checked {
    background: var(--teal);
    border-color: var(--teal);
}

input[type="checkbox"][switch].switch-fallback:checked::after {
    transform: translateX(20px);
}

/* Copy Button with Live Status Bubble (modern-web-guidance: copy-button) */
.copy-control {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.copy-button {
    min-inline-size: 34px;
    min-block-size: 34px;
    --icon: var(--icon-copy);
}

.copy-button[data-copied] {
    --icon: var(--icon-check);
    color: var(--ok);
    border-color: #b7e2c8;
    background: var(--ok-soft);
}

.copy-button[data-failed] {
    color: var(--danger);
    border-color: #f4c2c0;
    background: var(--danger-soft);
}

.copy-tip {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ok);
    opacity: 0;
    transition: opacity 160ms var(--ease);
    white-space: nowrap;
}

.copy-button[data-copied] + .copy-tip {
    opacity: 1;
}

.copy-button[data-failed] + .copy-tip {
    opacity: 1;
    color: var(--danger);
}

/* Mango Settings: Salon Chat ID Cards */
.salon-chats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.salon-chat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.salon-chat-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-id-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.chat-id-row .chat-id-input {
    flex: 1.1;
    min-width: 120px;
}

.chat-id-row .chat-label-input {
    flex: 1;
    min-width: 100px;
}

.action-icons {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}
