:root {
    --color-primary: #16232E;
    --color-primary-dark: #0B141B;
    --color-accent: #C8A848;
    --color-accent-text: #8A6D1F;
    --color-route: #3E7C7B;
    --color-background-light: #F4F7F9;
    --color-text-dark: #333;
    --font-header: 'Space Grotesk', sans-serif;
    --font-body: 'Roboto', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --shadow-md: 0 1px 2px rgba(11,20,27,0.04), 0 8px 24px rgba(11,20,27,0.08);

    /* Semantic tokens that dark mode overrides. --color-primary and
       --color-primary-dark deliberately stay FIXED across themes below —
       they're used as literal brand-navy backgrounds (.app-header) and as
       text-on-gold-button color (needs to stay dark for contrast against
       --color-accent regardless of page theme), not as general "foreground
       text". --text-heading is the one that actually flips to light text
       in dark mode, used everywhere headings/titles reference "primary"
       as a foreground color rather than a background. */
    --text-heading: var(--color-primary);
    --surface-page: var(--color-background-light);
    --surface-card: #ffffff;
    --surface-subtle: var(--color-background-light);
    --text-muted: #667;
    --text-muted-2: #778;
    --text-muted-3: #889;
    --border-color: #e3e8ee;
    --border-color-2: #dde3ea;
    --border-color-3: #e9edf2;

    /* Status color pairs shared by badges, banners, and alert boxes —
       defining these once means dark mode only needs one override block
       instead of touching ~20 individual badge/alert rules by hand. */
    --status-blue-bg: #eaf1fb;   --status-blue-text: #1a5fb4;
    --status-orange-bg: #fff3e0; --status-orange-text: #b06a00; --status-orange-border: #f0d9a8;
    --status-green-bg: #eaf7ee;  --status-green-text: #1f7a3c;  --status-green-border: #bfe6cb;
    --status-red-bg: #fdecec;    --status-red-text: #a5271f;    --status-red-border: #f3c6c3;
    --status-gray-bg: #eee;      --status-gray-text: var(--text-muted);
}

[data-theme="dark"] {
    --color-accent-text: #E4C87A;
    --color-route: #5FA8A6;
    --color-background-light: #0F1620;
    --color-text-dark: #DCE3EA;

    --text-heading: #E8EDF2;
    --surface-page: #0B1017;
    --surface-card: #161E29;
    --surface-subtle: #1C2530;
    --text-muted: #9AA7B5;
    --text-muted-2: #8A97A5;
    --text-muted-3: #7A8794;
    --border-color: #2A3644;
    --border-color-2: #313E4D;
    --border-color-3: #2A3644;

    --status-blue-bg: #1B2A42;   --status-blue-text: #7FB3FF;
    --status-orange-bg: #3A2A12; --status-orange-text: #F0B058; --status-orange-border: #5C4420;
    --status-green-bg: #14301F;  --status-green-text: #6FCF97;  --status-green-border: #245538;
    --status-red-bg: #3A1616;    --status-red-text: #FF8A8A;    --status-red-border: #5C2828;
    --status-gray-bg: #232D38;   --status-gray-text: var(--text-muted);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

input, select, textarea {
    background: var(--surface-card);
    color: var(--color-text-dark);
    font-family: inherit;
}

body {
    font-family: var(--font-body);
    color: var(--color-text-dark);
    background: var(--surface-page);
    line-height: 1.6;
}

.container { width: 92%; max-width: 900px; margin: 0 auto; padding: 30px 0 80px; }

h1, h2 { font-family: var(--font-header); color: var(--text-heading); margin-bottom: 8px; }
h1 { font-size: 1.8em; }
h2 { font-size: 1.3em; margin-bottom: 20px; }

.muted { color: var(--text-muted); margin-bottom: 20px; }
.muted.small { font-size: 0.85em; margin-top: 20px; margin-bottom: 0; }

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-accent-text);
}
.eyebrow::before { content: ""; width: 6px; height: 6px; background: var(--color-accent); }

/* Header */
.app-header {
    background: var(--color-primary);
    color: white;
    padding: 16px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.app-header__brand { display: flex; flex-direction: column; gap: 2px; width: 92%; max-width: 900px; margin: 0 auto; }
.app-header__title { font-family: var(--font-header); font-weight: 700; font-size: 1.1em; }
.app-header .eyebrow { color: #E9D9A8; }
.app-header .eyebrow::before { background: #E9D9A8; }
.app-header__right {
    width: 92%; max-width: 900px; margin: 0 auto;
    display: flex; align-items: center; justify-content: flex-end; gap: 14px;
}
.app-header__user {
    display: flex; align-items: center; gap: 14px;
    font-size: 0.9em;
}
.theme-toggle {
    background: none; border: 1px solid rgba(255,255,255,0.3); border-radius: 6px;
    width: 34px; height: 34px; font-size: 1.1em; cursor: pointer; color: white;
    display: flex; align-items: center; justify-content: center;
    transition: background-color 0.15s;
}
.theme-toggle:hover { background: rgba(255,255,255,0.12); }

.notif-wrap { position: relative; }
.notif-badge {
    position: absolute; top: -4px; right: -4px;
    background: var(--status-red-text); color: white;
    font-size: 0.65em; font-weight: 700; line-height: 1;
    min-width: 16px; height: 16px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.notif-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0; width: 340px; max-height: 420px;
    background: var(--surface-card); border: 1px solid var(--border-color); border-radius: 8px;
    box-shadow: var(--shadow-md); overflow: hidden; z-index: 50; display: flex; flex-direction: column;
}
.notif-dropdown__header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 14px; border-bottom: 1px solid var(--border-color);
    font-weight: 600; color: var(--text-heading); font-size: 0.9em;
}
.notif-list { overflow-y: auto; max-height: 360px; }
.notif-item {
    display: block; width: 100%; text-align: left; border: none; background: none;
    padding: 10px 14px; border-bottom: 1px solid var(--border-color); cursor: pointer;
    color: var(--color-text-dark); font-family: inherit;
}
.notif-item:hover { background: var(--surface-subtle); }
.notif-item.is-unread { background: var(--status-blue-bg); }
.notif-item__title { font-weight: 600; font-size: 0.88em; margin-bottom: 2px; }
.notif-item__body { font-size: 0.82em; color: var(--text-muted); }
.notif-item__time { font-size: 0.75em; color: var(--text-muted-3); margin-top: 4px; }

/* Cards */
.card {
    background: var(--surface-card);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    padding: 30px;
    margin-bottom: 20px;
}
.card--narrow { max-width: 420px; margin: 60px auto; }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; color: var(--text-heading); margin-bottom: 6px; font-size: 0.9em; }
.field input, .field select, .field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color-2);
    background: var(--surface-card);
    color: var(--color-text-dark);
    border-radius: 6px;
    font-family: var(--font-body);
    font-size: 1em;
}
.field textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }

.form-error {
    background: var(--status-red-bg); color: var(--status-red-text); border: 1px solid var(--status-red-border);
    padding: 10px 14px; border-radius: 6px; font-size: 0.9em; margin-bottom: 14px;
}
.form-success {
    background: var(--status-green-bg); color: var(--status-green-text); border: 1px solid var(--status-green-border);
    padding: 10px 14px; border-radius: 6px; font-size: 0.9em; margin-bottom: 14px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 11px 22px;
    font-family: var(--font-header);
    font-weight: 600;
    font-size: 0.85em;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background-color 0.2s, color 0.2s;
    border: 2px solid transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--color-accent); color: var(--color-primary); border-color: var(--color-accent); }
.btn-primary:hover { background: #B49641; border-color: #B49641; }
.btn-outline { background: transparent; color: white; border-color: rgba(255,255,255,0.5); }
.btn-outline:hover { background: rgba(255,255,255,0.12); }
.btn-small { padding: 6px 12px; font-size: 0.75em; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--border-color); }
.tab {
    background: none; border: none; cursor: pointer;
    padding: 12px 18px; font-family: var(--font-header); font-weight: 600; font-size: 0.9em;
    color: var(--text-muted-2); border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tab.active { color: var(--text-heading); border-bottom-color: var(--color-accent); }

/* Ticket list */
.ticket-list { display: flex; flex-direction: column; gap: 14px; }
.ticket-item {
    border: 1px solid var(--border-color); border-radius: 8px; padding: 16px 18px;
    display: flex; flex-direction: column; gap: 8px;
}
.ticket-item__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ticket-item__title { font-weight: 700; color: var(--text-heading); }
.ticket-item__meta { font-size: 0.82em; color: var(--text-muted-2); display: flex; gap: 10px; flex-wrap: wrap; }
.ticket-item__desc { font-size: 0.92em; color: var(--text-muted); white-space: pre-wrap; }
.ticket-item__controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.ticket-item__controls select { padding: 6px 8px; border-radius: 5px; border: 1px solid var(--border-color-2); font-size: 0.85em; }

.badge {
    display: inline-block; padding: 3px 9px; border-radius: 20px;
    font-size: 0.72em; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
}
.badge--open { background: var(--status-blue-bg); color: var(--status-blue-text); }
.badge--in_progress { background: var(--status-orange-bg); color: var(--status-orange-text); }
.badge--resolved { background: var(--status-green-bg); color: var(--status-green-text); }
.badge--closed { background: var(--status-gray-bg); color: var(--status-gray-text); }
.badge--low { background: var(--status-gray-bg); color: var(--status-gray-text); }
.badge--normal { background: var(--status-blue-bg); color: var(--status-blue-text); }
.badge--high { background: var(--status-orange-bg); color: var(--status-orange-text); }
.badge--urgent { background: var(--status-red-bg); color: var(--status-red-text); }

.empty-state { color: var(--text-muted-3); font-size: 0.9em; padding: 20px 0; text-align: center; }

/* ---------------- Training modules ---------------- */
.training-list { display: flex; flex-direction: column; gap: 20px; }
.training-module { background: var(--surface-card); border-radius: 10px; box-shadow: var(--shadow-md); padding: 26px 28px; }
.training-module__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.training-module__title { font-family: var(--font-header); font-weight: 700; color: var(--text-heading); font-size: 1.15em; }
.training-module__desc { color: var(--text-muted); margin-bottom: 16px; }
.audience-tag {
    font-family: var(--font-mono); font-size: 0.7em; letter-spacing: 0.06em; text-transform: uppercase;
    padding: 3px 8px; border-radius: 4px; background: var(--color-background-light); color: var(--color-accent-text);
    white-space: nowrap;
}

.video-embed { position: relative; width: 100%; padding-top: 56.25%; margin-bottom: 16px; border-radius: 8px; overflow: hidden; background: #000; }
.video-embed iframe, .video-embed video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-link { display: inline-block; margin-bottom: 16px; color: var(--color-accent-text); font-weight: 600; }

.faq-accordion { margin-bottom: 18px; }
.faq-item { border-top: 1px solid var(--border-color-3); }
.faq-item:last-child { border-bottom: 1px solid var(--border-color-3); }
.faq-item summary {
    cursor: pointer; padding: 12px 4px; font-weight: 600; color: var(--text-heading);
    list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; font-size: 1.2em; color: var(--color-accent-text); }
.faq-item[open] summary::after { content: "\2212"; }
.faq-item p { padding: 0 4px 14px; color: var(--text-muted); }

.quiz-status { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.quiz-status .badge--pass { background: var(--status-green-bg); color: var(--status-green-text); }
.quiz-status .badge--fail { background: var(--status-red-bg); color: var(--status-red-text); }

/* ---------------- Modal (quiz + quiz builder) ---------------- */
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 1000; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(11,20,27,0.5); }
.modal-card {
    position: relative; z-index: 1; width: min(560px, 92vw); max-height: 86vh; overflow-y: auto;
    margin: 6vh auto; background: var(--surface-card); border-radius: 12px; padding: 30px 28px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-card--wide { width: min(760px, 94vw); }
.modal-close { position: absolute; right: 14px; top: 10px; font-size: 26px; background: none; border: none; cursor: pointer; color: var(--text-muted-2); }

/* Mandatory MFA setup: no way to dismiss until it's actually done. */
.modal--mandatory .modal-close { display: none; }
.modal--mandatory .modal-backdrop { pointer-events: none; }

/* Quiz-taking */
.quiz-question { margin-bottom: 20px; }
.quiz-question__text { font-weight: 700; color: var(--text-heading); margin-bottom: 10px; }
.quiz-option { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.quiz-option input { flex-shrink: 0; }
.quiz-option label { font-weight: 400; margin: 0; cursor: pointer; }
.quiz-option.is-correct label { color: var(--status-green-text); font-weight: 600; }
.quiz-option.is-wrong label { color: var(--status-red-text); text-decoration: line-through; }
.quiz-result-banner {
    padding: 14px 16px; border-radius: 8px; font-weight: 700; margin-bottom: 20px;
    display: flex; justify-content: space-between; align-items: center;
}
.quiz-result-banner.pass { background: var(--status-green-bg); color: var(--status-green-text); }
.quiz-result-banner.fail { background: var(--status-red-bg); color: var(--status-red-text); }

/* ---------------- Admin: training module management ---------------- */
.manage-item { background: var(--surface-card); border: 1px solid var(--border-color); border-radius: 8px; padding: 18px 20px; margin-bottom: 14px; }
.manage-item__top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.manage-item__title { font-weight: 700; color: var(--text-heading); }
.manage-item__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.manage-faq-row { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px dashed var(--border-color); font-size: 0.9em; }
.manage-faq-row:first-child { border-top: none; }
.small-btn { padding: 4px 10px; font-size: 0.72em; }

.builder-question { border: 1px solid var(--border-color); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
.builder-question__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.builder-option-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.builder-option-row input[type="text"] { flex: 1; }
.link-btn { background: none; border: none; color: var(--color-accent-text); font-weight: 600; cursor: pointer; padding: 4px 0; font-size: 0.85em; }
.link-btn.danger { color: var(--status-red-text); }

/* ---------------- Filter bar ---------------- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.filter-bar input, .filter-bar select {
    padding: 8px 10px; border: 1px solid var(--border-color-2); border-radius: 6px; font-family: var(--font-body); font-size: 0.88em;
}
.filter-bar input { flex: 1; min-width: 180px; }

/* ---------------- SLA / view button on ticket items ---------------- */
.badge--overdue { background: var(--status-red-bg); color: var(--status-red-text); }
.badge--escalated { background: var(--status-orange-bg); color: var(--status-orange-text); }
.ticket-item__view-btn { margin-left: auto; }

/* ---------------- Dashboard ---------------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card { background: var(--surface-card); border: 1px solid var(--border-color); border-radius: 8px; padding: 18px 20px; box-shadow: var(--shadow-md); }
.stat-card .stat-value { font-family: var(--font-header); font-size: 1.9em; font-weight: 700; color: var(--text-heading); }
.stat-card .stat-label { font-size: 0.82em; color: var(--text-muted-2); margin-top: 4px; }
.stat-card.overdue .stat-value { color: var(--status-red-text); }
.stat-breakdown { grid-column: 1 / -1; background: var(--surface-card); border: 1px solid var(--border-color); border-radius: 8px; padding: 18px 20px; }
.stat-breakdown h3 { font-size: 1em; margin-bottom: 10px; }
.stat-row { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px dashed var(--border-color-3); font-size: 0.9em; }
.stat-row:first-of-type { border-top: none; }

/* ---------------- Ticket detail modal ---------------- */
.detail-meta { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 16px; font-size: 0.85em; color: var(--text-muted); }
.detail-controls { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border-color-3); }
.detail-controls select { padding: 8px 10px; border: 1px solid var(--border-color-2); border-radius: 6px; }
.detail-section { margin-bottom: 22px; }
.detail-section h3 { font-size: 1em; color: var(--text-heading); margin-bottom: 10px; }

.comment-thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.comment {
    background: var(--color-background-light); border-radius: 8px; padding: 12px 14px;
}
.comment.is-mine { background: var(--status-blue-bg); }
.comment__head { display: flex; justify-content: space-between; font-size: 0.8em; color: var(--text-muted); margin-bottom: 4px; }
.comment__author { font-weight: 700; color: var(--text-heading); }
.comment__body { white-space: pre-wrap; font-size: 0.92em; }
.comment-form { display: flex; gap: 8px; align-items: flex-start; }
.comment-form textarea { flex: 1; padding: 8px 10px; border: 1px solid var(--border-color-2); border-radius: 6px; font-family: var(--font-body); }

.attachment-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.attachment-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: var(--color-background-light); border-radius: 6px; font-size: 0.88em; }
.attachment-row a { color: var(--color-accent-text); font-weight: 600; }
.attachment-size { color: var(--text-muted-3); font-size: 0.85em; }

.event-timeline { list-style: none; font-size: 0.85em; color: var(--text-muted); }
.event-timeline li { padding: 5px 0; border-top: 1px dashed var(--border-color-3); }
.event-timeline li:first-child { border-top: none; }

/* ---------------- Wiki content rendering ---------------- */
.wiki-content { margin: 18px 0; line-height: 1.65; }
.wiki-content h1 { font-size: 1.6em; margin: 20px 0 10px; color: var(--text-heading); }
.wiki-content h2 { font-size: 1.35em; margin: 18px 0 8px; color: var(--text-heading); text-align: left; }
.wiki-content h3 { font-size: 1.15em; margin: 16px 0 6px; }
.wiki-content p { margin-bottom: 12px; }
.wiki-content ul, .wiki-content ol { margin: 0 0 12px 24px; }
.wiki-content li { margin-bottom: 4px; }
.wiki-content code { font-family: var(--font-mono); background: var(--color-background-light); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.wiki-content pre { background: var(--color-primary-dark); color: #eef1f4; padding: 14px 16px; border-radius: 8px; overflow-x: auto; margin-bottom: 14px; }
.wiki-content pre code { background: none; color: inherit; padding: 0; }
.wiki-content a { color: var(--color-accent-text); font-weight: 600; }

/* ---------------- Manage Users ---------------- */
.user-row { background: var(--surface-card); border: 1px solid var(--border-color); border-radius: 8px; padding: 14px 18px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.user-row__info { display: flex; flex-direction: column; gap: 2px; }
.user-row__name { font-weight: 700; color: var(--text-heading); }
.user-row__meta { font-size: 0.82em; color: var(--text-muted-2); }
.user-row__controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-row__controls select { padding: 6px 8px; border: 1px solid var(--border-color-2); border-radius: 5px; font-size: 0.85em; }
.badge--inactive { background: var(--status-gray-bg); color: var(--status-gray-text); }

/* ---------------- Assets ---------------- */
.badge--active { background: var(--status-green-bg); color: var(--status-green-text); }
.badge--sold { background: var(--status-blue-bg); color: var(--status-blue-text); }
.badge--retired { background: var(--status-gray-bg); color: var(--status-gray-text); }
.asset-value { font-family: var(--font-header); font-size: 1.8em; font-weight: 700; color: var(--text-heading); }
.asset-value-label { font-size: 0.7em; font-weight: 500; color: var(--text-muted-3); text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------------- MFA / Security ---------------- */
.mfa-on-label { color: var(--status-green-text); }
.badge--mfa-on { background: var(--status-green-bg); color: var(--status-green-text); }
.badge--mfa-off { background: var(--status-gray-bg); color: var(--text-muted-3); }
.qr-code-wrap { text-align: center; margin: 16px 0; }
.qr-code-wrap img { width: 200px; height: 200px; border: 1px solid var(--border-color); border-radius: 8px; }
.mfa-secret-manual { font-family: var(--font-mono); font-size: 0.85em; background: var(--color-background-light); padding: 8px 12px; border-radius: 6px; text-align: center; word-break: break-all; margin: 10px 0; }
.backup-codes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.backup-codes-grid code { font-family: var(--font-mono); background: var(--color-background-light); padding: 8px 10px; border-radius: 6px; text-align: center; font-size: 0.9em; }
.backup-codes-warning { background: var(--status-orange-bg); color: var(--status-orange-text); border: 1px solid var(--status-orange-border); padding: 12px 14px; border-radius: 6px; font-size: 0.88em; margin-bottom: 12px; }
