/* Layout: header band, a row of sheet cards (one per Solar sheet), then the
   selected sheet's tabs, KPI strip, bar chart and row table. */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1d2230;
  --muted: #5d6475;
  --line: #e3e1da;
  --sun: #d9821f;
  --sun-soft: #fbecd6;
  --cell: #2a6f97;
  --bad: #b3261e;
  --ok: #2e7d4f;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --surface: #1a1f29; --ink: #e8eaf0; --muted: #9aa2b4; --line: #2a3140;
    --sun: #f2a33a; --sun-soft: #3a2c17; --cell: #6fb3d9; --bad: #ff8a80; --ok: #7fd3a0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151c; --surface: #1a1f29; --ink: #e8eaf0; --muted: #9aa2b4; --line: #2a3140;
  --sun: #f2a33a; --sun-soft: #3a2c17; --cell: #6fb3d9; --bad: #ff8a80; --ok: #7fd3a0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 20px; font-weight: 700; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
a { color: var(--cell); }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.top {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 16px max(16px, env(safe-area-inset-left, 0px)) 16px max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: center; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.who { color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--sun);
  background: var(--sun); color: #1b1206; font: 600 13px var(--font); text-decoration: none; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn:focus-visible, select:focus-visible, input:focus-visible, .sheet:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--sun); outline-offset: 2px;
}
.btn[disabled] { opacity: .6; cursor: progress; }

main {
  max-width: 1280px; margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px));
  display: grid; gap: 20px;
}

.sheets { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.sheet {
  text-align: left; padding: 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; display: grid; gap: 6px;
}
.sheet[aria-pressed="true"] { border-color: var(--sun); box-shadow: inset 0 0 0 1px var(--sun); background: var(--sun-soft); }
.sheet .name { font-weight: 700; font-size: 15px; }
.sheet .meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.sheet .err { color: var(--bad); font-size: 12px; }

.detail { display: grid; gap: 16px; min-width: 0; }
.detail-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; justify-content: space-between; }
.open { font-size: 13px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: 500 13px var(--font); cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi { padding: 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.kpi .label { color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.kpi .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; overflow-wrap: anywhere; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
select, input[type="search"] {
  font: 13px var(--font); color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; max-width: 100%;
}
input[type="search"] { min-width: 0; width: 240px; }

.chart { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(80px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bar .track { display: block; height: 14px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--sun); border-radius: 4px; min-width: 2px; }
.bar .v { font-variant-numeric: tabular-nums; font-weight: 600; }

.table-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
th { position: sticky; top: 0; background: var(--surface); font-weight: 600; cursor: pointer; user-select: none; }
th[aria-sort="ascending"]::after { content: " ▲"; color: var(--sun); }
th[aria-sort="descending"]::after { content: " ▼"; color: var(--sun); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.blank { color: var(--muted); font-style: italic; }
tbody tr:hover td { background: var(--sun-soft); }
.note { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 12px; padding: 24px; }
.empty h2 { margin-bottom: 8px; }
.empty code { font-family: var(--mono); background: var(--bg); padding: 1px 5px; border-radius: 4px; }

body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; display: grid; gap: 12px; justify-items: start;
}
.btn.wide { width: 100%; padding: 12px; font-size: 14px; }
.msg { min-height: 1.5em; margin: 0; color: var(--muted); font-size: 13px; }
.msg.bad { color: var(--bad); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
