/* ==========================================================================
   QMS design system - light/dark, desktop-first with a mobile drawer.
   Same approach as GLP-Won: tokens on :root, redefined for the dark theme,
   no CDN, no JS framework.

   Light is the LIVE TULA brand (livetula.com/style-guide): Navy #002F3F and
   Green #128040 as the primaries, Orange #E66E17 and Light Blue #EAF6FA as
   the secondaries, Poppins throughout - SemiBold headlines, Regular all-caps
   sub-headlines, Bold section headlines, Regular paragraphs, navy text except
   on a dark ground.

   Dark is the same system on a Tron grid: near-black blue, cyan light lines,
   neon status inks, a glow where light mode has a shadow.
   ========================================================================== */

/* --- Poppins, self-hosted (SIL OFL 1.1, see /fonts/poppins/OFL.txt) ------- */
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/poppins/poppins-400.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: italic; font-weight: 400; font-display: swap; src: url("../fonts/poppins/poppins-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/poppins/poppins-500.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/poppins/poppins-600.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/poppins/poppins-700.woff2") format("woff2"); }

:root {
    color-scheme: light;

    /* LIVE TULA palette, verbatim from the style guide. */
    --tula-navy: #002F3F;
    --tula-green: #128040;
    --tula-orange: #E66E17;
    --tula-light-blue: #EAF6FA;

    /* Surfaces. The ground is the brand light blue; every card is white on it. */
    --bg: var(--tula-light-blue);
    --surface: #ffffff;
    --surface-2: #f3f9fb;
    --border: #d3e4eb;
    --track: #e1eef3;
    --text: var(--tula-navy);
    --text-muted: #4a6671;
    --shadow: 0 2px 10px rgba(0, 47, 63, 0.07);

    /* Navy carries buttons and the active state; green carries links and "yes". */
    --accent: var(--tula-navy);
    --accent-hover: #0b4257;
    --accent-ink: #ffffff;
    --accent-soft: #dceef5;
    --accent-soft-ink: var(--tula-navy);
    --link: var(--tula-green);
    --link-hover: #0e6a35;
    --focus: var(--tula-green);

    /* Status inks and their soft fills. Each ink clears 4.5:1 on white and on its own fill. */
    --ok-ink: #0f6b36;      --ok-soft: #dcf2e4;
    --warn-ink: #9a4a0c;    --warn-soft: #fbe8d8;
    --danger-ink: #b3243a;  --danger-soft: #fde1e5;
    --info-ink: var(--tula-navy); --info-soft: #d9ecf4;
    --neutral-ink: #3f5a65; --neutral-soft: #e4eef2;
    --muted-ink: #5d7580;   --muted-soft: #eaf2f5;

    /* The navigation rail is a dark ground, so its text is light. */
    --nav-bg: var(--tula-navy);
    --nav-bg-2: #073a4d;
    --nav-text: #ffffff;
    --nav-muted: #a9c9d4;
    --nav-border: rgba(255, 255, 255, 0.12);
    --nav-hover-bg: rgba(255, 255, 255, 0.07);
    --nav-active-bg: rgba(255, 255, 255, 0.11);
    --nav-active-text: #ffffff;
    --nav-accent: #3fcf7a;

    --radius: 10px;
    --radius-sm: 6px;
    --nav-w: 248px;
    --font: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --caps-tracking: 0.08em;
}

/* --- Dark: the grid ---------------------------------------------------------- */
:root[data-theme="dark"] {
    color-scheme: dark;

    --cyan: #3fe3ff;
    --cyan-dim: #1fb7d6;

    --bg: #04080f;
    --surface: #080f1b;
    --surface-2: #0c1626;
    --border: rgba(63, 227, 255, 0.22);
    --track: #10203a;
    --text: #d3eef8;
    --text-muted: #7fa9ba;
    --shadow: 0 0 0 1px rgba(63, 227, 255, 0.05), 0 0 28px rgba(63, 227, 255, 0.07);

    --accent: var(--cyan);
    --accent-hover: #7cedff;
    --accent-ink: #03101a;
    --accent-soft: rgba(63, 227, 255, 0.12);
    --accent-soft-ink: var(--cyan);
    --link: var(--cyan);
    --link-hover: #8df0ff;
    --focus: var(--cyan);

    --ok-ink: #4ef59c;      --ok-soft: rgba(78, 245, 156, 0.12);
    --warn-ink: #ffa047;    --warn-soft: rgba(255, 160, 71, 0.13);
    --danger-ink: #ff5d7a;  --danger-soft: rgba(255, 93, 122, 0.13);
    --info-ink: var(--cyan); --info-soft: rgba(63, 227, 255, 0.10);
    --neutral-ink: #9fc6d4; --neutral-soft: rgba(159, 198, 212, 0.12);
    --muted-ink: #7fa9ba;   --muted-soft: rgba(127, 169, 186, 0.10);

    --nav-bg: #030710;
    --nav-bg-2: #071021;
    --nav-text: #e2f6fc;
    --nav-muted: #7fa9ba;
    --nav-border: rgba(63, 227, 255, 0.25);
    --nav-hover-bg: rgba(63, 227, 255, 0.06);
    --nav-active-bg: rgba(63, 227, 255, 0.10);
    --nav-active-text: var(--cyan);
    --nav-accent: var(--cyan);

    --glow: 0 0 10px rgba(63, 227, 255, 0.55), 0 0 24px rgba(63, 227, 255, 0.25);
    --radius: 6px;
    --radius-sm: 4px;
}

/* --- Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14.5px; line-height: 1.55; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.005em; color: var(--text); }
h1 { font-size: 1.6rem; font-weight: 600; }          /* Headlines: Poppins SemiBold */
h2 { font-size: 1.1rem; font-weight: 700; }          /* Section headlines: Poppins Bold */
h3 { font-size: 0.98rem; font-weight: 700; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
.icon { width: 1em; height: 1em; vertical-align: -0.15em; flex: none; }
.muted { color: var(--text-muted); }
.small { font-size: 0.86rem; }
.tiny { font-size: 0.76rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.wrap { white-space: normal; }
.center { text-align: center; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.gap-8 { gap: 8px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-0 { margin-bottom: 0; }
/* Sub-headlines: Poppins Regular, all caps. */
.eyebrow { font-size: 0.72rem; font-weight: 400; letter-spacing: var(--caps-tracking); text-transform: uppercase; color: var(--text-muted); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); color: var(--text); padding: 8px 12px; border-radius: 8px; z-index: 200; }
.skip-link:focus { left: 8px; }

/* Dark: a faint grid under everything and a light source at the top. */
:root[data-theme="dark"] body {
    background-color: var(--bg);
    background-image:
        radial-gradient(ellipse 70% 40% at 50% -10%, rgba(63, 227, 255, 0.10), transparent 70%),
        linear-gradient(rgba(63, 227, 255, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(63, 227, 255, 0.045) 1px, transparent 1px);
    background-size: auto, 36px 36px, 36px 36px;
    background-attachment: fixed;
}
:root[data-theme="dark"] h1 { text-shadow: 0 0 14px rgba(63, 227, 255, 0.22); }
:root[data-theme="dark"] .eyebrow { color: var(--cyan-dim); }
:root[data-theme="dark"] ::selection { background: rgba(63, 227, 255, 0.35); }
:root[data-theme="dark"] { scrollbar-color: rgba(63, 227, 255, 0.35) var(--bg); }

/* --- Shell ----------------------------------------------------------------- */
.app-shell { min-height: 100vh; }
.app-main { max-width: 1120px; margin: 0 auto; padding: 24px 20px 56px; }
.app-shell.no-nav .app-main { max-width: 520px; padding-top: 48px; }

.side-nav {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--nav-w);
    background: var(--nav-bg); color: var(--nav-text); border-right: 1px solid var(--nav-border);
    display: flex; flex-direction: column; z-index: 100;
    transform: translateX(-100%); transition: transform 0.2s ease;
}
:root[data-theme="dark"] .side-nav { box-shadow: 1px 0 24px rgba(63, 227, 255, 0.08); }
.nav-overlay { position: fixed; inset: 0; background: rgba(0, 20, 30, 0.5); z-index: 90; display: none; }
body.menu-open .side-nav { transform: none; }
body.menu-open .nav-overlay { display: block; }

.side-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 12px; }
.brand { font-weight: 700; font-size: 1.3rem; letter-spacing: -0.01em; color: inherit; display: inline-flex; flex-direction: column; line-height: 1.1; }
.brand:hover { text-decoration: none; color: inherit; }
.brand-sub { font-size: 0.66rem; font-weight: 400; letter-spacing: var(--caps-tracking); text-transform: uppercase; color: var(--nav-accent); margin-top: 3px; }
.side-nav .brand { color: var(--nav-text); }
:root[data-theme="dark"] .side-nav .brand { text-shadow: var(--glow); }

.org-switch { padding: 6px 18px 14px; border-bottom: 1px solid var(--nav-border); }
.org-switch .eyebrow { color: var(--nav-muted); }
.org-switch select { width: 100%; margin-top: 6px; background: var(--nav-bg-2); color: var(--nav-text); border-color: var(--nav-border); }
.org-switch select:focus { border-color: var(--nav-accent); box-shadow: 0 0 0 3px rgba(63, 207, 122, 0.25); }
.org-name { font-weight: 600; margin-top: 4px; color: var(--nav-text); }

.side-links { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.side-links a {
    position: relative; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--nav-muted); font-weight: 500; font-size: 0.92rem;
}
.side-links a:hover { background: var(--nav-hover-bg); color: var(--nav-text); text-decoration: none; }
.side-links a.active { background: var(--nav-active-bg); color: var(--nav-active-text); font-weight: 600; }
.side-links a.active::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 2px; background: var(--nav-accent); }
:root[data-theme="dark"] .side-links a.active::before { box-shadow: var(--glow); }
:root[data-theme="dark"] .side-links a.active { text-shadow: 0 0 10px rgba(63, 227, 255, 0.45); }
.side-links .ni { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center; }
.side-links .ni .icon { width: 18px; height: 18px; }
.side-links .nav-sep { height: 1px; background: var(--nav-border); margin: 8px 6px; }

.nav-foot { border-top: 1px solid var(--nav-border); padding: 12px 14px; display: flex; align-items: center; gap: 8px; }
.nav-user { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.nav-user-name { font-weight: 600; font-size: 0.88rem; color: var(--nav-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-user-email { font-size: 0.72rem; color: var(--nav-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-foot-icons { display: flex; gap: 2px; }
.nav-foot-icons a, .nav-foot-icons button {
    display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
    border-radius: var(--radius-sm); border: 0; background: transparent; color: var(--nav-muted); cursor: pointer;
}
.nav-foot-icons a:hover, .nav-foot-icons button:hover { background: var(--nav-hover-bg); color: var(--nav-text); text-decoration: none; }
.nav-foot-icons .icon { width: 17px; height: 17px; }
.nav-foot form { margin: 0; display: inline-flex; }

.topbar {
    position: sticky; top: 0; z-index: 80; display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; background: var(--nav-bg); color: var(--nav-text); border-bottom: 1px solid var(--nav-border);
}
.topbar .brand { font-size: 1.1rem; }
.topbar-org { margin-left: auto; font-size: 0.8rem; color: var(--nav-muted); font-weight: 500; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
    border-radius: var(--radius-sm); border: 1px solid var(--nav-border); background: transparent; color: var(--nav-text); cursor: pointer;
}
.icon-btn .icon { width: 18px; height: 18px; }

@media (min-width: 960px) {
    .app-shell.has-nav { padding-left: var(--nav-w); }
    .side-nav { transform: none; }
    .nav-overlay, .topbar, .nav-close { display: none !important; }
}

/* --- Page head ------------------------------------------------------------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--text-muted); margin: 4px 0 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.crumbs .icon { width: 12px; height: 12px; }
.record-number { font-family: var(--mono); font-size: 0.86rem; color: var(--text-muted); font-weight: 600; }

/* --- Cards ------------------------------------------------------------------ */
.card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.tight { padding: 12px 14px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-title h2 { font-size: 1rem; }
.card-title .head-link { font-size: 0.82rem; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
a.stat { color: inherit; }
a.stat:hover { text-decoration: none; color: inherit; border-color: var(--link); }
.stat .val { font-size: 1.7rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; text-transform: uppercase; letter-spacing: var(--caps-tracking); margin-top: 2px; }
.stat .delta { font-size: 0.76rem; font-weight: 500; }
.stat .delta.danger { color: var(--danger-ink); }
.stat .delta.warn { color: var(--warn-ink); }
.stat .delta.ok { color: var(--ok-ink); }

/* Dark: every panel is a lit edge on the grid - a cyan hairline across the top. */
:root[data-theme="dark"] .card::before,
:root[data-theme="dark"] .stat::before {
    content: ""; position: absolute; left: 8%; right: 8%; top: -1px; height: 1px;
    background: linear-gradient(90deg, transparent, rgba(63, 227, 255, 0.8), transparent);
    pointer-events: none;
}
:root[data-theme="dark"] .card { backdrop-filter: blur(2px); }
:root[data-theme="dark"] .card-title h2 { text-transform: uppercase; letter-spacing: var(--caps-tracking); font-size: 0.82rem; font-weight: 600; color: var(--cyan); }
:root[data-theme="dark"] .stat .val { color: var(--cyan); text-shadow: 0 0 12px rgba(63, 227, 255, 0.45); }
:root[data-theme="dark"] a.stat:hover { box-shadow: var(--glow); border-color: var(--cyan); }

/* --- Lists inside cards --------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; padding-top: 0; }
.list li:last-child { padding-bottom: 0; }
.list .meta { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }
.list .title { flex: 1; min-width: 0; }
.list .title a { color: var(--text); font-weight: 500; }
.list .title a:hover { color: var(--link); }
.list .title .sub { display: block; font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { color: var(--text-muted); padding: 18px 0; text-align: center; font-size: 0.92rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--text-muted); font-size: 0.72rem; font-weight: 400; text-transform: uppercase; letter-spacing: 0.06em; padding-top: 2px; }
.kv dd { margin: 0; }
.prose { max-width: 72ch; }
.prose h1 { font-size: 1.3rem; margin: 18px 0 8px; }
.prose h2 { font-size: 1.05rem; margin: 16px 0 6px; }
.prose h3 { font-size: 0.95rem; margin: 12px 0 4px; }
.prose p, .prose ul, .prose ol { margin: 0 0 10px; }
.prose table { border-collapse: collapse; font-size: 0.9rem; margin-bottom: 10px; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose blockquote { border-left: 3px solid var(--link); margin: 0 0 10px; padding: 2px 12px; color: var(--text-muted); }
.pre { white-space: pre-wrap; }

/* --- Tables ---------------------------------------------------------------- */
.table-wrap { position: relative; overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); margin-bottom: 16px; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.table th, table.table td { padding: 11px 14px; text-align: left; white-space: nowrap; vertical-align: middle; }
table.table thead th { background: var(--surface-2); color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: var(--caps-tracking); font-weight: 400; border-bottom: 1px solid var(--border); }
table.table tbody tr { border-top: 1px solid var(--border); }
table.table tbody tr:hover { background: var(--surface-2); }
table.table td.wrap { white-space: normal; min-width: 240px; }
table.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.table a.row-link { color: var(--text); font-weight: 500; }
table.table a.row-link:hover { color: var(--link); }
table.table td .sub { display: block; font-size: 0.76rem; color: var(--text-muted); font-weight: 400; }
:root[data-theme="dark"] table.table thead th { color: var(--cyan-dim); background: rgba(63, 227, 255, 0.05); }
:root[data-theme="dark"] table.table tbody tr:hover { background: rgba(63, 227, 255, 0.06); }

/* The training matrix: people down, documents across, a tick where both meet. */
.matrix th.doc { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; max-height: 160px; padding: 10px 6px; font-size: 0.72rem; text-transform: none; letter-spacing: 0; }
.matrix td.cell { text-align: center; width: 44px; }
.matrix .tick { color: var(--ok-ink); }
.matrix .cross { color: var(--danger-ink); opacity: 0.7; }

/* --- Badges ---------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.7rem; font-weight: 500; padding: 3px 9px; border-radius: 999px; background: var(--neutral-soft); color: var(--neutral-ink); white-space: nowrap; letter-spacing: 0.02em; border: 1px solid transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok-ink); }
.badge.warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge.danger { background: var(--danger-soft); color: var(--danger-ink); }
.badge.info { background: var(--info-soft); color: var(--info-ink); }
.badge.accent { background: var(--accent-soft); color: var(--accent-soft-ink); }
.badge.muted { background: var(--muted-soft); color: var(--muted-ink); }
.badge.neutral { background: var(--neutral-soft); color: var(--neutral-ink); }
.badge .icon { width: 12px; height: 12px; }
.chip { display: inline-block; font-size: 0.76rem; padding: 2px 8px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); margin: 2px 4px 2px 0; }
/* Dark: badges are outlined light, not filled. */
:root[data-theme="dark"] .badge { border-radius: 3px; border-color: currentColor; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.64rem; padding: 3px 7px; }

/* --- Buttons --------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: var(--radius-sm); border: 1.5px solid transparent;
    font: inherit; font-weight: 500; font-size: 0.88rem; cursor: pointer; text-decoration: none; line-height: 1.2;
    background: var(--surface-2); color: var(--text); transition: background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, color 0.12s ease;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-ink); filter: none; }
.btn-outline { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-outline:hover { background: var(--accent-soft); color: var(--accent-soft-ink); filter: none; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); filter: none; }
.btn-danger { background: var(--danger-soft); color: var(--danger-ink); }
.btn-danger:hover { color: var(--danger-ink); }
.btn-ok { background: var(--tula-green); color: #ffffff; font-weight: 600; }
.btn-ok:hover { background: #0e6a35; color: #ffffff; filter: none; }
.btn-sm { padding: 6px 11px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 15px; height: 15px; }
form.inline { display: inline; margin: 0; }

/* Dark: light lines. Primary is a lit cyan bar; everything else is an outline that lights on hover. */
:root[data-theme="dark"] .btn { background: transparent; border-color: var(--border); color: var(--text); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.78rem; }
:root[data-theme="dark"] .btn:hover { filter: none; border-color: var(--cyan); color: var(--cyan); box-shadow: 0 0 12px rgba(63, 227, 255, 0.25); }
:root[data-theme="dark"] .btn-sm { font-size: 0.72rem; }
:root[data-theme="dark"] .btn-primary { background: var(--cyan); border-color: var(--cyan); color: var(--accent-ink); box-shadow: 0 0 14px rgba(63, 227, 255, 0.35); }
:root[data-theme="dark"] .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); box-shadow: var(--glow); }
:root[data-theme="dark"] .btn-outline { border-color: var(--cyan-dim); color: var(--cyan); }
:root[data-theme="dark"] .btn-outline:hover { background: var(--accent-soft); }
:root[data-theme="dark"] .btn-ghost { border-color: transparent; color: var(--text-muted); }
:root[data-theme="dark"] .btn-ghost:hover { box-shadow: none; }
:root[data-theme="dark"] .btn-danger { background: transparent; border-color: var(--danger-ink); color: var(--danger-ink); }
:root[data-theme="dark"] .btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-ink); color: var(--danger-ink); box-shadow: 0 0 12px rgba(255, 93, 122, 0.35); }
:root[data-theme="dark"] .btn-ok { background: transparent; border-color: var(--ok-ink); color: var(--ok-ink); }
:root[data-theme="dark"] .btn-ok:hover { background: var(--ok-soft); border-color: var(--ok-ink); color: var(--ok-ink); box-shadow: 0 0 12px rgba(78, 245, 156, 0.35); }

/* --- Forms ----------------------------------------------------------------- */
.field { margin-bottom: 14px; }
.field label, .field .label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 5px; }
.field .hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="date"], input[type="number"], input[type="file"], select, textarea {
    width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-size: 0.92rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(18, 128, 64, 0.18); }
:root[data-theme="dark"] input:focus, :root[data-theme="dark"] select:focus, :root[data-theme="dark"] textarea:focus { box-shadow: 0 0 0 1px var(--cyan), 0 0 14px rgba(63, 227, 255, 0.35); }
:root[data-theme="dark"] input, :root[data-theme="dark"] select, :root[data-theme="dark"] textarea { background: #050b14; }
::placeholder { color: var(--text-muted); opacity: 0.7; }
textarea { min-height: 110px; resize: vertical; }
textarea.tall { min-height: 260px; font-family: var(--mono); font-size: 0.86rem; line-height: 1.5; }
select { appearance: auto; }
.field-error { display: block; color: var(--danger-ink); font-size: 0.78rem; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 400; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--tula-green); }
:root[data-theme="dark"] .check input { accent-color: var(--cyan); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 12px; max-height: 260px; overflow-y: auto; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.check-grid .check { font-size: 0.86rem; font-weight: 400; padding: 3px 0; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"] { width: 240px; padding: 8px 12px; }
.toolbar select { width: auto; padding: 8px 32px 8px 12px; }

/* Disclosure for an action that needs a word or two before it happens. */
.action-box { display: inline-block; }
.action-box summary { list-style: none; display: inline-flex; cursor: pointer; }
.action-box summary::-webkit-details-marker { display: none; }
.action-box .action-form { position: relative; margin-top: 10px; padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); min-width: 320px; max-width: 520px; }
.action-box .action-form .field { margin-bottom: 10px; }
.action-box .action-form textarea { min-height: 80px; }
.action-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }

/* --- Alerts and toast ------------------------------------------------------- */
.alert { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 0.9rem; border: 1px solid transparent; border-left-width: 4px; }
.alert .grow { min-width: 180px; }
.alert .icon { width: 18px; height: 18px; margin-top: 2px; }
.alert-info { background: var(--info-soft); color: var(--info-ink); border-left-color: var(--info-ink); }
.alert-warn { background: var(--warn-soft); color: var(--warn-ink); border-left-color: var(--warn-ink); }
.alert-danger { background: var(--danger-soft); color: var(--danger-ink); border-left-color: var(--danger-ink); }
.alert-success { background: var(--ok-soft); color: var(--ok-ink); border-left-color: var(--ok-ink); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.validation-summary-valid { display: none; }
.toast {
    position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 300;
    background: var(--tula-navy); color: #fff; padding: 12px 18px; border-radius: var(--radius); font-size: 0.9rem;
    box-shadow: 0 8px 24px rgba(0, 47, 63, 0.3); max-width: 480px; text-align: center; border-left: 4px solid var(--tula-green);
}
:root[data-theme="dark"] .toast { background: var(--surface); color: var(--cyan); border: 1px solid var(--cyan); border-left-width: 1px; box-shadow: var(--glow); }

/* --- Timeline (version history, CAPA updates, activity) -------------------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 14px 14px; }
.timeline li::before { content: ""; position: absolute; left: -24px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--border); border: 2px solid var(--surface); }
.timeline li.is-now::before { background: var(--link); }
:root[data-theme="dark"] .timeline li::before { background: var(--surface); border-color: var(--cyan-dim); }
:root[data-theme="dark"] .timeline li.is-now::before { background: var(--cyan); box-shadow: var(--glow); }
.timeline .when { font-size: 0.76rem; color: var(--text-muted); }
.timeline .what { font-weight: 600; }
.timeline .note { font-size: 0.9rem; color: var(--text); margin-top: 2px; white-space: pre-wrap; }

/* --- Blockers (what stops the next step) ----------------------------------- */
.blockers { background: var(--warn-soft); color: var(--warn-ink); border-radius: var(--radius); border-left: 4px solid var(--warn-ink); padding: 10px 14px; font-size: 0.86rem; margin-bottom: 12px; }
.blockers ul { margin: 4px 0 0; padding-left: 18px; }

/* --- Account pages ------------------------------------------------------------ */
.acct-brand { text-align: center; margin-bottom: 20px; }
.acct-brand .brand { font-size: 2rem; color: var(--text); align-items: center; }
.acct-brand .brand::after { content: ""; display: block; width: 36px; height: 3px; border-radius: 2px; background: var(--tula-green); margin: 10px auto 0; }
:root[data-theme="dark"] .acct-brand .brand { color: var(--cyan); text-shadow: var(--glow); }
:root[data-theme="dark"] .acct-brand .brand::after { background: var(--cyan); box-shadow: var(--glow); }
.acct-brand .sub { color: var(--text-muted); margin-top: 10px; }
.temp-password { font-family: var(--mono); font-size: 1.3rem; font-weight: 700; letter-spacing: 0.05em; padding: 10px 14px; background: var(--warn-soft); color: var(--warn-ink); border-radius: var(--radius); display: inline-block; user-select: all; }

/* --- Pager ------------------------------------------------------------------- */
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 8px 0 16px; }

@media (max-width: 640px) {
    .app-main { padding: 16px 14px 48px; }
    .page-head { flex-direction: column; }
    .kv { grid-template-columns: 1fr; gap: 2px; }
    .kv dt { margin-top: 6px; }
    .action-box .action-form { min-width: 0; width: 100%; }
    table.table th, table.table td { padding: 9px 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .side-nav, .btn { transition: none; }
}

@media print {
    .side-nav, .topbar, .nav-overlay, .toast, .actions, .action-bar, .btn { display: none !important; }
    .app-shell.has-nav { padding-left: 0; }
    .card, .table-wrap { box-shadow: none; }
    :root[data-theme="dark"] body { background-image: none; }
}
