/* =============================================================================
   Workforce Activity Portal - enterprise UI
   No external dependency: this file is the whole design system, so the portal
   works on an air-gapped intranet.
   Palette roles follow the validated data-viz reference palette; light and dark
   are separately selected steps, not an automatic inversion.
   ========================================================================== */

:root {
    color-scheme: light;

    /* surfaces */
    --surface-0:      #f4f4f2;   /* app background */
    --surface-1:      #fcfcfb;   /* cards, chart surface */
    --surface-2:      #eeeeea;   /* table stripe, inset */
    --surface-3:      #e3e3de;   /* hover */
    --border:         #dcdcd6;
    --border-strong:  #c4c4bc;

    /* ink */
    --text-primary:   #0b0b0b;
    --text-secondary: #52514e;
    --text-muted:     #7c7b76;
    --text-inverse:   #ffffff;

    /* brand */
    --brand:          #1c5cab;
    --brand-strong:   #184f95;
    --brand-soft:     #cde2fb;

    /* categorical series (fixed order - never cycled) */
    --series-1:  #2a78d6;   /* blue    */
    --series-2:  #eb6834;   /* orange  */
    --series-3:  #1baf7a;   /* aqua    */
    --series-4:  #eda100;   /* yellow  */
    --series-5:  #e87ba4;   /* magenta */
    --series-6:  #008300;   /* green   */
    --series-7:  #4a3aa7;   /* violet  */
    --series-8:  #e34948;   /* red     */

    /* sequential blue ramp (heat map) */
    --seq-100: #cde2fb;
    --seq-200: #9ec5f4;
    --seq-300: #6da7ec;
    --seq-400: #3987e5;
    --seq-500: #256abf;
    --seq-600: #184f95;
    --seq-700: #0d366b;

    /* status - fixed, never themed, always paired with an icon or label */
    --good:     #0ca30c;
    --warning:  #fab219;
    --serious:  #ec835a;
    --critical: #d03b3b;

    /* geometry */
    --radius:    6px;
    --radius-lg: 10px;
    --shadow-1:  0 1px 2px rgba(11,11,11,.06), 0 1px 3px rgba(11,11,11,.04);
    --shadow-2:  0 4px 12px rgba(11,11,11,.08), 0 1px 3px rgba(11,11,11,.05);
    --sidebar-w: 232px;
    --header-h:  56px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --surface-0:      #121211;
    --surface-1:      #1a1a19;
    --surface-2:      #232322;
    --surface-3:      #2e2e2c;
    --border:         #34342f;
    --border-strong:  #4a4a44;

    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #8f8e85;
    --text-inverse:   #0b0b0b;

    --brand:          #3987e5;
    --brand-strong:   #2a78d6;
    --brand-soft:     #184f95;

    --series-1:  #3987e5;
    --series-2:  #d95926;
    --series-3:  #199e70;
    --series-4:  #c98500;
    --series-5:  #d55181;
    --series-6:  #008300;
    --series-7:  #9085e9;
    --series-8:  #e66767;

    --seq-100: #0d366b;
    --seq-200: #184f95;
    --seq-300: #256abf;
    --seq-400: #2a78d6;
    --seq-500: #3987e5;
    --seq-600: #6da7ec;
    --seq-700: #9ec5f4;

    --shadow-1: 0 1px 2px rgba(0,0,0,.5);
    --shadow-2: 0 6px 18px rgba(0,0,0,.55);
}

/* ---------------------------------------------------------------- reset --- */

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

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--surface-0);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

table { border-collapse: collapse; width: 100%; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 3px;
}

.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* -------------------------------------------------------------- shell ----- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.brand-mark {
    width: 26px; height: 26px;
    border-radius: 7px;
    background: linear-gradient(135deg, var(--series-1), var(--series-7));
    display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: 13px;
    flex: 0 0 auto;
}

.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: 13px; line-height: 1.2; }
.brand-text span {
    display: block; font-size: 11px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav { padding: 12px 8px; overflow-y: auto; flex: 1 1 auto; }
.nav-group { margin-bottom: 14px; }
.nav-group-title {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    padding: 4px 10px 6px;
}

.nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }
.nav a.active {
    background: var(--brand-soft);
    color: var(--brand-strong);
    font-weight: 600;
}
:root[data-theme="dark"] .nav a.active { color: #fff; }
.nav a .ico {
    width: 16px; height: 16px; flex: 0 0 auto; opacity: .85;
    display: inline-flex; align-items: center; justify-content: center;
}
.nav a .ico svg { width: 16px; height: 16px; display: block; }
.nav a.active .ico { opacity: 1; }

/* Icon-only button (the theme toggle) */
.btn-icon { padding: 5px 7px; line-height: 0; }
.btn-icon svg { width: 15px; height: 15px; display: block; }
.nav a .count {
    margin-left: auto; font-size: 11px; font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.sidebar-foot {
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    font-size: 11px;
    color: var(--text-muted);
    flex: 0 0 auto;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--header-h);
    display: flex; align-items: center; gap: 14px;
    padding: 0 20px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { flex: 0 0 auto; }
.topbar .spacer { flex: 1 1 auto; }

.user-chip {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 8px 4px 4px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-1);
}
.avatar {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--brand); color: #fff;
    display: grid; place-items: center;
    font-size: 11px; font-weight: 700;
}
.user-chip .who { font-size: 12px; line-height: 1.1; }
.user-chip .who small { display: block; color: var(--text-muted); font-size: 10.5px; }

.content { padding: 20px; flex: 1 1 auto; }

/* --------------------------------------------------------------- cards ---- */

.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 16px; }

.card-head {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
}
.card-head h2 { flex: 0 0 auto; }
.card-head .sub { font-size: 12px; color: var(--text-muted); }
.card-head .spacer { flex: 1 1 auto; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.split-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.split-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }

@media (max-width: 1200px) {
    .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.split-2-1, .grid.split-1-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
    .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
    .sidebar { display: none; }
}

/* ----------------------------------------------------------- stat tiles --- */

.stat {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-1);
    min-width: 0;
}
.stat .label {
    font-size: 12px; color: var(--text-secondary);
    display: flex; align-items: center; gap: 6px;
}
.stat .value {
    font-size: 26px; font-weight: 600; letter-spacing: -0.02em;
    margin-top: 4px; line-height: 1.15;
}
.stat .value.hero { font-size: 48px; }
.stat .foot { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.stat .spark { margin-top: 8px; height: 28px; }

.stat-dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 auto;
}

/* meter: fill carries severity, track is a lighter step of the same ramp */
.meter { height: 6px; border-radius: 3px; background: var(--seq-100); overflow: hidden; margin-top: 10px; }
.meter > i { display: block; height: 100%; background: var(--seq-500); border-radius: 3px; }
.meter.warn > i { background: var(--warning); }
.meter.bad  > i { background: var(--critical); }

/* --------------------------------------------------------------- pills ---- */

.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px; font-weight: 500;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    white-space: nowrap;
}
.pill::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%;
    background: currentColor; flex: 0 0 auto;
}
.pill-good     { color: #0a7d0a; border-color: #b7e3b7; background: #edf8ed; }
.pill-warning  { color: #8a5c00; border-color: #f4e0ae; background: #fdf6e5; }
.pill-serious  { color: #a04a22; border-color: #f6cdb9; background: #fdf0e9; }
.pill-critical { color: #a12a2a; border-color: #f2bdbd; background: #fceded; }
.pill-muted    { color: var(--text-muted); }
.pill-info     { color: var(--brand-strong); border-color: var(--brand-soft); background: var(--brand-soft); }

:root[data-theme="dark"] .pill-good     { color: #7fd47f; border-color: #1f4a1f; background: #12280f; }
:root[data-theme="dark"] .pill-warning  { color: #f0c669; border-color: #4d3c12; background: #2a2109; }
:root[data-theme="dark"] .pill-serious  { color: #f0a780; border-color: #4d2c1c; background: #2b1a12; }
:root[data-theme="dark"] .pill-critical { color: #f08c8c; border-color: #4d2020; background: #2b1212; }
:root[data-theme="dark"] .pill-info     { color: #a9cdf7; border-color: #1d3f6b; background: #14263d; }

/* ------------------------------------------------------------- controls --- */

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: var(--surface-1);
    color: var(--text-primary);
    font: inherit; font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--brand); border-color: var(--brand); color: #fff;
}
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-danger { border-color: var(--critical); color: var(--critical); background: transparent; }
.btn-danger:hover { background: rgba(208,59,59,.08); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }

input[type=text], input[type=password], input[type=search], input[type=date],
input[type=number], input[type=email], select, textarea {
    padding: 6px 9px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-1);
    color: var(--text-primary);
    font: inherit; font-size: 13px;
    min-width: 0;
}
select { padding-right: 26px; }
label { font-size: 12px; color: var(--text-secondary); }

.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

/* filters live in ONE row above the charts */
.filterbar {
    display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    box-shadow: var(--shadow-1);
}
.filterbar .spacer { flex: 1 1 auto; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.segmented a {
    padding: 6px 10px; font-size: 12.5px; color: var(--text-secondary);
    border-right: 1px solid var(--border); background: var(--surface-1); text-decoration: none;
}
.segmented a:last-child { border-right: 0; }
.segmented a:hover { background: var(--surface-2); text-decoration: none; }
.segmented a.active { background: var(--brand); color: #fff; }

/* --------------------------------------------------------------- tables --- */

.table-wrap { overflow-x: auto; }

table.data { font-size: 13px; }
table.data thead th {
    position: sticky; top: 0; z-index: 1;
    text-align: left;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted);
    background: var(--surface-1);
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data thead th a { color: inherit; }
table.data tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.nowrap { white-space: nowrap; }
table.data .muted { color: var(--text-muted); }
table.data .truncate { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sort-caret { font-size: 9px; opacity: .7; }

.empty {
    padding: 34px 16px; text-align: center; color: var(--text-muted); font-size: 13px;
}
.empty strong { display: block; color: var(--text-secondary); margin-bottom: 4px; font-size: 14px; }

/* colour key beside a label - identity never comes from coloured text */
.key {
    width: 9px; height: 9px; border-radius: 2px;
    display: inline-block; flex: 0 0 auto; margin-right: 7px;
    vertical-align: -1px;
}
.key.round { border-radius: 50%; }

/* -------------------------------------------------------------- charts ---- */

.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { font-size: 11px; fill: var(--text-muted); }
.chart .axis line, .chart .grid line {
    stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges;
}
.chart .series-label { font-size: 11px; fill: var(--text-secondary); }

.legend {
    display: flex; flex-wrap: wrap; gap: 6px 16px;
    padding: 10px 16px 0;
    font-size: 12px; color: var(--text-secondary);
}
.legend .item { display: inline-flex; align-items: center; }

.tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
    padding: 8px 10px;
    font-size: 12px;
    min-width: 130px;
    z-index: 50;
    opacity: 0;
    transition: opacity .08s linear;
}
.tooltip.on { opacity: 1; }
.tooltip .t-title { font-weight: 600; margin-bottom: 5px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tooltip .t-row .t-val { margin-left: auto; font-variant-numeric: tabular-nums; }

/* heat map cells */
.heat { display: grid; gap: 2px; }
.heat .cell { border-radius: 2px; aspect-ratio: 1 / 1; }
.heat-axis { font-size: 10.5px; color: var(--text-muted); }

/* timeline strip */
.timeline { position: relative; height: 44px; background: var(--surface-2); border-radius: var(--radius); overflow: hidden; }
.timeline i { position: absolute; top: 0; bottom: 0; }
.timeline-scale { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); margin-top: 4px; }

/* ---------------------------------------------------------- notifications - */

.banner {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    margin-bottom: 16px;
    font-size: 13px;
}
.banner.good     { border-color: #b7e3b7; background: #edf8ed; color: #0a5c0a; }
.banner.warning  { border-color: #f4e0ae; background: #fdf6e5; color: #7a5100; }
.banner.critical { border-color: #f2bdbd; background: #fceded; color: #8f2323; }
:root[data-theme="dark"] .banner.good     { border-color: #1f4a1f; background: #12280f; color: #9be09b; }
:root[data-theme="dark"] .banner.warning  { border-color: #4d3c12; background: #2a2109; color: #f0c669; }
:root[data-theme="dark"] .banner.critical { border-color: #4d2020; background: #2b1212; color: #f0a0a0; }

.banner .ico {
    flex: 0 0 auto; width: 16px; height: 16px; margin-top: 2px;
    display: inline-flex; align-items: center; justify-content: center;
}
.banner .ico svg { width: 16px; height: 16px; display: block; }

/* ---------------------------------------------------------------- misc ---- */

.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 2px; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }

.token-box {
    font-family: var(--mono); font-size: 18px; letter-spacing: .06em;
    padding: 12px 16px; background: var(--surface-2);
    border: 1px dashed var(--border-strong); border-radius: var(--radius);
    user-select: all;
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

.pager { display: flex; align-items: center; gap: 6px; padding: 10px 16px; border-top: 1px solid var(--border); }
.pager .spacer { flex: 1 1 auto; }

/* ------------------------------------------------------------ login page -- */

.login-shell {
    min-height: 100vh; display: grid; place-items: center;
    background:
      radial-gradient(1000px 500px at 15% -10%, var(--brand-soft), transparent 60%),
      var(--surface-0);
    padding: 24px;
}
.login-card {
    width: 100%; max-width: 380px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    padding: 28px;
}
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-card .sub { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card input { width: 100%; padding: 9px 11px; font-size: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 9px; font-size: 14px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }

/* ------------------------------------------------------------- printing -- */

@media print {
    .sidebar, .topbar, .filterbar, .btn, .pager { display: none !important; }
    .content { padding: 0; }
    .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
    body { background: #fff; }
}
