:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #23201c;
  --muted: #7a7268;
  --line: #e7e1d8;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e3efea;
  --warn: #b5651d;
  --warn-soft: #fbeedd;
  --danger: #b03a2e;
  --danger-soft: #f9e3e0;
  --ok: #3b7d3b;
  --ok-soft: #e4f1e1;
  --shadow: 0 1px 2px rgba(40, 30, 20, .05), 0 4px 16px rgba(40, 30, 20, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #212326;
    --surface-2: #1c1d20;
    --ink: #ece8e2;
    --muted: #9b958c;
    --line: #33363a;
    --accent: #5fb39a;
    --accent-ink: #0f1a16;
    --accent-soft: #1f3530;
    --warn: #e0a060;
    --warn-soft: #3a2c1c;
    --danger: #e37b70;
    --danger-soft: #3d2220;
    --ok: #82c482;
    --ok-soft: #1f3320;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Assistant", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; padding-bottom: 14px; }
h1 { margin: 0; font-size: 24px; font-weight: 800; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
.top-actions { display: flex; gap: 8px; }

.btn {
  font: inherit; font-weight: 600; border-radius: 10px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.small { padding: 4px 10px; font-size: 14px; }
.btn.danger { color: var(--danger); }
.icon-btn { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 20px 0 8px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 30px; font-weight: 800; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 14px; }
.stat.warn .n { color: var(--warn); }
.stat.danger .n { color: var(--danger); }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin: 16px 0; }
.tabs { display: inline-flex; background: var(--surface); border-radius: 12px; padding: 4px; box-shadow: var(--shadow); }
.tab { font: inherit; font-weight: 600; border: 0; background: none; padding: 6px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters input, .filters select, .form-add input {
  font: inherit; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); min-width: 0;
}
.filters input { width: 220px; }

.list { padding-bottom: 40px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
.branch-group + .branch-group { margin-top: 10px; }
.branch-group .group { margin-bottom: 10px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; display: flex; gap: 14px; border-inline-start: 4px solid var(--accent);
}
.card.due-soon { border-inline-start-color: var(--warn); }
.card.overdue { border-inline-start-color: var(--danger); }
.card-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1; }
.card h3 { margin: 0; font-size: 18px; line-height: 1.3; }
.card .author { color: var(--muted); margin-top: -4px; }
.cover, .thumb { object-fit: cover; border-radius: 6px; background: var(--surface-2); flex-shrink: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.cover { width: 96px; height: 144px; }
.thumb { width: 44px; height: 64px; }
.no-cover { display: flex; align-items: center; justify-content: center; font-size: 24px; border: 1px dashed var(--line); box-shadow: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.chip.branch { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip.branch.inferred { background: transparent; border: 1px solid var(--accent); }
.chip.branch.maybe { background: var(--surface-2); color: var(--muted); font-weight: 400; border: 1px dashed var(--line); }
.chip.who { font-weight: 600; }
.dates { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 14px; margin: 0; }
.dates dt { color: var(--muted); }
.dates dd { margin: 0; }
.due-badge { align-self: flex-start; font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 8px; background: var(--ok-soft); color: var(--ok); }
.due-badge.due-soon { background: var(--warn-soft); color: var(--warn); }
.due-badge.overdue { background: var(--danger-soft); color: var(--danger); }
.tags { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.tags span + span::before { content: "·"; margin-inline-end: 10px; }
.summary { font-size: 14px; }
.summary summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }
.summary p { margin: 6px 0 0; white-space: pre-line; color: var(--ink); }

.list.rows { display: flex; flex-direction: column; gap: 8px; }
.group { font-size: 20px; margin: 18px 0 2px; }
.group small { font-size: 14px; color: var(--muted); font-weight: 400; margin-inline-start: 6px; }
.row { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.row-title { font-weight: 700; }
.count { font-size: 13px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 0 6px; vertical-align: middle; }
.row-sub { color: var(--muted); font-size: 14px; }
.row-dates { font-size: 13px; text-align: end; white-space: nowrap; color: var(--ink); }
.row-dates span { color: var(--muted); }

.info-box { background: var(--accent-soft); color: var(--accent); padding: 10px 14px; border-radius: 10px; margin: 8px 0; font-weight: 600; }

.empty { text-align: center; padding: 60px 16px; color: var(--muted); }
.empty-icon { font-size: 54px; }
.empty h2 { color: var(--ink); margin: 8px 0; }

.error-box { background: var(--danger-soft); color: var(--danger); padding: 10px 14px; border-radius: 10px; margin: 8px 0; }

dialog {
  border: 0; border-radius: 18px; padding: 20px; width: min(480px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(20, 15, 10, .4); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { margin: 0; }
.account-list { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.account-list li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.account-list .name { flex: 1; }
.account-list .name small { display: block; color: var(--muted); }
.form-add { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.form-add h3 { margin: 0; }
.form-add label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.form-msg:empty { display: none; }
.form-msg { padding: 8px 12px; border-radius: 10px; font-size: 14px; }
.form-msg.err { background: var(--danger-soft); color: var(--danger); }
.form-msg.ok { background: var(--ok-soft); color: var(--ok); }

@media (max-width: 600px) {
  h1 { font-size: 20px; }
  .filters input { width: 100%; }
  .filters { width: 100%; }
  .filters > * { flex: 1; }
  .cards { grid-template-columns: 1fr; }
  .cover { width: 72px; height: 108px; }
  .row { flex-wrap: wrap; }
  .row-dates { width: 100%; text-align: start; display: flex; gap: 12px; padding-inline-start: 56px; }
}

.unlock {
  max-width: 360px; margin: 60px auto; text-align: center; display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); padding: 28px 24px; border-radius: 18px; box-shadow: var(--shadow);
}
.unlock h2 { margin: 0; }
.unlock p { margin: 0; color: var(--muted); }
.unlock input[type=password] {
  font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); text-align: center;
}
.unlock .remember { font-size: 14px; color: var(--muted); display: flex; gap: 6px; justify-content: center; align-items: center; }

.branches { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
.branches legend { font-weight: 600; font-size: 14px; padding: 0 4px; }
#set-branches { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px 12px; margin-top: 6px; }
#set-branches label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.form-add select { font: inherit; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
