/* Dark-only theme, violet-led.
 *
 * Series hexes are the validated dark categorical steps re-ordered to lead with
 * violet (slot order violet → orange → aqua → yellow). Against this surface
 * (#101016) the set passes the lightness band, chroma floor, adjacent CVD
 * separation (worst ΔE 8.4 protan), the normal-vision floor (19.8) and 3:1
 * contrast; the three colours that ever share a chart (violet/aqua/orange) also
 * pass all-pairs. The bucket ramp is one violet hue, monotone light→dark, its
 * dark end clearing 2:1 on the surface. Don't substitute hexes without re-running
 * the palette validator. */

:root {
  color-scheme: dark;

  --plane:        #08080b;
  --surface:      #101016;
  --surface-2:    #17171f;
  --surface-3:    #20202b;
  --border:       rgba(255, 255, 255, 0.07);
  --border-strong:rgba(255, 255, 255, 0.13);

  --ink:          #f5f5f7;
  --ink-2:        #a9a9b8;
  --ink-muted:    #6f6f80;

  --grid:         #23232d;
  --axis:         #2e2e3a;

  /* Brand violet: --brand carries white button text (4.9:1); --series-1 is the
     data step, chosen for the chart surface rather than for text on top of it. */
  --brand:        #6d5fd8;
  --brand-hover:  #7d70e2;
  --brand-soft:   rgba(144, 133, 233, 0.14);

  --series-1:     #9085e9;
  --series-2:     #d95926;
  --series-3:     #199e70;
  --series-4:     #c98500;

  --good:         #0ca30c;
  --warning:      #fab219;
  --serious:      #ec835a;
  --critical:     #d03b3b;

  --radius:       18px;
  --radius-sm:    12px;
  --rail-w:       74px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.icon { flex: none; }

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

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

.rail {
  position: fixed; inset: 0 auto 0 0; z-index: 50;
  width: var(--rail-w);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 0 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.rail-logo {
  display: grid; place-items: center;
  width: 42px; height: 42px; margin-bottom: 12px;
  border-radius: 13px; flex: none;
  background: linear-gradient(150deg, #ffffff, #d9d6f5);
  color: #14121f; font-weight: 800; font-size: 17px; letter-spacing: -0.04em;
}
.rail-logo:hover { text-decoration: none; }

.rail-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--ink-muted); margin-bottom: 4px;
}

.rail-nav { display: flex; flex-direction: column; gap: 6px; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }

.rail-btn {
  position: relative;
  display: grid; place-items: center;
  width: 42px; height: 42px; border-radius: 14px;
  background: transparent; border: 1px solid transparent;
  color: var(--ink-muted); cursor: pointer;
}
.rail-btn:hover { background: var(--surface-2); color: var(--ink-2); text-decoration: none; }
.rail-btn.active {
  background: linear-gradient(160deg, #7b6ee2, #574ab0);
  border-color: rgba(255, 255, 255, 0.16);
  color: #fff;
  box-shadow: 0 6px 18px rgba(87, 74, 176, 0.45);
}
.rail-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Tooltip on the icon-only rail — the glyph alone doesn't name the destination. */
.rail-btn::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  padding: 5px 9px; border-radius: 8px; white-space: nowrap;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  color: var(--ink); font-size: 12px;
  opacity: 0; pointer-events: none; transition: opacity 0.12s;
}
.rail-btn:hover::after, .rail-btn:focus-visible::after { opacity: 1; }

.main { flex: 1; min-width: 0; margin-left: var(--rail-w); }

/* ------------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px;
  background: rgba(8, 8, 11, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.acct-chip {
  display: flex; align-items: center; gap: 8px;
  font-weight: 620; letter-spacing: -0.01em; min-width: 0;
  color: var(--ink);
}
.acct-chip small {
  display: block; font-weight: 400; font-size: 11px; color: var(--ink-muted);
  letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.search {
  flex: 1; max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 9px;
  padding: 0 14px; height: 40px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; color: var(--ink-muted);
}
.search:focus-within { border-color: var(--brand); color: var(--ink-2); }
.search input {
  flex: 1; background: none; border: none; padding: 0; color: var(--ink);
  font: inherit; font-size: 13px; min-width: 0;
}
.search input:focus { outline: none; }

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 12px 5px 5px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  min-width: 0;
}
.avatar {
  display: grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(150deg, #7b6ee2, #574ab0);
  color: #fff; font-size: 12px; font-weight: 650; letter-spacing: 0.02em;
}
.user-chip .who { min-width: 0; line-height: 1.25; }
.user-chip .who b { display: block; font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
.user-chip .who small { font-size: 11px; color: var(--ink-muted); }

.container { max-width: 1560px; margin: 0 auto; padding: 22px; }

/* --------------------------------------------------------------- page head */

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 27px; font-weight: 680; letter-spacing: -0.025em; }
.page-head p { margin: 3px 0 0; font-size: 13px; color: var(--ink-muted); }
.page-head-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--ink-2); font-size: 13px; white-space: nowrap;
}

/* Hero figure — the one number the page is about. */
.hero {
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 18px;
  margin-bottom: 22px;
}
.hero-value {
  font-size: 54px; font-weight: 680; letter-spacing: -0.035em; line-height: 1;
}
.hero-value .unit { font-size: 26px; color: var(--ink-muted); letter-spacing: -0.02em; }
.hero-sub { font-size: 13px; color: var(--ink-muted); margin-top: 9px; }
/* Emphasis, not status — an attendance rate is a level, not a good/bad delta, so
   it must not borrow the reserved success green. */
.hero-sub .emph { color: var(--ink); font-weight: 620; }
.hero-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }

/* ------------------------------------------------------------------ filters */

.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px;
  padding: 16px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted); }

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent;
}
input::placeholder { color: var(--ink-muted); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 14px; font: inherit; font-size: 13px; font-weight: 520;
  cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: var(--critical); border-color: rgba(208, 59, 59, 0.4); background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 10px; }
.btn-icon { padding: 0; width: 40px; height: 40px; justify-content: center; }

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

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); gap: 14px; margin-bottom: 20px; }

.tile {
  position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.tile-icon {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 11px; margin-bottom: 12px;
  background: var(--brand-soft); color: var(--series-1);
}
.tile-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted); margin-bottom: 5px; }
.tile-value { font-size: 28px; font-weight: 660; letter-spacing: -0.025em; line-height: 1.15; }
.tile-sub { font-size: 12px; color: var(--ink-2); margin-top: 4px; }

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

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.card-title { font-size: 15px; font-weight: 620; letter-spacing: -0.01em; }
.card-sub { font-size: 12px; color: var(--ink-muted); }

.chart-grid { display: grid; grid-template-columns: 1.7fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .chart-grid { grid-template-columns: 1fr; } }

/* The grid stretches both cards to the taller one; centre the shorter chart in
   its card instead of leaving it stranded against the header. */
.chart-grid > .card { display: flex; flex-direction: column; }
.chart-grid > .card > div:not(.card-head):not(.legend) { flex: 1; display: flex; flex-direction: column; justify-content: center; }

/* Legend — always present for >= 2 series so identity is never colour-alone. */
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* Donut + its direct labels. The label column is the legend, so the ramp's dark
   end never has to carry identity on contrast alone. */
.pie-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 4px 0; }
.pie-svg { width: 168px; height: 168px; flex: none; }
/* Capped, so on a wide card the values stay beside their labels instead of
   drifting to the far edge of the row. */
.pie-legend { flex: 1 1 190px; min-width: 0; max-width: 340px; display: flex; flex-direction: column; gap: 2px; }
.pie-row {
  display: grid; grid-template-columns: 10px 1fr auto auto; align-items: center;
  gap: 9px; padding: 5px 7px; border-radius: 7px; font-size: 12px;
  color: var(--ink-2); cursor: default; transition: background .12s;
}
.pie-row.on { background: rgba(255, 255, 255, .05); }
.pie-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pie-val { color: var(--ink); font-variant-numeric: tabular-nums; }
.pie-pct { color: var(--ink-muted); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
@media (max-width: 1000px) { .pie-wrap { justify-content: center; } }

/* -------------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  position: sticky; top: 0;
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted);
  padding: 12px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
thead th .arrow { opacity: 0.5; font-size: 9px; }

tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: rgba(255, 255, 255, 0.028); }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.topic-cell { max-width: 460px; }
.muted { color: var(--ink-muted); }
.nowrap { white-space: nowrap; }

/* Percentage meter inside a table cell. */
.meter { display: flex; align-items: center; gap: 9px; min-width: 128px; }
.meter-track { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 3px; background: var(--series-1); }
.meter-val { font-variant-numeric: tabular-nums; font-size: 12px; min-width: 44px; text-align: right; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 550; border: 1px solid transparent; white-space: nowrap;
}
.badge-good     { color: var(--good);     border-color: rgba(12, 163, 12, 0.4);  background: rgba(12, 163, 12, 0.11); }
.badge-warning  { color: var(--warning);  border-color: rgba(250, 178, 25, 0.4); background: rgba(250, 178, 25, 0.11); }
.badge-serious  { color: var(--serious);  border-color: rgba(236, 131, 90, 0.4); background: rgba(236, 131, 90, 0.11); }
.badge-critical { color: var(--critical); border-color: rgba(208, 59, 59, 0.4);  background: rgba(208, 59, 59, 0.11); }
.badge-neutral  { color: var(--ink-2);    border-color: var(--border-strong);    background: var(--surface-2); }

/* --------------------------------------------------------------- pagination */

.pager { display: flex; align-items: center; gap: 10px; padding: 14px 2px; font-size: 12px; color: var(--ink-2); }
.pager-spacer { flex: 1; }

/* --------------------------------------------------------------------- tabs */

/* Segmented pill group, matching the topbar/search radius language. */
.tabs {
  display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; max-width: 100%; overflow-x: auto;
}
.tab {
  padding: 8px 16px; font-size: 13px; font-weight: 540; color: var(--ink-muted);
  background: none; border: none; border-radius: 999px;
  cursor: pointer; white-space: nowrap; font-family: inherit;
}
.tab:hover { color: var(--ink-2); }
.tab.active { color: #fff; background: var(--brand); }
.tab .count { font-size: 11px; opacity: 0.75; margin-left: 6px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- chat & Q&A */

.msg-list { display: flex; flex-direction: column; gap: 2px; }
.msg {
  display: grid; grid-template-columns: 78px 190px 1fr; gap: 12px;
  padding: 10px 12px; border-radius: 10px; font-size: 13px;
}
.msg:nth-child(odd) { background: rgba(255, 255, 255, 0.022); }
.msg-time { color: var(--ink-muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.msg-from { color: var(--ink-2); font-weight: 550; overflow-wrap: anywhere; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 720px) { .msg { grid-template-columns: 1fr; gap: 3px; } }

.qa-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.qa-item:last-child { border-bottom: none; }
.qa-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-bottom: 6px; font-size: 12px; color: var(--ink-muted); }
.qa-q { font-size: 14px; margin-bottom: 7px; overflow-wrap: anywhere; }
.qa-a {
  font-size: 13px; color: var(--ink-2); padding: 9px 13px;
  background: var(--surface-2); border-left: 2px solid var(--series-3);
  border-radius: 0 8px 8px 0; margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------- states */

.empty { padding: 44px 20px; text-align: center; color: var(--ink-muted); font-size: 13px; }
.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--surface-3); border-top-color: var(--series-1);
  animation: spin 0.7s linear infinite; display: inline-block; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.notice {
  padding: 13px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px;
  border: 1px solid rgba(250, 178, 25, 0.35); background: rgba(250, 178, 25, 0.08); color: #f3d79b;
}
.notice strong { color: var(--warning); }
.error-text { color: var(--critical); font-size: 13px; }

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

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(120% 90% at 50% -10%, rgba(109, 95, 216, 0.22), transparent 60%), var(--plane); }
.login-card {
  width: 100%; max-width: 390px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 22px; padding: 32px;
}
.login-card .rail-logo { margin-bottom: 18px; }
.login-card h1 { font-size: 20px; margin: 0 0 5px; letter-spacing: -0.02em; }
.login-card p.sub { color: var(--ink-muted); font-size: 13px; margin: 0 0 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card input { width: 100%; padding: 11px 13px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; }

/* ------------------------------------------------------------------ tooltip */

.chart-tooltip {
  position: fixed; z-index: 100; pointer-events: none;
  background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 10px 12px; font-size: 12px; color: var(--ink);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.7); max-width: 300px;
  opacity: 0; transition: opacity 0.1s;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-title { font-weight: 600; margin-bottom: 6px; line-height: 1.35; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.chart-tooltip .tt-row b { color: var(--ink); font-variant-numeric: tabular-nums; margin-left: auto; }

/* ------------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7);
  display: grid; place-items: center; z-index: 200; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 20px; padding: 24px; width: 100%; max-width: 450px;
}
.modal h2 { margin: 0 0 16px; font-size: 17px; letter-spacing: -0.01em; }
.modal .field { margin-bottom: 13px; }
.modal input, .modal select { width: 100%; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 20px; }

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

/* ------------------------------------------------------------------ compact */

@media (max-width: 900px) {
  .search { display: none; }
  .hero-value { font-size: 42px; }
}

@media (max-width: 640px) {
  :root { --rail-w: 58px; }
  .rail { padding: 10px 0 12px; }
  .rail-logo, .rail-btn { width: 38px; height: 38px; }
  .rail-label { display: none; }
  .topbar { gap: 10px; padding: 10px 12px; }
  .acct-chip small { display: none; }
  .user-chip .who { display: none; }
  .container { padding: 14px 12px; }
  .page-head { flex-wrap: wrap; }
  .page-head h1 { font-size: 22px; }
}
