:root {
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #d03b3b;
  --shadow: 0 1px 3px rgba(11, 11, 11, 0.08), 0 1px 2px rgba(11, 11, 11, 0.04);
  --shadow-lift: 0 8px 24px rgba(11, 11, 11, 0.16);
  --c1: #2a78d6; --c2: #1baf7a; --c3: #eda100; --c4: #008300;
  --c5: #4a3aa7; --c6: #e34948; --c7: #e87ba4; --c8: #eb6834;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #f2f1ec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --danger: #e66767;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 8px 24px rgba(0, 0, 0, 0.5);
    --c1: #3987e5; --c2: #199e70; --c3: #c98500; --c4: #008300;
    --c5: #9085e9; --c6: #e66767; --c7: #d55181; --c8: #d95926;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand svg { display: block; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  text-decoration: none; color: var(--ink-2);
  padding: 7px 12px; border-radius: 8px; font-weight: 500; font-size: 14px;
}
.topbar nav a.active { background: var(--surface-2); color: var(--ink); }
.topbar nav a:hover { color: var(--ink); }

main { height: calc(100dvh - 52px); overflow: hidden; }
main.scrolly { overflow-y: auto; }

/* ---- board ---- */
.board {
  display: flex; gap: 12px; align-items: flex-start;
  height: 100%; overflow-x: auto; overflow-y: hidden;
  padding: 14px;
  scroll-snap-type: x proximity;
}
.col {
  flex: 0 0 auto; width: 300px;
  max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface-2);
  border-radius: 12px;
  scroll-snap-align: start;
}
@media (max-width: 640px) {
  .col { width: min(85vw, 320px); }
  .board { scroll-snap-type: x mandatory; }
}
.col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 6px;
  cursor: grab;
}
.col-name { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-name input {
  width: 100%; border: 1px solid var(--accent); border-radius: 6px;
  padding: 2px 6px; background: var(--surface); font-weight: 600; font-size: 14px;
}
.col-count {
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
  background: var(--surface); border-radius: 10px; padding: 1px 8px;
}
.col-done-mark { font-size: 11px; color: var(--muted); border: 1px solid var(--baseline); border-radius: 8px; padding: 0 6px; }
.col-menu-btn {
  border: none; background: none; color: var(--muted);
  padding: 2px 6px; border-radius: 6px; font-size: 16px; line-height: 1;
}
.col-menu-btn:hover { background: var(--surface); color: var(--ink); }

.cards {
  flex: 1; overflow-y: auto; min-height: 24px;
  padding: 4px 8px 8px;
  display: flex; flex-direction: column; gap: 8px;
}
.card {
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  border-left: 3px solid transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card:hover { box-shadow: var(--shadow-lift); }
.card.color-c1 { border-left-color: var(--c1); } .card.color-c2 { border-left-color: var(--c2); }
.card.color-c3 { border-left-color: var(--c3); } .card.color-c4 { border-left-color: var(--c4); }
.card.color-c5 { border-left-color: var(--c5); } .card.color-c6 { border-left-color: var(--c6); }
.card.color-c7 { border-left-color: var(--c7); } .card.color-c8 { border-left-color: var(--c8); }
.card-title { font-size: 14px; line-height: 1.35; overflow-wrap: break-word; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }
.card-meta:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--ink-2);
  background: var(--surface-2); border-radius: 9px; padding: 2px 8px 2px 6px;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.chip.c1 .dot { background: var(--c1); } .chip.c2 .dot { background: var(--c2); }
.chip.c3 .dot { background: var(--c3); } .chip.c4 .dot { background: var(--c4); }
.chip.c5 .dot { background: var(--c5); } .chip.c6 .dot { background: var(--c6); }
.chip.c7 .dot { background: var(--c7); } .chip.c8 .dot { background: var(--c8); }
.due {
  font-size: 11.5px; color: var(--ink-2);
  border: 1px solid var(--grid); border-radius: 9px; padding: 1px 7px;
}
.due.overdue { color: var(--danger); border-color: var(--danger); font-weight: 600; }
.notes-hint { color: var(--muted); font-size: 12px; }

.card-ghost { opacity: 0.35; }
.card-drag { transform: rotate(2deg); }

.add-card-btn {
  margin: 0 8px 10px; padding: 7px 10px;
  border: none; border-radius: 8px; background: none;
  color: var(--muted); text-align: left; font-size: 13.5px;
}
.add-card-btn:hover { background: var(--surface); color: var(--ink); }
.composer { margin: 0 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.composer textarea {
  border: 1px solid var(--accent); border-radius: 8px; background: var(--surface);
  padding: 8px 10px; resize: none; font-size: 14px; min-height: 56px;
}
.composer textarea:focus { outline: none; }
.composer-row { display: flex; gap: 6px; }

.add-col {
  flex: 0 0 auto; width: 260px;
  border: 1.5px dashed var(--baseline); border-radius: 12px;
  background: none; color: var(--muted);
  padding: 12px; font-size: 14px; text-align: left;
  scroll-snap-align: start;
}
.add-col:hover { color: var(--ink); border-color: var(--muted); }

/* ---- popover menu ---- */
.popover {
  position: absolute; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lift);
  min-width: 180px; padding: 5px; display: flex; flex-direction: column;
}
.popover button {
  border: none; background: none; text-align: left;
  padding: 8px 10px; border-radius: 7px; font-size: 13.5px;
}
.popover button:hover { background: var(--surface-2); }
.popover button.danger { color: var(--danger); }

/* ---- generic views ---- */
.page {
  max-width: 860px; margin: 0 auto; padding: 20px 16px 60px;
}
.page h2 { font-size: 18px; margin: 26px 0 12px; }
.page h2:first-child { margin-top: 4px; }
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
}

/* ---- buttons & forms ---- */
.btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 7px 14px; font-size: 13.5px; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border: none; background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], textarea, select {
  border: 1px solid var(--baseline); border-radius: 8px;
  background: var(--surface); padding: 8px 10px; font-size: 14px;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--ink-2); font-weight: 500; }

/* ---- modal ---- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 14px;
  width: 100%; max-width: 480px; max-height: 90dvh; overflow-y: auto;
  padding: 18px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow-lift);
}
.modal h3 { font-size: 15px; }
.modal .row { display: flex; gap: 10px; }
.modal .row > * { flex: 1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.modal-actions .spacer { flex: 1; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent; background: var(--surface-2); padding: 0;
}
.swatch.sel { border-color: var(--ink); }
.swatch.c1 { background: var(--c1); } .swatch.c2 { background: var(--c2); }
.swatch.c3 { background: var(--c3); } .swatch.c4 { background: var(--c4); }
.swatch.c5 { background: var(--c5); } .swatch.c6 { background: var(--c6); }
.swatch.c7 { background: var(--c7); } .swatch.c8 { background: var(--c8); }
.meta-line { font-size: 12px; color: var(--muted); }

/* ---- login ---- */
#login { z-index: 200; background: var(--page); }
.login-card {
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; max-width: 320px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  text-align: center;
}
.login-card .brand { justify-content: center; font-size: 18px; margin-bottom: 6px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 17px; }

/* ---- toast ---- */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 300; background: var(--ink); color: var(--page);
  border-radius: 10px; padding: 10px 16px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
  max-width: 90vw;
}
#toast.show { opacity: 1; }

/* ---- stats ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px;
}
.tile .t-label { font-size: 12px; color: var(--ink-2); }
.tile .t-value { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .t-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.chart-panel { overflow-x: auto; }
.chart-panel svg { display: block; }
.chart-title { font-size: 13.5px; font-weight: 600; margin-bottom: 10px; }
.chart-sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.stats-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.bar-hover:hover rect.bar { filter: brightness(1.15); }
svg text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }

table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.list th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--grid);
}
table.list td { padding: 8px; border-bottom: 1px solid var(--grid); }
table.list tr:last-child td { border-bottom: none; }
table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list th.num { text-align: right; }
.minibar { display: inline-block; height: 8px; border-radius: 0 4px 4px 0; background: var(--accent); vertical-align: middle; }

/* ---- archive ---- */
.arch-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--grid);
}
.arch-row:last-child { border-bottom: none; }
.arch-main { flex: 1; min-width: 0; }
.arch-title { font-size: 14px; }
.arch-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.arch-actions { display: flex; gap: 6px; flex: none; }
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input { flex: 1; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 14px; }

/* ---- settings ---- */
.set-grid { display: flex; flex-direction: column; gap: 16px; }
.set-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
