/* Nikar Agent Portal - styles. Colour tokens first; everything else reads roles, not raw hex. */

:root {
  color-scheme: light;
  --page: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --surface-3: #f0efec;
  --chart-surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #6e6d68;
  --muted: #898781;
  --line: #e4e3dc;
  --line-strong: #c3c2b7;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);

  --brand: #1c5cab;
  --brand-ink: #ffffff;
  --brand-soft: #e6effb;
  --brand-strong: #184f95;
  --sidebar: #0f2744;
  --sidebar-ink: #c9d6e8;
  --sidebar-active: #1c5cab;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-muted: #898781;

  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5;
  --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;

  --good: #0ca30c;      --good-ink: #006300;   --good-soft: #e3f4e3;
  --warning: #fab219;   --warning-ink: #7a5200; --warning-soft: #fdf1d6;
  --serious: #ec835a;   --serious-ink: #963d17; --serious-soft: #fce7de;
  --critical: #d03b3b;  --critical-ink: #a32424; --critical-soft: #f9e1e1;
  --info-soft: #e6effb; --info-ink: #1c5cab;

  --shadow: 0 1px 2px rgba(15, 20, 30, 0.06), 0 4px 16px rgba(15, 20, 30, 0.05);
  --shadow-lg: 0 20px 60px rgba(15, 20, 30, 0.25);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #202020; --surface-3: #2a2a28; --chart-surface: #1a1a19;
    --ink: #ffffff; --ink-2: #c3c2b7; --ink-3: #a3a29a; --muted: #898781;
    --line: #2f2f2c; --line-strong: #454541; --grid: #2c2c2a; --baseline: #383835; --ring: rgba(255, 255, 255, 0.10);
    --brand: #3987e5; --brand-ink: #ffffff; --brand-soft: #16263b; --brand-strong: #5598e7;
    --sidebar: #111418; --sidebar-ink: #b8c1cc; --sidebar-active: #2a78d6;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #b7d3f6;
    --good-ink: #0ca30c; --good-soft: #13291a; --warning-ink: #fab219; --warning-soft: #2f2610;
    --serious-ink: #ec835a; --serious-soft: #33211a; --critical-ink: #ef7070; --critical-soft: #341818;
    --info-soft: #16263b; --info-ink: #86b6ef;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #202020; --surface-3: #2a2a28; --chart-surface: #1a1a19;
  --ink: #ffffff; --ink-2: #c3c2b7; --ink-3: #a3a29a; --muted: #898781;
  --line: #2f2f2c; --line-strong: #454541; --grid: #2c2c2a; --baseline: #383835; --ring: rgba(255, 255, 255, 0.10);
  --brand: #3987e5; --brand-ink: #ffffff; --brand-soft: #16263b; --brand-strong: #5598e7;
  --sidebar: #111418; --sidebar-ink: #b8c1cc; --sidebar-active: #2a78d6;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #b7d3f6;
  --good-ink: #0ca30c; --good-soft: #13291a; --warning-ink: #fab219; --warning-soft: #2f2610;
  --serious-ink: #ec835a; --serious-soft: #33211a; --critical-ink: #ef7070; --critical-soft: #341818;
  --info-soft: #16263b; --info-ink: #86b6ef;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); background: var(--page); color: var(--ink); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.small { font-size: 12px; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
[hidden] { display: none !important; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* ---------- login ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--brand-soft), transparent), var(--page); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand h1 { font-size: 20px; }
.login-hint { margin-top: 20px; padding: 12px; background: var(--surface-2); border-radius: var(--radius-sm); font-size: 12px; color: var(--ink-2); }
.login-hint code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.logo { width: 40px; height: 40px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; letter-spacing: -0.5px; flex: none; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; color: #fff; }
.sidebar-brand .logo { width: 36px; height: 36px; font-size: 16px; background: #2a78d6; }
.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand span { font-size: 11px; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.08em; }
.nav { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.55; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--sidebar-ink); font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, 0.07); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { width: 20px; text-align: center; font-size: 15px; opacity: 0.9; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; font-size: 11.5px; opacity: 0.6; border-top: 1px solid rgba(255, 255, 255, 0.08); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title .crumbs { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--ink); font: inherit; }
.user-chip .avatar { width: 28px; height: 28px; font-size: 11px; }
.user-chip small { color: var(--muted); display: block; font-size: 11px; line-height: 1.1; text-transform: capitalize; }
.user-chip span { text-align: left; line-height: 1.2; }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50; }
.dropdown-menu button, .dropdown-menu a { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; color: var(--ink); font: inherit; border-radius: 6px; cursor: pointer; }
.dropdown-menu button:hover, .dropdown-menu a:hover { background: var(--surface-3); text-decoration: none; }

.page { padding: 24px; max-width: 1480px; width: 100%; margin: 0 auto; }
.page.loading { opacity: 0.55; transition: opacity 0.15s; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-strong); }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); background: var(--critical); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn.btn-icon { padding: 4px 5px; min-width: 28px; }

/* Line icons drawn with CSS masks so they take the text colour and render the same in every browser. */
.ico { display: inline-block; width: 16px; height: 16px; flex: none; vertical-align: -3px; background: currentColor;
  -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; }
.ico-trash { color: var(--critical-ink); --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6M10 11v6M14 11v6'/%3E%3C/svg%3E"); }
.ico-edit { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E"); }
.ico-ban { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M5.6 5.6l12.8 12.8'/%3E%3C/svg%3E"); }
.ico-check { color: var(--good-ink); --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='m8 12 3 3 5-6'/%3E%3C/svg%3E"); }
.btn-danger .ico, .btn-primary .ico { color: inherit; }
.btn:disabled .ico { opacity: 0.5; }
.icon-btn { border: 0; background: transparent; color: var(--ink-2); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
input[readonly] { background: var(--surface-2); color: var(--ink-2); }
label { display: block; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.field .req { color: var(--critical-ink); }
.field .hint { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; font-weight: 400; }
.field .hint.warn { color: var(--warning-ink); }
.field .hint.bad { color: var(--critical-ink); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
legend { font-weight: 650; padding: 0 6px; color: var(--ink); }
legend small { font-weight: 400; color: var(--muted); }
.form-error { background: var(--critical-soft); color: var(--critical-ink); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-weight: 500; }
.form-error::before { content: '✕  '; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filters .field { min-width: 150px; flex: 0 1 180px; }
.filters .field.grow { flex: 1 1 240px; }
.filters .field > span { font-size: 11.5px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg { flex-wrap: wrap; }
.filters .field:has(.seg) { flex: 0 1 auto; max-width: 100%; }
.seg button { white-space: nowrap; border: 0; background: transparent; padding: 7px 12px; font: inherit; color: var(--ink-2); cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 650; }

/* ---------- cards / layout ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { font-size: 12px; color: var(--ink-2); font-weight: 550; display: flex; justify-content: space-between; gap: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; margin: 4px 0 2px; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.delta { font-size: 12px; font-weight: 600; display: inline-flex; gap: 4px; align-items: baseline; }
.delta-good { color: var(--good-ink); }
.delta-bad { color: var(--critical-ink); }
.delta .muted { font-weight: 400; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.table td.wrap { white-space: normal; min-width: 240px; }
.table td.wrap-sm { white-space: normal; min-width: 130px; max-width: 220px; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--ink); }
.table th .arrow { font-size: 10px; margin-left: 3px; }
.table-compact td, .table-compact th { padding: 6px 10px; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line-strong); }
tr.clickable { cursor: pointer; }
.person { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.person .avatar { width: 32px; height: 32px; font-size: 12px; }
.person small { display: block; color: var(--muted); font-size: 11.5px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); gap: 12px; flex-wrap: wrap; font-size: 13px; }

.avatar { border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar.lg { width: 72px; height: 72px; font-size: 26px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; white-space: nowrap; }
.badge-good { background: var(--good-soft); color: var(--good-ink); }
.badge-warning { background: var(--warning-soft); color: var(--warning-ink); }
.badge-serious { background: var(--serious-soft); color: var(--serious-ink); }
.badge-critical { background: var(--critical-soft); color: var(--critical-ink); }
.badge-info { background: var(--info-soft); color: var(--info-ink); }
.badge-neutral { background: var(--surface-3); color: var(--ink-2); }

/* ---------- attainment bar ---------- */
.att { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.att-track { position: relative; flex: 1; height: 8px; background: var(--surface-3); border-radius: 4px; }
.att-fill { height: 100%; border-radius: 4px; }
.att-good { background: var(--good); }
.att-ok { background: var(--series-1); }
.att-warning { background: var(--warning); }
.att-critical { background: var(--critical); }
.att-pace { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--ink); border-radius: 1px; box-shadow: 0 0 0 2px var(--surface); }
.att-label { font-size: 12px; font-weight: 650; min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- charts ---------- */
.viz { position: relative; min-width: 0; }
.viz-plot { width: 100%; min-height: 40px; }
.viz svg { display: block; overflow: visible; }
.viz-grid { stroke: var(--grid); stroke-width: 1; }
.viz-baseline { stroke: var(--baseline); stroke-width: 1; }
.viz-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-line.dashed { stroke-dasharray: 5 4; stroke-width: 1.5; }
.viz-dot { stroke: var(--chart-surface); stroke-width: 2; }
.viz-hover-dot { stroke: var(--chart-surface); stroke-width: 2; pointer-events: none; }
.viz-cross { stroke: var(--line-strong); stroke-width: 1; pointer-events: none; }
.viz-bar { opacity: 0.9; }
.viz-hit { cursor: crosshair; outline: none; }
.viz-hit:focus-visible { stroke: var(--brand); stroke-width: 1; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.viz-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend-key.line { width: 16px; height: 0; border-top: 2px solid var(--key); }
.viz-legend-key.line.dashed { border-top-style: dashed; }
.viz-legend-key.box { width: 10px; height: 10px; border-radius: 2px; background: var(--key); }
.viz-tip { position: fixed; z-index: 1000; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 8px 10px; font-size: 12px; opacity: 0; transition: opacity 0.1s; max-width: 280px; }
.viz-tip.show { opacity: 1; }
.viz-tip-title { color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.viz-tip-row { display: flex; align-items: center; gap: 6px; }
.viz-tip-row strong { font-variant-numeric: tabular-nums; }
.viz-tip-row span:last-child { color: var(--muted); }
.viz-tip-key { width: 12px; height: 0; border-top: 2px solid var(--key); flex: none; }
.viz-tip-key.dashed { border-top-style: dashed; }
.viz-table { margin-top: 8px; font-size: 12px; }
.viz-table summary { cursor: pointer; color: var(--muted); }
.viz-table summary:hover { color: var(--ink); }
.viz-table .table-wrap { max-height: 280px; overflow: auto; margin-top: 6px; border: 1px solid var(--line); border-radius: 6px; }

.barlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.barlist-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 10px; padding: 5px 6px; border-radius: 6px; font-size: 13px; }
.barlist-row:hover, .barlist-row:focus { background: var(--surface-2); outline: none; }
.barlist-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.barlist-track { height: 10px; }
.barlist-fill { height: 100%; border-radius: 0 4px 4px 0; }
.barlist-value { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 56px; text-align: right; }
.spark { display: block; }

.heat td.cell { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.heat td.s0 { color: var(--muted); }
.heat td.s1 { background: var(--seq-1); } .heat td.s2 { background: var(--seq-2); } .heat td.s3 { background: var(--seq-3); }
.heat td.s4 { background: var(--seq-4); color: #fff; } .heat td.s5 { background: var(--seq-5); color: #fff; }
.heat td.s6 { background: var(--seq-6); color: #fff; } .heat td.s7 { background: var(--seq-7); color: #fff; }
.heat td.s1, .heat td.s2, .heat td.s3 { color: #0b0b0b; }
:root[data-theme="dark"] .heat td.s1, :root[data-theme="dark"] .heat td.s2, :root[data-theme="dark"] .heat td.s3 { color: #fff; }
:root[data-theme="dark"] .heat td.s6, :root[data-theme="dark"] .heat td.s7 { color: #0b0b0b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .heat td.s1, :root:not([data-theme="light"]) .heat td.s2, :root:not([data-theme="light"]) .heat td.s3 { color: #fff; }
  :root:not([data-theme="light"]) .heat td.s6, :root:not([data-theme="light"]) .heat td.s7 { color: #0b0b0b; }
}
.heat-legend { display: flex; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
.heat-legend i { width: 22px; height: 10px; display: inline-block; }

/* ---------- alerts ---------- */
.alerts { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; }
.alerts li { display: flex; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.alerts li:last-child { border-bottom: 0; }
.alert-icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; flex: none; margin-top: 1px; }
.alert-critical .alert-icon { background: var(--critical-soft); color: var(--critical-ink); }
.alert-serious .alert-icon { background: var(--serious-soft); color: var(--serious-ink); }
.alert-warning .alert-icon { background: var(--warning-soft); color: var(--warning-ink); }
.alerts small { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }

/* ---------- profile ---------- */
.profile-head { display: flex; gap: 20px; align-items: center; padding: 20px; flex-wrap: wrap; }
.profile-head h1 { font-size: 24px; }
.profile-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 6px; color: var(--ink-2); font-size: 13px; align-items: center; }
.profile-head .actions { margin-left: auto; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 12px 14px; font: inherit; font-weight: 600; color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { font-size: 11px; background: var(--surface-3); padding: 1px 6px; border-radius: 999px; margin-left: 4px; color: var(--ink-2); }
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 20px; margin: 0; }
.dl div { min-width: 0; }
.dl dt { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
.dl dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 12px; font-weight: 700; }
.nida { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.04em; font-weight: 600; }
.stars { color: #eda100; letter-spacing: 1px; }
.stars .off { color: var(--line-strong); }
.review { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.review:last-child { border-bottom: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 18px; border-bottom: 1px solid var(--line); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }

/* ---------- project cards ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.project-card { display: flex; flex-direction: column; gap: 12px; padding: 18px; color: inherit; }
.project-card:hover { text-decoration: none; border-color: var(--brand); }
.project-card h3 { font-size: 15px; }
.project-card .code { font-size: 11.5px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.project-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.project-stats div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.project-stats strong { display: block; font-size: 14px; }
.project-stats span { font-size: 11px; color: var(--muted); }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.timebar { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.timebar div { height: 100%; background: var(--line-strong); }

/* ---------- modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 12, 20, 0.55); z-index: 100; display: grid; place-items: center; padding: 16px; animation: fade 0.12s ease-out; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; border: 1px solid var(--line); }
.modal-sm { max-width: 420px; } .modal-md { max-width: 620px; } .modal-lg { max-width: 920px; } .modal-xl { max-width: 1100px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 14px 14px; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 40px); }
.toast { display: flex; gap: 10px; align-items: center; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--good); box-shadow: var(--shadow-lg); padding: 12px 16px; border-radius: 8px; min-width: 260px; transition: opacity 0.3s, transform 0.3s; }
.toast-critical { border-left-color: var(--critical); } .toast-warning { border-left-color: var(--warning); }
.toast span:first-child { font-weight: 800; }
.toast.out { opacity: 0; transform: translateY(8px); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-icon { font-size: 28px; margin-bottom: 6px; }
.skeleton { padding: 60px; text-align: center; color: var(--muted); }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--info-soft); color: var(--info-ink); font-size: 13px; margin-bottom: 16px; }
.notice.warn { background: var(--warning-soft); color: var(--warning-ink); }
.rank { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-3); font-size: 11.5px; font-weight: 700; }
.rank-1 { background: #eda100; color: #fff; } .rank-2 { background: #9a9a9a; color: #fff; } .rank-3 { background: #b0714b; color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2-1, .grid-1-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform 0.2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .shell.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 55; }
  .icon-btn.menu-btn { display: inline-grid; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .page { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .user-chip > span:not(.avatar) { display: none; }
  .user-chip { padding: 4px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid, .form-grid.two { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-value { font-size: 19px; }
  .project-grid { grid-template-columns: minmax(0, 1fr); }
  .filters .field { flex: 1 1 140px; }
  .profile-head .actions { margin-left: 0; }
  .barlist-row { grid-template-columns: minmax(80px, 34%) 1fr auto; }
}

/* ---------- print ---------- */
@media print {
  .sidebar, .topbar, .actions, .filters, .tabs, .viz-table, .no-print, #toasts { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  .page { padding: 0; }
  [data-tab-panel] { display: block !important; }
}

/* Dense tables keep every column of wide registers visible on laptop screens */
.table.dense th, .table.dense td { padding: 9px 8px; }
.table.dense td.wrap-sm { min-width: 140px; }

/* Dialogs never grow wider than the screen: the backdrop's single column can shrink and footers wrap on phones */
.modal-backdrop { grid-template-columns: minmax(0, 1fr); justify-items: center; }
.modal { min-width: 0; }
.modal-foot { flex-wrap: wrap; }
@media (max-width: 640px) {
  .modal-backdrop { padding: 8px; }
  .modal-body { padding: 14px; }
  .modal-foot .btn { flex: 1 1 auto; }
  fieldset { padding: 12px; }
}

/* =====================================================================
   Mobile-first refinements (phones and small tablets)
   ===================================================================== */
.bottom-nav { display: none; }
.filters-toggle { display: none; }
.filters-toggle .count { background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 0 7px; font-size: 11px; margin-left: 2px; }
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }

@media (max-width: 900px) {
  /* Bottom navigation: always within thumb reach */
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(15, 20, 30, 0.06);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    min-height: 52px; border: 0; background: none; border-radius: 10px; color: var(--ink-3); font: inherit; font-size: 11px; font-weight: 600;
    text-decoration: none; cursor: pointer;
  }
  .bottom-nav .bn-icon { font-size: 19px; line-height: 1.1; }
  .bottom-nav a.active { color: var(--brand); background: var(--brand-soft); }
  .bottom-nav a:hover { text-decoration: none; }
  .main { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .sidebar { padding-bottom: env(safe-area-inset-bottom); }
  .sidebar-foot { display: none; }

  /* Main "create" action floats above the bottom bar */
  .btn.fab-mobile {
    position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 44;
    border-radius: 999px; padding: 14px 20px; font-size: 15px; min-height: 52px;
    box-shadow: 0 8px 24px rgba(28, 92, 171, 0.35), 0 2px 6px rgba(0, 0, 0, 0.15);
  }
  .page:has(.fab-mobile) { padding-bottom: 84px; } /* keep the last controls clear of the floating button */
  #toasts { bottom: calc(84px + env(safe-area-inset-bottom)); left: 16px; right: 16px; }
  .toast { min-width: 0; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .page { padding: 14px 12px 24px; }
  .topbar { padding: 8px 10px; gap: 6px; }
  .topbar-title h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-title .crumbs { display: none; }
  .page-head { margin-bottom: 12px; gap: 10px; }
  .page-head h1 { font-size: 20px; }
  .page-head p { font-size: 13.5px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn:not(.fab-mobile) { flex: 1 1 auto; padding: 9px 10px; font-size: 13.5px; }
  h2 { font-size: 15px; }

  /* Touch-friendly controls; 16px text stops iPhones zooming into inputs */
  input, select, textarea { font-size: 16px; min-height: 44px; padding: 10px 12px; }
  textarea { min-height: 88px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }
  .btn.btn-icon { min-width: 40px; min-height: 40px; }
  .check input { width: 22px; height: 22px; min-height: 0; }
  .icon-btn { width: 40px; height: 40px; }

  /* Segmented tabs / period pickers scroll sideways instead of wrapping */
  .seg { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: none; padding: 10px 14px; }
  .filters .field:has(.seg) { width: 100%; flex: 1 1 100%; }
  .tabs button { padding: 12px 12px; }

  /* Filters fold away behind a toggle */
  .filters-toggle { display: inline-flex; margin-bottom: 10px; }
  form.filters[data-collapsible] { display: none; }
  form.filters[data-collapsible].open { display: flex; }
  form.filters:not([data-collapsible]), form.filters.open { gap: 10px; }
  .filters .field, .filters .field.grow { flex: 1 1 100%; min-width: 0; }
  .card > .filters-toggle { margin: 12px 12px 0; }

  /* KPI tiles */
  .kpis { gap: 8px; }
  .kpi { padding: 12px; }
  .kpi-label { font-size: 11.5px; }
  .kpi-value { font-size: 20px; }

  /* Tables become labelled cards: every column visible, actions always reachable */
  .table.cards, .table.cards tbody, .table.cards tfoot, .table.cards tr, .table.cards td { display: block; width: 100%; }
  .table.cards thead { display: none; }
  .table.cards tr { margin: 0 0 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
  .card-body.flush .table.cards { padding: 10px 10px 0; }
  .table.cards tbody tr:hover { background: var(--surface); }
  /* label floats left, the value (one or more lines) sits right-aligned beside it */
  .table.cards td { border: 0; padding: 5px 0; display: flow-root; text-align: right; white-space: normal;
    min-width: 0 !important; max-width: none !important; }
  .table.cards td::before { content: attr(data-label); float: left; max-width: 44%; margin-right: 12px; text-align: left; font-size: 11.5px;
    font-weight: 650; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); padding-top: 2px; }
  .table.cards td[data-label=""]::before, .table.cards td:first-child::before { display: none; }
  .table.cards td:first-child { display: block; text-align: left; font-size: 15px; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
  .table.cards td[data-label=""]:not(:first-child) { display: flex; justify-content: flex-start; flex-wrap: wrap; gap: 8px; padding-top: 10px; text-align: left; }
  .table.cards td[data-label=""]:not(:first-child) > div { width: 100%; flex-direction: row !important; flex-wrap: wrap; }
  .table.cards td[data-label=""] .btn { flex: 1 1 auto; }
  .table.cards td .att { display: flex; margin-left: auto; }
  .table.cards td .badge { white-space: nowrap; }
  .table.cards td:empty { display: none; }
  .table.cards td .att { min-width: 0; max-width: 62%; }
  .table.cards td .person { min-width: 0; }
  .table.cards tfoot tr { background: var(--surface-2); }
  .table.cards tfoot td { border-top: 0; }
  .table.cards .num { text-align: right; }
  .table-wrap { overflow-x: visible; }
  .heat-wrap, .card-body.flush.table-wrap:has(.heat) { overflow-x: auto; }
  .pager { padding: 10px 12px; }
  .pager > .muted { width: 100%; text-align: center; font-size: 12.5px; }
  .pager .actions { width: 100%; }
  .pager .actions .btn { flex: 1 1 0; }

  /* Pop-up forms open as full-height sheets with the buttons always visible */
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { max-width: none !important; width: 100%; max-height: 94vh; max-height: 94dvh; border-radius: 18px 18px 0 0; border-bottom: 0; }
  .modal-head { padding: 14px 16px; position: relative; }
  .modal-head::before { content: ''; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line-strong); }
  .modal-head h2 { font-size: 16px; padding-right: 8px; }
  .modal-foot { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); border-radius: 0; }

  /* Profile header */
  .profile-head { padding: 16px; gap: 12px; }
  .profile-head h1 { font-size: 20px; }
  .avatar.lg { width: 56px; height: 56px; font-size: 20px; }
  .profile-head .actions { width: 100%; }
  .profile-head .actions .btn:not(.fab-mobile) { flex: 1 1 calc(50% - 8px); padding: 9px 8px; font-size: 13.5px; }
  .dl { grid-template-columns: 1fr 1fr; gap: 12px; }
  .dl dd { font-size: 14px; }

  .barlist-row { grid-template-columns: minmax(90px, 45%) 1fr auto; }
  .notice { font-size: 13.5px; }
  .login-card { padding: 22px; }
}

@media (max-width: 380px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .dl { grid-template-columns: 1fr; }
  .bottom-nav a, .bottom-nav button { font-size: 10px; }
}

.actions-cell { white-space: nowrap; text-align: right; }
.access-extra { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.row-menu { position: fixed; right: auto; top: 0; z-index: 200; }
.row-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.row-menu button.danger { color: var(--critical-ink); }
.table td.status-cell { white-space: normal; min-width: 120px; max-width: 200px; }
.status-cell .badge { margin: 2px 0; }
.actions-cell .btn + .btn { margin-left: 4px; }

/* ---------- offline & sync ---------- */
.sync-pill { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 12px; border-radius: 999px; border: 1px solid transparent; font: inherit; font-size: 12.5px; font-weight: 650; cursor: pointer; white-space: nowrap; }
.sync-pill[hidden] { display: none; }
.sync-pill.is-offline { background: var(--surface-2); color: var(--ink-2); border-color: var(--line-strong); }
.sync-pill.is-pending { background: var(--warning-soft); color: var(--warning-ink); }
.sync-pill.is-error { background: var(--critical-soft); color: var(--critical-ink); }
.offline-banner { padding: 10px 24px; background: var(--warning-soft); color: var(--warning-ink); font-size: 13px; border-bottom: 1px solid var(--line); }
.offline-banner[hidden] { display: none; }
.outbox-list .outbox-item { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.outbox-item.is-error { background: var(--critical-soft); }
.outbox-actions { display: flex; flex-direction: column; gap: 6px; flex: none; align-items: flex-end; }
@media (max-width: 640px) {
  .offline-banner { padding: 10px 16px; }
  .sync-pill { min-height: 36px; }
}

@media print {
  .bottom-nav, .fab-mobile, .filters-toggle, .sync-pill, .offline-banner { display: none !important; }
}
