:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --ink: #23201c;
  --muted: #6f685f;
  --line: #ddd6cb;
  --accent: #7a3b1e;
  --accent-ink: #ffffff;
  --star: #c98a12;
  --danger: #a32222;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1917;
    --panel: #26231f;
    --ink: #efe9e0;
    --muted: #a59c90;
    --line: #3b362f;
    --accent: #d98a5f;
    --accent-ink: #1b1917;
    --star: #e6b043;
    --danger: #e07070;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, "Segoe UI", sans-serif;
}
h1 { font: 600 1.6rem Georgia, serif; margin: 0; }
h2 { font: 600 1.25rem Georgia, serif; margin: 0 0 12px; }
.muted { color: var(--muted); margin: 2px 0; font-size: 0.9rem; }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0; font-size: 0.9rem; }

button, input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#app { max-width: 1100px; margin: 0 auto; padding: 16px; }
.top { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-end; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 8px; }
.controls input[type=search] { flex: 1 1 260px; min-width: 0; }
.toggle { display: flex; }
.toggle button { border-radius: 0; }
.toggle button:first-child { border-radius: 6px 0 0 6px; }
.toggle button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.toggle button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
td.title { font-weight: 600; }
.stars { color: var(--star); white-space: nowrap; letter-spacing: 1px; }
.tag { font-size: 0.75rem; border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; color: var(--muted); white-space: nowrap; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; }
.card { background: none; border: 0; padding: 0; text-align: left; }
.cover {
  aspect-ratio: 2 / 3; width: 100%; border-radius: 4px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.cover span { padding: 10px; font: 600 0.85rem Georgia, serif; text-align: center; color: var(--muted); }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card b { display: block; margin-top: 6px; font-size: 0.85rem; line-height: 1.25; }
.card small { color: var(--muted); }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }

#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 8px; }
.login-card h1 { margin-bottom: 12px; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); padding: 20px; width: min(640px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); min-width: 0; }
.grid .wide { grid-column: 1 / -1; }
.grid input, .grid select, .grid textarea { width: 100%; background: var(--bg); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.dialog-actions { display: flex; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }

/* ---------- dashboard ---------- */
:root { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s-other: #b9b3a8; --grid: #ebe6dd; }
@media (prefers-color-scheme: dark) {
  :root { --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s-other: #5d574e; --grid: #353029; }
}
#dashboard { margin-top: 16px; }
#dashboard h2 { margin-bottom: 2px; }
#dashboard h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 0 4px; }
.figure { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.note { margin-top: 10px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; }
.tile-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.tile-value { font-size: 2rem; font-weight: 600; line-height: 1.2; }
.tile-sub { font-size: 0.82rem; color: var(--muted); }

.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.card-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; min-width: 0; }
.card-panel.wide { grid-column: 1 / -1; }
.card-panel > .muted { margin-bottom: 14px; }

.donut-wrap { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; }
.donut { width: 190px; height: 190px; flex: none; margin: 0 auto; }
.arc { stroke: var(--panel); stroke-width: 2; }
.arc:hover { opacity: 0.8; }
.donut-num { font-size: 30px; font-weight: 600; fill: var(--ink); }
.donut-cap { font-size: 11px; fill: var(--muted); }
.legend { flex: 1 1 200px; display: flex; flex-direction: column; min-width: 0; }
.legend-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 3.2em; gap: 8px; align-items: center; padding: 5px 6px; border: 0; background: none; border-radius: 4px; text-align: left; font-size: 0.9rem; }
.legend-row i { width: 12px; height: 12px; border-radius: 3px; }
.legend-row .name, .hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .pct { color: var(--muted); }
button.legend-row:hover, button.hbar:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.hbars { display: flex; flex-direction: column; }
.hbar { display: grid; grid-template-columns: minmax(90px, 36%) 1fr 2.6em; gap: 10px; align-items: center; padding: 4px 6px; border: 0; background: none; border-radius: 4px; text-align: left; font-size: 0.9rem; }
.hbar .track { height: 14px; display: block; }
.hbar .bar { display: block; height: 100%; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }

.cols { padding-left: 26px; }
.cols .plot { position: relative; height: 200px; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); }
.gridline.base { border-top-color: var(--line); }
.gridline span { position: absolute; right: 100%; top: -0.7em; margin-right: 6px; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.slots { position: absolute; inset: 0; display: flex; gap: 2px; align-items: stretch; }
.slot { flex: 1 1 0; min-width: 0; display: flex; align-items: flex-end; justify-content: center; }
.col { width: 100%; max-width: 56px; background: var(--accent); border-radius: 4px 4px 0 0; }
.cols.dense .slots { gap: 1px; }
.cols.dense .col { border-radius: 2px 2px 0 0; }
.slot:hover .col { opacity: 0.7; }
.axis { position: relative; height: 1.6em; margin-top: 4px; }
.axis span { position: absolute; transform: translateX(-50%); font-size: 0.72rem; color: var(--muted); white-space: nowrap; }

table.plain { border: 0; background: none; font-size: 0.9rem; }
table.plain th, table.plain td { padding: 6px 8px 6px 0; }
table.plain tbody tr { cursor: default; }
table.plain tbody tr:hover { background: none; }
button.link { border: 0; background: none; padding: 0; text-align: left; color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
button.link:hover { text-decoration-color: var(--accent); }
.gap { color: var(--danger); }

.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 0.8rem; padding: 4px 8px; border-radius: 4px; white-space: nowrap; }

@media (max-width: 760px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .cols .plot { height: 160px; }
}

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .grid { grid-template-columns: 1fr; }
  th, td { padding: 8px; }
}
