/* InsuBot dashboard. Gold = chrome, clinical colours = data (same rule as the PWA). */
:root {
  --bg: #120d07;
  --panel: #1b150d;
  --panel-2: #221a10;
  --line: rgba(243, 195, 74, 0.14);
  --line-soft: rgba(255, 255, 255, 0.06);
  --text: #fbf3e9;
  --text-mid: #c9b190;
  --text-muted: #9a8569;
  --gold: #f3c34a;
  --gold-deep: #e6a82e;
  --on-gold: #2a1c06;
  --in-range: #34c886;
  --low: #f87171;
  --very-low: #b91c1c;
  --high: #fb923c;
  --very-high: #c2410c;
  --tight: #6ee7b7;
  --band-outer: rgba(243, 195, 74, 0.16);
  --band-inner: rgba(243, 195, 74, 0.38);
  --median: #f3c34a;
  --target: rgba(52, 200, 134, 0.10);
  --flag: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6efe1;
  --panel: #fffdf8;
  --panel-2: #fbf4e6;
  --line: rgba(160, 120, 40, 0.22);
  --line-soft: rgba(80, 60, 20, 0.08);
  --text: #2a1c06;
  --text-mid: #6b5636;
  --text-muted: #8c7653;
  --gold: #c98a12;
  --gold-deep: #a86f05;
  --on-gold: #fffaf0;
  --band-outer: rgba(201, 138, 18, 0.16);
  --band-inner: rgba(201, 138, 18, 0.36);
  --median: #a86f05;
  --target: rgba(52, 200, 134, 0.12);
  --flag: rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 2px rgba(80, 60, 20, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6efe1; --panel: #fffdf8; --panel-2: #fbf4e6; --line: rgba(160, 120, 40, 0.22);
    --line-soft: rgba(80, 60, 20, 0.08); --text: #2a1c06; --text-mid: #6b5636; --text-muted: #8c7653;
    --gold: #c98a12; --gold-deep: #a86f05; --on-gold: #fffaf0; --band-outer: rgba(201, 138, 18, 0.16);
    --band-inner: rgba(201, 138, 18, 0.36); --median: #a86f05; --target: rgba(52, 200, 134, 0.12);
    --flag: rgba(0, 0, 0, 0.05); --shadow: 0 1px 2px rgba(80, 60, 20, 0.08); color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
a { color: var(--gold); }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-mid); font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* --- header --- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  padding: 10px 24px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand .drop { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(150deg, #fbdf9c, #e6a82e); display: grid; place-items: center; }
.brand .drop::after { content: ""; width: 8px; height: 11px; background: var(--on-gold); border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; transform: translateY(1px); }
.brand small { color: var(--text-muted); font-weight: 500; }
.period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 10px; cursor: pointer; color: var(--text-mid); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--gold); color: var(--on-gold); font-weight: 650; }
input[type="date"], select, input[type="search"] {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; min-height: 30px;
}
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--text-mid); cursor: pointer; user-select: none; }
.spacer { flex: 1; }
.iconbtn { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; color: var(--text-mid); }
.iconbtn:hover, .seg button:hover { color: var(--text); }

nav.tabs { display: flex; gap: 2px; padding: 0 24px; border-bottom: 1px solid var(--line); overflow-x: auto; }
nav.tabs button {
  background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--text-muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
nav.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--gold); font-weight: 600; }

main { padding: 20px 24px 60px; max-width: 1600px; margin: 0 auto; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr); }
@media (max-width: 1000px) { .g2, .g3, .g-main { grid-template-columns: 1fr; } main, .top, nav.tabs { padding-left: 16px; padding-right: 16px; } }

.card { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card > header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card > header .hint { color: var(--text-muted); font-size: 12px; }
.chart { width: 100%; height: 320px; }
.chart.tall { height: 420px; }
.chart.short { height: 220px; }

/* --- key figures --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px 12px; }
.kpi .label { color: var(--text-muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 650; line-height: 1.2; margin-top: 2px; }
.kpi .value small { font-size: 13px; color: var(--text-mid); font-weight: 500; }
.kpi .delta { font-size: 12px; color: var(--text-muted); }
.kpi .delta.good { color: var(--in-range); }
.kpi .delta.bad { color: var(--low); }
.kpi.k-tir .value { color: var(--in-range); }
.kpi.k-tbr .value { color: var(--low); }
.kpi.k-tar .value { color: var(--high); }
.kpi .sub { font-size: 12px; color: var(--text-muted); }
.warn { color: var(--high); }

.stack { display: flex; flex-direction: column; gap: 6px; }
.tirbar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; }
.tirbar div { min-width: 0; }
.legend { display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 8px; align-items: center; font-size: 13px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* --- daily small multiples --- */
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day { background: var(--panel-2); border-radius: 8px; padding: 6px; cursor: pointer; border: 1px solid transparent; }
.day:hover { border-color: var(--line); }
.day .dh { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }
.day .dh b { color: var(--text-mid); font-weight: 600; }
.day svg { width: 100%; height: 54px; display: block; }
.day.flagged { box-shadow: inset 0 0 0 1px var(--flag); }
.day .fl { font-size: 10px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) { .days { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* --- tables --- */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--panel); }
td.r, th.r { text-align: right; }
tr.dim td { color: var(--text-muted); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.pill { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: var(--flag); color: var(--text-mid); margin: 1px 2px 1px 0; white-space: nowrap; }
.pill.low { background: color-mix(in srgb, var(--low) 20%, transparent); color: var(--low); }
.pill.ok { background: color-mix(in srgb, var(--in-range) 18%, transparent); color: var(--in-range); }
.pill.high { background: color-mix(in srgb, var(--high) 18%, transparent); color: var(--high); }
.pill.gold { background: color-mix(in srgb, var(--gold) 20%, transparent); color: var(--gold); }
.scroll { max-height: 520px; overflow: auto; }

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.empty { color: var(--text-muted); padding: 24px 0; text-align: center; }
.loading { opacity: 0.55; transition: opacity 0.2s; }
.note { background: var(--panel-2); border-left: 3px solid var(--gold); padding: 8px 12px; border-radius: 6px; white-space: pre-wrap; font-size: 13px; max-height: 260px; overflow: auto; }
.explain { color: var(--text-muted); font-size: 12px; margin-top: 8px; }
.err { color: var(--low); padding: 12px 0; }

/* --- login --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { font-size: 22px; margin: 14px 0 6px; }
.login p { color: var(--text-mid); margin: 0 0 18px; }
.login label { display: block; font-weight: 600; margin: 12px 0 6px; }
.login input[type="tel"], .login input[type="text"] { width: 100%; font-size: 20px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); letter-spacing: 0.04em; }
.login .check { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; color: var(--text-mid); font-weight: 400; }
.btn { display: inline-block; width: 100%; margin-top: 16px; padding: 11px; border: 0; border-radius: 10px; background: linear-gradient(150deg, #fbdf9c, #e6a82e); color: #2a1c06; font-weight: 700; cursor: pointer; font-size: 15px; }
.btn[disabled] { opacity: 0.6; cursor: default; }
.linkbtn { background: none; border: 0; color: var(--gold); cursor: pointer; padding: 6px 0; margin-top: 8px; }
.login .err { padding: 8px 0 0; }

/* --- report / print --- */
.report { max-width: 1050px; margin: 0 auto; padding: 24px; }
.report .rhead { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--text); padding-bottom: 8px; margin-bottom: 16px; }
.report section { margin-bottom: 22px; break-inside: avoid; }
.report .chart { height: 300px; }
.report .printbar { display: flex; gap: 10px; margin-bottom: 16px; }
@media print {
  @page { size: A4; margin: 12mm; }
  :root, :root[data-theme] { --bg: #fff; --panel: #fff; --panel-2: #f5f5f5; --text: #111; --text-mid: #333; --text-muted: #555; --line: #ccc; --line-soft: #ddd; --shadow: none; color-scheme: light; }
  body { font-size: 11px; }
  .printbar, .top, nav.tabs { display: none !important; }
  .card { border: 1px solid #ccc; box-shadow: none; }
  .report { padding: 0; }
  .report .chart { height: 260px; }
}
