:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  --accent-ink: #184f95;
  --warn-bg: #fff6e0;
  --warn-ink: #7a5300;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
}

button, select { font: inherit; color: inherit; }

.muted { color: var(--muted); }

/* ---- Header & tabs ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab {
  padding: 16px 12px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ---- Page ---- */
.page { max-width: 1280px; margin: 0 auto; padding: 24px; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; font-size: 22px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  max-width: 280px;
}
select:disabled { opacity: 0.5; }
.reset {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-ink);
  cursor: pointer;
}
.reset:hover:not(:disabled) { background: var(--accent-soft); }
.reset:disabled { color: var(--muted); cursor: default; opacity: 0.6; }

/* ---- Grid & cards ---- */
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.charts { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 0;
}
.card h2 { margin: 0; font-size: 14px; font-weight: 600; }
.card .sub { margin: 2px 0 12px; color: var(--muted); font-size: 12px; }

.kpi { text-align: center; padding: 22px 18px; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }
.kpi .label { margin-top: 4px; color: var(--ink-2); }
.kpi .note { margin-top: 6px; color: var(--muted); font-size: 12px; }

.notice {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  text-align: center;
  color: var(--muted);
  padding: 16px;
}
.empty strong { display: block; color: var(--ink); font-size: 20px; margin-bottom: 4px; }

/* ---- Column chart ---- */
.colchart { width: 100%; height: auto; display: block; }
.colchart .gridline { stroke: var(--grid); stroke-width: 1; }
.colchart .baseline { stroke: var(--axis); stroke-width: 1; }
.colchart .tick, .colchart .xlabel { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.colchart .vlabel { fill: var(--ink-2); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.colchart .bar { fill: var(--accent); }
.colchart .bar.dim { opacity: 0.35; }
.colchart .hit { fill: transparent; cursor: default; }

/* ---- Horizontal bar list ---- */
.hbars { display: grid; gap: 4px; }
.hbar {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) 72px;
  gap: 10px;
  align-items: center;
  padding: 2px 4px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
  width: 100%;
}
button.hbar { cursor: pointer; }
button.hbar:hover { background: var(--surface-2); }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); font-size: 12px; }
.hbar .track { display: block; height: 12px; }
.hbar .fill { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .fill.others { background: var(--axis); }
.hbar .val { text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ---- Table ---- */
.table-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 600;
}
.table-wrap { max-height: 560px; overflow: auto; border-top: 1px solid var(--grid); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
tbody tr.org-row:hover { background: var(--surface-2); }
tbody tr.org-row.clickable { cursor: pointer; }
tr.selected { background: var(--surface-2); }
td .dept { display: block; color: var(--muted); font-size: 12px; }
td.pseudo .org-name { font-style: italic; color: var(--ink-2); }
tfoot td { font-weight: 600; border-bottom: 0; }
.chev { display: inline-block; width: 14px; color: var(--muted); transition: transform 0.15s; }
tr.open .chev { transform: rotate(90deg); }
.drill {
  margin-left: 8px;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-ink);
  font-size: 11px;
  cursor: pointer;
}
.drill:hover { background: var(--accent-soft); }
tr.breakdown td { background: var(--surface-2); padding: 10px 16px 14px 34px; }
tr.breakdown .hbar { grid-template-columns: minmax(0, 300px) minmax(0, 1fr) 72px; }

/* ---- Tooltip ---- */
.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  max-width: 320px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--page);
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.tip b { font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .app-header { flex-direction: column; align-items: stretch; gap: 0; padding: 8px 16px 0; }
  .page { padding: 16px; }
  .hbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 64px; }
}
