@import url("https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400;1,6..72,500&family=IBM+Plex+Mono:wght@400;500;600&display=swap");

/* vindra design tokens — warm paper & ink, mono machine output, serif display.
   Red carries exactly one meaning: money leaking out (costs, fees, corrections).
   Keep vindra-theme.css (daisyUI apps) in sync with this palette. */
:root {
  --paper: #FCFCFB;
  --ink: #211D16;
  --ink-muted: #61594C;
  --surface-1: #FBFBF9;  /* large areas: panels, frames, side rails */
  --surface-2: #F2EFE9;  /* small fills: tab pills, chips, hovers */
  --line: #EAE4D7;
  --red: #A3331F;

  --background: var(--paper);
  --foreground: var(--ink);
  --muted: var(--surface-1);
  --muted-2: var(--surface-2);
  --muted-foreground: var(--ink-muted);
  --border: var(--line);
  --border-strong: #DCD3C0;
  --card: var(--paper);
  --ring: var(--ink);

  --primary: var(--ink);
  --accent: var(--ink);
  --secondary: var(--ink-muted);
  --danger: var(--red);

  --font-display: "Newsreader", Georgia, serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --tracking-label: 0.08em;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow-card: 0 1px 2px rgba(33, 29, 22, 0.05);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-body);
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
[x-cloak] { display: none !important; }
:focus-visible {
  outline: 2px solid rgba(33, 29, 22, 0.55);
  outline-offset: 2px;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  min-height: 100vh;
  max-width: 1500px;
  margin: 0 auto;
  transition: grid-template-columns 0.2s ease;
}
.app.collapsed { grid-template-columns: minmax(0, 1fr) 44px; }

main {
  order: 1;
  min-width: 0;
  padding: 28px 36px 56px;
}

.toc {
  order: 2;
  border-left: 1px solid var(--border);
  background: var(--surface-1);
  padding: 14px 20px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}
.toc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.toc-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.brand-mark img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.brand-name {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: var(--tracking-label);
}
.toc-toggle {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.toc-toggle:hover {
  background: var(--muted-2);
  color: var(--foreground);
  border-color: var(--border);
}
.toc-toggle svg { width: 16px; height: 16px; }
.app.collapsed .toc {
  padding: 14px 8px;
  align-items: center;
}
.app.collapsed .toc-top {
  border-bottom: 0;
  padding-bottom: 0;
  width: 100%;
  justify-content: center;
}
.app.collapsed .toc-brand { display: none; }
.app.collapsed .toc > *:not(.toc-top) { display: none; }

.toc-list { display: flex; flex-direction: column; gap: 6px; }
.toc-row {
  display: flex; align-items: center; gap: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  list-style: none;
}
.toc-row::-webkit-details-marker { display: none; }
.toc-row::marker { content: none; }
summary.toc-row:hover { background: var(--muted-2); }
.toc-chevron {
  width: 16px; height: 16px;
  display: grid; place-items: center;
  color: var(--muted-foreground);
  flex-shrink: 0;
}
.toc-chevron svg { width: 11px; height: 11px; transition: transform 0.12s; }
details[open] > .toc-row .toc-chevron svg { transform: rotate(90deg); }
.toc-group-label {
  flex: 1; min-width: 0;
  display: block;
  padding: 4px 8px 2px 4px;
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 500;
  letter-spacing: var(--tracking-label);
  color: var(--muted-foreground);
  border-radius: var(--radius-sm);
}
.toc-group-label:hover { color: var(--foreground); }
.toc-dash-link {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 6px 4px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  color: var(--foreground);
  cursor: pointer;
  transition: background 0.12s;
}
.toc-dash-link:hover { background: var(--muted-2); }
.toc-row.toc-dash.active > .toc-dash-link { background: var(--muted-2); }
.toc-group > .toc-dash { margin-left: 8px; }
.toc-pages {
  display: flex; flex-direction: column; gap: 1px;
  margin: 2px 0 6px 15px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
.toc-page {
  display: block;
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--muted-foreground);
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  transition: color 0.12s, background 0.12s;
}
.toc-page:hover { color: var(--foreground); background: var(--muted-2); }
.toc-page.active {
  color: var(--foreground);
  font-weight: 500;
  background: var(--muted-2);
}
.toc-page.active::before {
  content: ""; position: absolute;
  left: -11px; top: 6px; bottom: 6px;
  width: 2px; background: var(--foreground); border-radius: 1px;
}

.index-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 24px;
}
.index-page h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0;
  margin: 0 0 16px;
}
.index-page ul { padding-left: 18px; }
.index-page li { margin: 8px 0; }

.page-header {
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.crumbs {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted-foreground);
  margin-bottom: 10px;
  display: flex; gap: 6px; align-items: center;
}
.crumbs span.sep { opacity: 0.5; }
.page-header h1,
.page-header .prose h1 {
  font-family: var(--font-display);
  font-size: 28px; font-weight: 500;
  letter-spacing: 0;
  margin: 0 0 6px;
  line-height: 1.25;
}
.page-header .prose p {
  color: var(--foreground);
  font-size: 16px; line-height: 1.6;
  max-width: 760px; margin: 0;
}

.filters {
  display: flex; align-items: center; gap: 8px;
  padding: 10px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.filter-label {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 500;
  color: var(--muted-foreground);
  letter-spacing: var(--tracking-label);
  padding-left: 8px;
}
.filter-field { display: inline-flex; align-items: center; gap: 6px; }
.filter-field > label {
  font-size: 12px; color: var(--muted-foreground);
}
.select, .input {
  appearance: none; -webkit-appearance: none;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  height: 32px;
  padding: 0 28px 0 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--foreground);
  cursor: pointer;
  min-width: 110px;
}
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2361594C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.input { padding: 0 10px; cursor: text; }
.select:focus, .input:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(33, 29, 22, 0.1);
}
.checkbox { width: 14px; height: 14px; accent-color: var(--primary); }

.output-slot { display: contents; }
.loading-card {
  min-height: 120px;
  display: grid;
  place-items: center;
}
.loading-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Metric row — machine figures, no cards: mono on paper over a single rule. */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.kpi {
  font-family: var(--font-mono);
  display: flex; flex-direction: column; gap: 4px;
}
.kpi-label {
  font-size: 12px; font-weight: 500;
  letter-spacing: var(--tracking-label);
  color: var(--muted-foreground);
}
.kpi-value {
  font-size: 26px; font-weight: 500;
  line-height: 1.2;
  margin-top: 2px;
  font-variant-numeric: tabular-nums lining-nums;
}
.kpi-delta {
  font-size: 11px; letter-spacing: 0.06em;
  color: var(--muted-foreground); margin-top: 2px;
  font-variant-numeric: tabular-nums lining-nums;
}
.kpi-value.leak { color: var(--red); }
.kpi-delta.up { color: var(--foreground); }
.kpi-delta.down { color: var(--red); }

.tabs-block { margin-bottom: 24px; }
.tabs-shadcn {
  display: inline-flex;
  background: var(--muted-2);
  padding: 3px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  gap: 2px;
}
.tabs-shadcn .tab {
  padding: 5px 14px;
  font-size: 13px; font-weight: 500;
  border-radius: 5px;
  background: transparent;
  border: 0;
  color: var(--muted-foreground);
  cursor: pointer;
}
.tabs-shadcn .tab:hover { color: var(--foreground); }
.tabs-shadcn .tab-active {
  background: var(--background);
  color: var(--foreground);
  box-shadow: 0 1px 2px rgba(33, 29, 22, 0.06), 0 0 0 1px rgba(33, 29, 22, 0.06);
}

/* Text following a standalone figure/table needs air; sibling margins
   collapse, so grids (margin-bottom 24px) don't double up. */
.section-header { margin: 28px 0 12px; }
.section-header:first-child { margin-top: 0; }
main > .output-slot > .card,
[role="tabpanel"] > .output-slot > .card { margin-bottom: 28px; }
.prose {
  max-width: 760px;
  color: var(--foreground);
  font-size: 16px;
  line-height: 1.65;
}
.prose :where(h1) {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: 0;
  margin: 0 0 10px;
  line-height: 1.25;
}
.prose :where(h2) {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 500;
  letter-spacing: 0;
  margin: 0 0 6px;
  line-height: 1.3;
}
.prose :where(p, ul, ol, blockquote, pre) {
  margin: 0 0 12px;
}
.prose > :last-child { margin-bottom: 0; }
.prose :where(h3) {
  font-family: var(--font-display);
  font-size: 17.5px;
  font-weight: 500;
  letter-spacing: 0;
  margin: 18px 0 6px;
  line-height: 1.35;
}
.prose :where(h4) {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  margin: 16px 0 4px;
  color: var(--muted-foreground);
  letter-spacing: var(--tracking-label);
}
.prose :where(ul, ol) { padding-left: 20px; }
.prose :where(li) { margin: 4px 0; }
.prose li::marker { color: var(--muted-foreground); }
.prose :where(blockquote) {
  margin: 12px 0;
  padding: 4px 0 4px 14px;
  border-left: 2px solid var(--border-strong);
  color: var(--muted-foreground);
  font-style: italic;
}
.prose :where(a) {
  color: var(--foreground);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 0.12s;
}
.prose :where(a:hover) { text-decoration-color: var(--foreground); }
.prose :where(:not(pre) > code) {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--muted-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--foreground);
}
.prose :where(pre) {
  background: var(--muted-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.55;
  margin: 12px 0;
}
.prose :where(pre code) {
  font-family: var(--font-mono);
  background: transparent;
  border: 0;
  padding: 0;
}
.prose :where(strong) { font-weight: 600; }
.prose :where(em) { font-style: italic; }
.prose :where(hr) {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.grid-1,
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.grid-1 { grid-template-columns: 1fr; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 24px; }
.grid-6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 24px; }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card-body { padding: 4px 8px 14px; }
.chart-card .card-body { min-height: 320px; }
.error-message { color: var(--danger); text-align: center; padding: 18px; }

/* Tables — machine output: mono, tabular lining figures. */
.table-card { padding: 0; }
.table-wrap { overflow-x: auto; max-height: 440px; overflow-y: auto; }
.table-wrap.sticky { max-height: 440px; }
table {
  width: 100%; border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums lining-nums;
}
thead th {
  text-align: left; padding: 10px 14px;
  font-weight: 500; color: var(--foreground);
  font-size: 11px; letter-spacing: var(--tracking-label);
  background: var(--background);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; white-space: nowrap;
}
tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table:not(.compact) tbody td { padding: 12px 14px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--muted-2); }
.num { text-align: right; }
.table-sort {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-start;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0;
  text-transform: inherit;
  letter-spacing: inherit;
  font: inherit;
}
.table-sort.num { justify-content: flex-end; }
.empty-row {
  padding: 24px 18px;
  text-align: center;
  color: var(--muted-foreground);
}
.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.table-pager {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pager-button {
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--background);
  color: var(--foreground);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 12px;
}
.pager-button:hover:not(:disabled) { background: var(--muted-2); }
.pager-button:disabled { color: var(--muted-foreground); cursor: not-allowed; opacity: 0.6; }
.page-count,
.table-status,
.table-clipped { font-variant-numeric: tabular-nums lining-nums; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .toc { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2,
  .grid-3,
  .grid-4,
  .grid-5,
  .grid-6 { grid-template-columns: 1fr; }
  main { padding: 20px; }
}
