:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --sunken: #efefea;
  --line: #e2e2dc;
  --text: #1f2328;
  --muted: #6b6f76;
  --faint: #9a9ea5;
  --accent: #2f62d8;
  --accent-soft: #e6edfc;
  --ok: #23905d;
  --ok-soft: #e3f3ea;
  --warn: #b7791f;
  --warn-soft: #fbf0dc;
  --danger: #cc3a43;
  --danger-soft: #fbe7e8;
  --shadow: 0 1px 2px rgb(20 20 10 / 5%), 0 8px 24px rgb(20 20 10 / 6%);
  --radius: 12px;
  --sidebar: 248px;
  --detail: 440px;
  color-scheme: light;
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b; --surface: #1e2125; --sunken: #23272c; --line: #30353c;
    --text: #e6e8eb; --muted: #a0a6ae; --faint: #6f757d;
    --accent: #7ea2ff; --accent-soft: #233154;
    --ok: #4cc38a; --ok-soft: #1c3a2c; --warn: #e2b04a; --warn-soft: #3d321b;
    --danger: #ff7b82; --danger-soft: #45242a;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; }

input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: grid; gap: 4px; align-content: start; font-size: 13px; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; font-weight: 550; white-space: nowrap; }
.btn:hover { background: var(--sunken); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--sunken); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 11px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 8px; font-size: 18px; line-height: 1; color: var(--muted); }
.icon-btn:hover { background: var(--sunken); color: var(--text); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 32px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 0; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 24px; font-weight: 700; }
.logo.small { width: 26px; height: 26px; border-radius: 7px; font-size: 15px; }

/* Layout */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.app.with-detail { grid-template-columns: var(--sidebar) 1fr var(--detail); }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; background: var(--bg); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 8px; }
.nav { display: grid; gap: 1px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text); border: 0; background: transparent; text-align: left; width: 100%; font-size: 14.5px; }
.nav-link:hover { background: var(--sunken); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link .ico { width: 18px; text-align: center; color: var(--faint); }
.nav-link.active .ico { color: var(--accent); }
.nav-link .count { margin-left: auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.nav-link .count.alert { color: var(--danger); font-weight: 650; }
.nav-link .dot { width: 9px; height: 9px; border-radius: 50%; margin: 0 4px; flex: none; }
.nav-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 4px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.nav-bottom { margin-top: auto; display: grid; gap: 1px; }

.main { min-width: 0; padding: 24px clamp(16px, 4vw, 48px) 96px; max-width: 980px; width: 100%; justify-self: center; }
.top { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.titles { flex: 1; min-width: 0; }
.eyebrow { margin: 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.top h1 { margin: 2px 0 0; font-size: 28px; letter-spacing: -.02em; }
.search { width: min(280px, 40vw); }
.search input { background: var(--sunken); border-color: transparent; }

/* Capture */
.capture { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 18px; }
.capture input { padding: 11px 14px; font-size: 15.5px; border-radius: 10px; box-shadow: var(--shadow); border-color: transparent; }
.capture .btn { border-radius: 10px; }
.preview { grid-column: 1 / -1; min-height: 0; }
.preview:empty { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; background: var(--sunken); color: var(--muted); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }
a.chip:hover { text-decoration: none; filter: brightness(.97); }

/* Reminders */
.reminders { display: grid; gap: 8px; margin-bottom: 16px; }
.reminder { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--text); }
.reminder strong { flex: 1; min-width: 0; font-weight: 550; cursor: pointer; }

/* Task list */
.group { margin: 22px 0 6px; display: flex; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 650; color: var(--muted); }
.group:first-child { margin-top: 0; }
.group.danger { color: var(--danger); }
.group .n { font-weight: 500; color: var(--faint); }
.row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; cursor: pointer; position: relative; }
.row + .row { border-top: 1px solid transparent; }
.row:hover { background: var(--surface); box-shadow: var(--shadow); }
.row.selected { background: var(--accent-soft); }
.row.done .row-title { color: var(--faint); text-decoration: line-through; }
.check { flex: none; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%; border: 1.6px solid var(--faint); background: transparent; display: grid; place-items: center; font-size: 12px; color: transparent; padding: 0; }
.check:hover { border-color: var(--ok); color: var(--ok); }
.row.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.row.p2 .check { border-color: var(--warn); }
.row.p3 .check { border-color: var(--danger); border-width: 2px; }
.row-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.row-title { overflow-wrap: anywhere; }
.row-title .prio { color: var(--danger); font-weight: 700; margin-right: 4px; }
.row-title .prio.p2 { color: var(--warn); }
.row-meta:empty { display: none; }
.row-actions { display: none; gap: 2px; flex: none; }
.row:hover .row-actions { display: flex; }
.row-actions button { border: 0; background: transparent; color: var(--muted); font-size: 12.5px; padding: 3px 7px; border-radius: 6px; }
.row-actions button:hover { background: var(--sunken); color: var(--text); }
.working { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }
.more { text-align: center; margin-top: 12px; }

/* Detail panel */
.detail { position: sticky; top: 0; height: 100vh; overflow-y: auto; overflow-x: hidden; border-left: 1px solid var(--line); background: var(--surface); padding: 16px 20px 40px; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 14px; }
.detail-head { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 13px; }
.detail-head .spacer { flex: 1; }
.title-input { font-size: 20px; font-weight: 650; border-color: transparent; padding: 6px 8px; margin: 0 -8px; background: transparent; resize: none; overflow: hidden; }
.title-input:hover { border-color: var(--line); }
.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px 12px; }
.fields .full { grid-column: 1 / -1; }
.date-field { display: grid; grid-template-columns: 1fr auto; gap: 4px; }
.quick-dates { display: flex; gap: 4px; flex-wrap: wrap; }
.quick-dates button { font-size: 12px; padding: 2px 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; color: var(--muted); }
.quick-dates button:hover { color: var(--text); background: var(--sunken); }
.section { display: grid; gap: 8px; }
.section h3 { margin: 6px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 650; }
.checklist { display: grid; gap: 2px; }
.check-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.check-item input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--ok); flex: none; }
.check-item span { flex: 1; overflow-wrap: anywhere; }
.check-item.done span { color: var(--faint); text-decoration: line-through; }
.check-item .icon-btn { width: 24px; height: 24px; font-size: 14px; opacity: 0; }
.check-item:hover .icon-btn { opacity: 1; }
.inline-form { display: flex; gap: 6px; }
.link-row { display: flex; align-items: center; gap: 8px; }
.link-row a, .link-row span.ref { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-form { display: grid; grid-template-columns: 110px 1fr; gap: 6px; }
.link-form .full { grid-column: 1 / -1; }
.timeline { display: grid; gap: 10px; }
.event { display: grid; gap: 2px; font-size: 13.5px; }
.event .who { font-size: 12px; color: var(--faint); }
.event.comment .body { background: var(--sunken); padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.event.system .body { color: var(--muted); }
.work { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; font-size: 13.5px; }
.work .steps { display: grid; gap: 3px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 14px; }
.detail-actions .spacer { flex: 1; }

/* Pages: stats, agents, trash */
.page { display: grid; gap: 22px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 12px; }
.card h2 { margin: 0; font-size: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.toolbar label { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 13px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 140px; padding-top: 6px; }
.bar { flex: 1; display: flex; flex-direction: column-reverse; gap: 1px; min-width: 2px; height: 100%; justify-content: flex-start; position: relative; }
.bar i { display: block; border-radius: 3px 3px 0 0; }
.bar i.c { background: var(--ok); }
.bar i.n { background: var(--accent); opacity: .35; }
.bars-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--faint); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 550; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
pre.snippet { background: var(--sunken); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; margin: 0; white-space: pre; }
.secret { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; border-radius: 10px; background: var(--ok-soft); }
.secret input { font-family: ui-monospace, monospace; font-size: 13px; }
.form-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: end; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; display: flex; gap: 14px; align-items: center; max-width: calc(100vw - 32px); }
.toast button { background: transparent; border: 0; color: var(--accent); font-weight: 650; filter: brightness(1.4); }
.only-mobile { display: none; }
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 35%); z-index: 30; }

@media (max-width: 1180px) {
  .app.with-detail { grid-template-columns: var(--sidebar) 1fr; }
  .app.with-detail .detail { position: fixed; right: 0; top: 0; bottom: 0; width: min(var(--detail), 100vw); z-index: 40; box-shadow: var(--shadow); }
}
@media (max-width: 760px) {
  .only-mobile { display: initial; }
  .app, .app.with-detail { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 35; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .main { padding: 14px 14px 110px; }
  .top { gap: 8px; }
  .top h1 { font-size: 23px; }
  .search { width: 42vw; }
  .capture { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0; margin: 0 0 10px; }
  .capture .btn { padding: 8px 12px; }
  .app.with-detail .detail { width: 100vw; padding-bottom: 100px; }
  .row-actions { display: none !important; }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .detail-head .icon-btn { width: 40px; height: 40px; font-size: 22px; }
  .form-row { grid-template-columns: 1fr 1fr; }
  .tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
  .tabbar a { display: grid; justify-items: center; font-size: 11px; color: var(--muted); position: relative; padding: 2px 0; }
  .tabbar a span { font-size: 18px; line-height: 1.2; }
  .tabbar a.active { color: var(--accent); }
  .tabbar a b { position: absolute; top: 0; left: 58%; font-size: 10px; background: var(--accent); color: #fff; border-radius: 999px; padding: 0 5px; }
  .tabbar a b:empty { display: none; }
}
