/* ── Tokens ── */

:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #f0e9db;
  --line: #e2d8c5;
  --ink: #1f2a2e;
  --ink-2: #5b6669;
  --ink-3: #8b9496;
  --accent: #1f5b5f;
  --accent-ink: #ffffff;
  --accent-soft: #dcebea;
  --good: #3d8a5a;
  --good-soft: #dcefe2;
  --neutral: #c08a2e;
  --neutral-soft: #f6e8cc;
  --bad: #b8483b;
  --bad-soft: #f6dcd7;
  --empty: #e9e1d2;
  --hatch: rgba(31, 42, 46, 0.06);
  --shadow: 0 1px 2px rgba(31, 42, 46, 0.05), 0 4px 16px rgba(31, 42, 46, 0.05);
  --radius: 14px;
  --radius-sm: 9px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1e2127;
    --surface-2: #262a31;
    --line: #333841;
    --ink: #ece7dc;
    --ink-2: #a9aeb5;
    --ink-3: #7c828b;
    --accent: #7cc3bd;
    --accent-ink: #10221f;
    --accent-soft: #23393a;
    --good: #6cc08a;
    --good-soft: #1f3a2a;
    --neutral: #e0b25e;
    --neutral-soft: #3b3220;
    --bad: #e57a6c;
    --bad-soft: #42261f;
    --empty: #2b3038;
    --hatch: rgba(255, 255, 255, 0.05);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

/* ── Base ── */

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.7rem; line-height: 1.2; }
h2 { font-size: 1.2rem; margin-bottom: 0.75rem; }
h3 { font-size: 1rem; color: var(--ink-2); margin: 0.9rem 0 0.4rem; }

a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.hint { color: var(--ink-2); font-size: 0.85rem; margin: 0.4rem 0 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Buttons ── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 40px; padding: 0 1rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-ghost { color: var(--bad); border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 0 0.8rem; font-size: 0.875rem; }
.btn.wide { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 1.25rem; line-height: 1;
}
.icon-btn:hover:not(:disabled) { border-color: var(--ink-3); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn.sm { width: 32px; height: 32px; font-size: 0.95rem; }

.link-btn {
  border: 0; background: none; padding: 0; color: var(--accent);
  font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

/* ── Layout ── */

.boot { display: grid; place-items: center; min-height: 100vh; color: var(--ink-2); font-family: var(--serif); font-size: 1.1rem; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0.7rem max(1rem, env(safe-area-inset-left)) 0.7rem max(1rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--ink); text-decoration: none; font-family: var(--serif); font-weight: 700; font-size: 1.15rem; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 1rem;
}
.brand.big { font-size: 1.6rem; }
.brand.big .brand-mark { width: 40px; height: 40px; font-size: 1.3rem; border-radius: 12px; }

.nav { display: flex; gap: 0.25rem; }
.nav a {
  padding: 0.4rem 0.85rem; border-radius: 999px;
  color: var(--ink-2); font-weight: 600; text-decoration: none;
}
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.active { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }

.save-status { margin-left: auto; font-size: 0.8rem; color: var(--ink-3); white-space: nowrap; }
.save-status::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 0.4rem; background: var(--good); vertical-align: 1px; }
.save-status[data-kind="busy"]::before { background: var(--neutral); }
.save-status[data-kind="warn"]::before { background: var(--neutral); }
.save-status[data-kind="error"] { color: var(--bad); }
.save-status[data-kind="error"]::before { background: var(--bad); }

.local-banner {
  margin: 0; padding: 0.45rem 1rem; text-align: center; font-size: 0.85rem;
  background: var(--neutral-soft); color: var(--ink);
}

.view { max-width: 820px; margin: 0 auto; padding: 1.5rem 1rem 6rem; }
.view:has(.table-wrap) { max-width: none; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.cards { display: grid; gap: 0; }
.empty-state { text-align: center; padding: 2rem 1rem; }
.empty-state p { margin-top: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: 0.35rem 0 0; max-width: 46ch; }
.head-actions { display: flex; gap: 0.5rem; }

.chip {
  display: inline-flex; align-items: center; padding: 0.1rem 0.55rem; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.chip.r-good { background: var(--good-soft); color: var(--good); }
.chip.r-neutral { background: var(--neutral-soft); color: var(--neutral); }
.chip.r-bad { background: var(--bad-soft); color: var(--bad); }

/* ── Day entry ── */

.day-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.day-title { flex: 1; text-align: center; min-width: 0; }
.day-sub { display: flex; align-items: center; justify-content: center; gap: 0.75rem; margin-top: 0.35rem; font-size: 0.875rem; }
.today-badge { color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem; }
.date-input {
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  padding: 0.15rem 0.6rem; font-size: 0.8rem; color: var(--ink-2);
}

.progress { margin-bottom: 1.25rem; }
.progress-bar { height: 6px; border-radius: 999px; background: var(--empty); overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.3s ease; }
.progress-text { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-top: 0.45rem; font-size: 0.82rem; color: var(--ink-2); flex-wrap: wrap; }
.chips { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; }

.group-card { padding: 0.35rem 1.1rem 0.6rem; }
.section-toggle {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  border: 0; background: none; padding: 0.55rem 0; text-align: left; cursor: pointer; color: var(--ink);
}
.section-toggle .caret { width: 0.9rem; flex: none; color: var(--ink-3); font-size: 0.8rem; transition: transform 0.15s; }
.collapsed > .section-toggle .caret { transform: rotate(-90deg); }
.collapsed > .section-body { display: none; }
.card-title { font-family: var(--serif); font-weight: 600; font-size: 1.15rem; }
.count {
  margin-left: auto; font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--ink-3); background: var(--surface-2); padding: 0.05rem 0.5rem; border-radius: 999px;
}
.count.done { color: var(--good); background: var(--good-soft); }

.entry-section { margin-left: calc(var(--d, 0) * 1rem); }
.entry-section.depth-1 { --d: 1; }
.entry-section.depth-2 { --d: 2; }
.entry-section.depth-3 { --d: 3; }
.entry-section > .section-toggle { padding: 0.5rem 0 0.25rem; border-top: 1px solid var(--line); }
.entry-section.depth-0 > .section-toggle .section-name { font-weight: 700; font-size: 0.95rem; }
.entry-section:not(.depth-0) > .section-toggle .section-name { font-weight: 600; font-size: 0.85rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; }
.entry-section .count { margin-left: 0.25rem; }

.entry-row {
  display: grid; grid-template-columns: minmax(7rem, 11rem) 1fr; align-items: center; gap: 0.35rem 1rem;
  padding: 0.4rem 0 0.4rem calc(var(--depth, 0) * 1rem + 1.4rem);
}
.group-card > .section-body > .entry-row, .group-card > .entry-row { padding-left: 1.4rem; }
.entry-row + .entry-row { border-top: 1px dashed var(--line); }
.entry-label { font-weight: 600; font-size: 0.92rem; }
.entry-row.multi { align-items: start; }
.entry-row.multi .entry-label { padding-top: 1.45rem; }
.entry-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 1.25rem; min-width: 0; }
.entry-field { display: grid; gap: 0.2rem; min-width: 0; }
.entry-field.type-text { flex: 1 1 14rem; }
.entry-caption { font-size: 0.72rem; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }

.seg { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.seg.compact { flex-wrap: nowrap; background: var(--surface-2); padding: 3px; border-radius: 999px; gap: 2px; }
.seg-btn {
  min-height: 32px; padding: 0 0.8rem; font-size: 0.9rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; font-weight: 500; transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.seg.compact .seg-btn { border-color: transparent; background: transparent; min-height: 30px; font-size: 0.85rem; padding: 0 0.8rem; }
.seg.compact .seg-btn.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.seg-btn:hover { border-color: var(--ink-3); }
.seg-btn.on { font-weight: 700; }
.seg-btn.r-good.on { background: var(--good); border-color: var(--good); color: #fff; }
.seg-btn.r-neutral.on { background: var(--neutral); border-color: var(--neutral); color: #fff; }
.seg-btn.r-bad.on { background: var(--bad); border-color: var(--bad); color: #fff; }

.num { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.num-input {
  width: 5rem; height: 34px; text-align: center; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-variant-numeric: tabular-nums; font-weight: 600;
}
.num[data-rating="good"] .num-input { border-color: var(--good); background: var(--good-soft); }
.num[data-rating="neutral"] .num-input { border-color: var(--neutral); background: var(--neutral-soft); }
.num[data-rating="bad"] .num-input { border-color: var(--bad); background: var(--bad-soft); }
.num.invalid .num-input { border-color: var(--bad); }
.step-btn {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; font-size: 1.1rem; line-height: 1;
}
.unit { color: var(--ink-2); font-size: 0.9rem; }
.clear-btn { border: 0; background: none; color: var(--ink-3); cursor: pointer; padding: 0.25rem; }
.field-error { flex-basis: 100%; color: var(--bad); font-size: 0.8rem; }
.field-error:empty { display: none; }

.text-input {
  width: 100%; min-height: 38px; resize: vertical; padding: 0.5rem 0.7rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); line-height: 1.4;
}
.text-input.note { min-height: 90px; }

/* ── Table ── */

.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.period-nav { display: flex; align-items: center; gap: 0.6rem; }
.period-label { font-size: 1.35rem; min-width: 10ch; text-align: center; }
.table-options { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.875rem; color: var(--ink-2); cursor: pointer; }

.table-wrap {
  overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow); max-height: calc(100vh - 230px);
}
.log-table { border-collapse: separate; border-spacing: 0; font-size: 0.85rem; min-width: 100%; }
.log-table th, .log-table td { border-bottom: 1px solid var(--line); padding: 0; }
.log-table thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface-2);
  font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.log-table .sticky-col {
  position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left;
  min-width: 13rem; max-width: 18rem; border-right: 1px solid var(--line);
}
.log-table thead .corner { z-index: 4; background: var(--surface-2); padding: 0 0.85rem; font-family: var(--serif); font-size: 0.95rem; color: var(--ink); }
.day-col a { display: grid; padding: 0.45rem 0.25rem; min-width: 3.4rem; text-align: center; color: inherit; text-decoration: none; }
.day-col .wd { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }
.day-col .dd { font-variant-numeric: tabular-nums; }
.day-col a:hover .dd { color: var(--accent); text-decoration: underline; }
.day-col.is-today { color: var(--accent); }
.day-col.is-today .wd { color: var(--accent); }
.day-col.weekend, .cell.weekend { background-image: linear-gradient(var(--hatch), var(--hatch)); }
.cell.is-today { box-shadow: inset 2px 0 0 var(--accent-soft), inset -2px 0 0 var(--accent-soft); }
.stat-col { padding: 0 0.75rem !important; color: var(--ink-2); white-space: nowrap; font-size: 0.8rem; text-align: right; }
thead .stat-col { text-align: right; }

.row-label { display: flex; align-items: center; gap: 0.35rem; padding: 0.45rem 0.85rem 0.45rem calc(0.85rem + var(--depth, 0) * 1rem); }
th .row-label { font-weight: 500; }
.row-label.toggle {
  width: 100%; border: 0; background: none; cursor: pointer; text-align: left; font-weight: 700;
  padding-left: calc(0.5rem + var(--depth, 0) * 1rem);
}
.sticky-col .row-label { padding-left: calc(0.85rem + var(--depth) * 1rem); }
.sticky-col .row-label.toggle { padding-left: calc(0.45rem + var(--depth) * 1rem); }
.caret { width: 1rem; color: var(--ink-3); flex: none; }
.group-row .sticky-col, .group-row td { background-color: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.group-row.depth-0 .row-label { font-family: var(--serif); font-size: 0.95rem; }
tr.archived { opacity: 0.55; }

.cell { text-align: center; height: 38px; }
.cell.inactive { background-image: repeating-linear-gradient(135deg, var(--hatch) 0 4px, transparent 4px 8px); }
.cell-btn {
  width: 100%; height: 100%; min-height: 38px; border: 0; background: none; padding: 0.25rem; cursor: pointer;
  display: grid; place-items: center;
}
.cell-btn:hover { background: var(--accent-soft); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--empty); }
.pill {
  display: inline-block; max-width: 6.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 0.12rem 0.5rem; border-radius: 999px; font-weight: 600; font-size: 0.78rem;
  background: var(--surface-2); color: var(--ink);
}
.pill.r-good { background: var(--good-soft); color: var(--good); }
.pill.r-neutral { background: var(--neutral-soft); color: var(--neutral); }
.pill.r-bad { background: var(--bad-soft); color: var(--bad); }
.pill.text-pill { background: transparent; color: var(--ink-2); font-size: 0.95rem; }

.mini-bar { display: flex; gap: 2px; width: 2.6rem; height: 8px; margin: 0 auto; border-radius: 999px; overflow: hidden; }
.mini-bar span { display: block; min-width: 3px; }
.r-good { --c: var(--good); }
.mini-bar .r-good { background: var(--good); }
.mini-bar .r-neutral { background: var(--neutral); }
.mini-bar .r-bad { background: var(--bad); }
.mini-bar .seg-empty { background: var(--empty); }

.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 0.85rem; font-size: 0.8rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 4px; }
.sw.r-good { background: var(--good); }
.sw.r-neutral { background: var(--neutral); }
.sw.r-bad { background: var(--bad); }
.sw.sw-empty { background: var(--empty); }
.sw.sw-inactive { background: repeating-linear-gradient(135deg, var(--ink-3) 0 2px, transparent 2px 4px); opacity: 0.6; }

.cell-editor { display: grid; gap: 0.75rem; }
.cell-editor p { margin: 0; }

/* ── Categories ── */

.cat-list { list-style: none; padding: 0.35rem 0; margin: 0 0 1rem; }
.cat-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.15rem 0.6rem 0.15rem calc(0.6rem + var(--depth) * 1.4rem);
  border-top: 1px solid var(--line);
}
.cat-row:first-child { border-top: 0; }
.cat-row.archived { opacity: 0.55; }
.cat-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  border: 0; background: none; text-align: left; cursor: pointer; padding: 0.6rem 0.4rem; border-radius: var(--radius-sm);
}
.cat-main:hover { background: var(--surface-2); }
.cat-row.type-group .cat-name { font-family: var(--serif); font-weight: 700; font-size: 1.02rem; }
.cat-name { font-weight: 600; }
.cat-desc { color: var(--ink-3); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.cat-actions { display: flex; gap: 0.25rem; flex: none; }
.type-badge {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0.12rem 0.45rem; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); flex: none;
}
.type-badge.t-group { background: var(--accent-soft); color: var(--accent); }
.type-badge.t-select { background: var(--good-soft); color: var(--good); }
.type-badge.t-number { background: var(--neutral-soft); color: var(--neutral); }

/* ── Forms ── */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem 1rem; }
.form-grid.four { grid-template-columns: repeat(4, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .field, .login-card .field {
  display: grid; grid-template-columns: 1fr; gap: 0.3rem; padding: 0; border: 0;
  font-size: 0.82rem; font-weight: 600; color: var(--ink-2);
}
.form-grid input, .form-grid select, .login-card input, .opt-row input {
  width: 100%; height: 40px; padding: 0 0.7rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-weight: 400; font-size: 0.95rem;
}
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; margin: 1.25rem 0 0.5rem; font-weight: 700; flex-wrap: wrap; }

.type-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }
.type-opt {
  display: grid; gap: 0.1rem; text-align: left; padding: 0.55rem 0.7rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
.type-opt span { font-size: 0.75rem; color: var(--ink-3); font-weight: 400; }
.type-opt.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.type-opt:disabled { opacity: 0.4; cursor: not-allowed; }
.type-picker .hint { grid-column: 1 / -1; }

.type-section { margin-top: 1.1rem; }
.type-section .section-title:first-child { margin-top: 0; }
.opt-editor { display: grid; gap: 0.4rem; }
.opt-row { display: flex; align-items: center; gap: 0.4rem; }
.opt-row input { flex: 1; height: 36px; }
.opt-row.archived input { text-decoration: line-through; opacity: 0.6; }
.opt-new { margin-top: 0.4rem; padding-top: 0.6rem; border-top: 1px dashed var(--line); }
.rating-pick { display: flex; gap: 4px; flex: none; }
.rate-btn {
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 2px solid transparent; background: var(--c); opacity: 0.3;
}
.rate-btn.r-good { --c: var(--good); }
.rate-btn.r-neutral { --c: var(--neutral); }
.rate-btn.r-bad { --c: var(--bad); }
.rate-btn.on { opacity: 1; border-color: var(--surface); box-shadow: 0 0 0 2px var(--c); }

/* ── Dialog ── */

.dlg {
  border: 0; padding: 0; border-radius: 18px; width: min(480px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
}
.dlg.wide { width: min(680px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(22, 24, 29, 0.45); backdrop-filter: blur(2px); }
.dlg-form { display: grid; max-height: calc(100vh - 40px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem 0.5rem; }
.dlg-head h2 { margin: 0; font-size: 1.15rem; }
.dlg-head .icon-btn { width: 32px; height: 32px; font-size: 0.9rem; border: 0; }
.dlg-body { padding: 0.5rem 1.25rem 0.75rem; overflow: auto; }
.dlg-text { margin: 0; color: var(--ink-2); }
.dlg-message { margin: 0; padding: 0 1.25rem; color: var(--bad); font-size: 0.875rem; min-height: 0; }
.dlg-message.ok { color: var(--good); }
.dlg-message:empty { display: none; }
.dlg-actions { display: flex; gap: 0.5rem; justify-content: flex-end; padding: 0.85rem 1.25rem 1.1rem; flex-wrap: wrap; border-top: 1px solid var(--line); margin-top: 0.5rem; }
.dlg-actions .left { margin-right: auto; }
.dlg-actions .left + .left { margin-right: auto; margin-left: -0.25rem; }
.dlg-actions .left:has(+ .left) { margin-right: 0; }

/* ── Login ── */

.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card {
  width: min(380px, 100%); display: grid; gap: 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 2rem 1.75rem; box-shadow: var(--shadow);
}
.login-card .muted { margin: -0.4rem 0 0.25rem; }
.login-msg { margin: 0; color: var(--bad); font-size: 0.875rem; }
.login-msg:empty { display: none; }
.login-card .link-btn { justify-self: center; font-size: 0.875rem; }

.account-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.acc-badge { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.acc-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }

/* ── Toast ── */

.toast {
  position: fixed; left: 50%; bottom: max(1.25rem, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100;
  padding: 0.65rem 1.1rem; border-radius: 999px; background: var(--ink); color: var(--bg);
  font-weight: 600; font-size: 0.9rem; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); max-width: calc(100vw - 2rem);
}
.toast[data-kind="error"] { background: var(--bad); color: #fff; }

/* ── Small screens ── */

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 0.5rem 1rem; padding-bottom: 0; }
  .nav { order: 3; width: calc(100% + 2rem); margin: 0 -1rem; padding: 0 0.5rem 0.4rem; overflow-x: auto; }
  .nav a { flex: none; }
  .view { padding-top: 1rem; }
  h1 { font-size: 1.35rem; }
  .entry-row.multi .entry-label { padding-top: 0; }
  .entry-row { grid-template-columns: 1fr; gap: 0.3rem; padding-left: calc(var(--depth, 0) * 0.6rem + 1.4rem); }
  .entry-section { margin-left: calc(var(--d, 0) * 0.6rem); }
  .entry-row:not(.multi):not(:has(.type-text)) { grid-template-columns: minmax(5.5rem, 38%) 1fr; align-items: center; }
  .form-grid, .form-grid.four { grid-template-columns: 1fr 1fr; }
  .type-picker { grid-template-columns: 1fr 1fr; }
  .log-table .sticky-col { min-width: 9.5rem; max-width: 11rem; }
  .table-wrap { max-height: calc(100vh - 260px); }
  .cat-desc { display: none; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
}
