/* ---------- tokens ---------- */
/* Colors are light-dark() pairs; color-scheme picks the side. It follows the
   OS unless <html data-theme="light|dark"> pins it (the theme toggle). */
:root {
  color-scheme: light dark;
  --page: light-dark(#f6f6f3, #0d0d0d);
  --surface: light-dark(#fcfcfb, #1a1a19);
  --surface-2: light-dark(#f0efec, #262624);
  --ink: light-dark(#0b0b0b, #ffffff);
  --ink-2: light-dark(#52514e, #c3c2b7);
  --muted: #898781;
  --grid: light-dark(#e9e8e2, #2c2c2a);
  --axis: light-dark(#c3c2b7, #383835);
  --border: light-dark(rgba(11, 11, 11, 0.10), rgba(255, 255, 255, 0.10));
  --accent: light-dark(#2a78d6, #3987e5);
  --danger: light-dark(#d03b3b, #e66767);
  --warn-bg: light-dark(#fff6df, #2e2714);
  --shadow: 0 1px 2px light-dark(rgba(0, 0, 0, 0.04), transparent),
            0 2px 8px light-dark(rgba(0, 0, 0, 0.03), transparent);

  --series-1: light-dark(#2a78d6, #3987e5); --series-2: light-dark(#eb6834, #d95926);
  --series-3: light-dark(#1baf7a, #199e70); --series-4: light-dark(#eda100, #c98500);
  --series-5: light-dark(#e87ba4, #d55181); --series-6: #008300;
  --series-7: light-dark(#4a3aa7, #9085e9); --series-8: light-dark(#e34948, #e66767);
  /* extra choices, see charts.PALETTE */
  --series-9: light-dark(#0f8fa8, #2aa5bd);  --series-10: light-dark(#a35f22, #b9773d);
  --series-11: light-dark(#8e3fa6, #b06ad0); --series-12: light-dark(#6f9a12, #6f9e1e);
  --series-13: light-dark(#c42d6b, #e0619a); --series-14: light-dark(#2c4fb5, #6683e0);
  --series-15: light-dark(#858a1c, #8f9428); --series-16: light-dark(#5f6b7a, #7a8594);

  --radius: 10px;
  --tint: 18%;  /* how strongly timeline blocks are tinted; dark needs more */
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; --tint: 30%; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --tint: 30%; }
}

.c1 { --c: var(--series-1); } .c2 { --c: var(--series-2); }
.c3 { --c: var(--series-3); } .c4 { --c: var(--series-4); }
.c5 { --c: var(--series-5); } .c6 { --c: var(--series-6); }
.c7 { --c: var(--series-7); } .c8 { --c: var(--series-8); }
.c9 { --c: var(--series-9); } .c10 { --c: var(--series-10); }
.c11 { --c: var(--series-11); } .c12 { --c: var(--series-12); }
.c13 { --c: var(--series-13); } .c14 { --c: var(--series-14); }
.c15 { --c: var(--series-15); } .c16 { --c: var(--series-16); }

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { background: var(--page); }
body { margin: 0; color: var(--ink); background: var(--page); font-size: 14px; line-height: 1.45; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.35rem; }
h2 { font-size: 0.95rem; }
.muted { color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); margin: 0.5rem 0; }

.topbar {
  display: flex; align-items: center; gap: 2rem;
  padding: 0 24px; height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; text-decoration: none; }
.brand svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linecap: round; }
.topbar nav { display: flex; gap: 4px; }
.mainnav svg { display: none; }
.topbar nav a {
  text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--ink-2);
}
.topbar nav a:hover { background: var(--surface-2); }
.topbar nav a[aria-current] { color: var(--ink); background: var(--surface-2); font-weight: 600; }

.page { max-width: 1440px; margin: 0 auto; padding: 20px 24px 48px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.page-head p { margin: 0; }
.pager { display: flex; align-items: center; gap: 6px; }
.pager h1 { margin-left: 8px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 12px;
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; color: var(--ink); text-decoration: none; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; min-height: 32px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.icon { width: 32px; padding: 0; font-size: 1.15rem; }
.btn.small { padding: 2px 10px; min-height: 26px; font-size: 0.85rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 7px; padding: 6px 9px; min-height: 34px; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
[aria-invalid="true"] { border-color: var(--danger); }

.segmented { display: flex; flex-wrap: wrap; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented a { text-decoration: none; padding: 5px 11px; border-radius: 7px; color: var(--ink-2); }
.segmented a[aria-current] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

.notice {
  background: var(--warn-bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; margin-bottom: 12px;
}
.notice.error { color: var(--danger); }

.swatch {
  display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 3px;
  background: var(--c); margin-right: 6px; vertical-align: baseline;
}

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 0; list-style: none; color: var(--ink-2); font-size: 0.85rem; }
.legend li { display: flex; align-items: center; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile-label { color: var(--ink-2); font-size: 0.85rem; }
.tile-value { font-size: 1.45rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.hero .tile-value { font-size: 2rem; line-height: 1.2; }
.tile-sub { color: var(--muted); font-size: 0.8rem; }

/* ---------- week layout ---------- */
.week-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 1000px) {
  .week-layout { grid-template-columns: minmax(0, 1fr); }
  .week-side { order: -1; }
}

/* ---------- timeline ---------- */
.timeline-scroll { overflow-x: auto; }
.timeline {
  display: grid; min-width: 620px;
  grid-template-columns: 44px repeat(7, minmax(0, 1fr));
  grid-template-rows: auto var(--height);
}
.tl-dayhead {
  text-align: center; padding: 2px 4px 8px; text-decoration: none; border-radius: 6px;
}
.tl-dayhead .dow { color: var(--ink-2); }
.tl-dayhead .dom { font-weight: 600; }
.tl-dayhead .dtot { display: block; font-size: 0.78rem; color: var(--muted); min-height: 1.1em; }
.tl-dayhead.today .dom {
  background: var(--accent); color: #fff; border-radius: 999px; padding: 0 6px;
}
.tl-hours { grid-column: 1; grid-row: 2; position: relative; }
.tl-hours span {
  position: absolute; left: 0; font-size: 0.72rem; color: var(--muted);
  transform: translateY(-0.6em); font-variant-numeric: tabular-nums;
}
.tl-lines { grid-column: 2 / -1; grid-row: 2; position: relative; pointer-events: none; border-bottom: 1px solid var(--grid); }
.tl-lines div { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); }
.tl-lines .off { background: repeating-linear-gradient(135deg, transparent 0 4px, var(--grid) 4px 5px); opacity: 0.45; }
.tl-lines .on + .off, .tl-lines .off + .on { border-top-color: var(--axis); }
.tl-day { grid-row: 2; grid-column: var(--col); position: relative; border-left: 1px solid var(--grid); cursor: copy; }
.tl-day:last-child { border-right: 1px solid var(--grid); }
.tl-day.today { background-color: color-mix(in oklab, var(--accent) 5%, transparent); }
.tl-block {
  position: absolute; overflow: hidden; cursor: pointer; text-align: left;
  top: calc(var(--y) + 1px);
  height: calc(var(--h) - 2px);
  left: calc(var(--lane) / var(--lanes) * 100% + 2px);
  width: calc(100% / var(--lanes) - 4px);
  min-height: 3px;
  padding: 3px 6px 3px 7px; margin: 0;
  /* line-height must match TL_LINE in views.py: the server decides how many lines fit */
  font: inherit; font-size: 0.75rem; line-height: 15px; color: var(--ink);
  background: color-mix(in oklab, var(--c) var(--tint), var(--surface));
  border: 0; border-radius: 6px;
  box-shadow: inset 3px 0 0 var(--c), inset 0 0 0 1px color-mix(in oklab, var(--c) 22%, transparent);
  display: flex; flex-direction: column;
  transition: background-color 0.12s, box-shadow 0.12s, transform 0.12s;
}
.tl-block:hover {
  background: color-mix(in oklab, var(--c) calc(var(--tint) + 12%), var(--surface)); z-index: 2;
  box-shadow: inset 3px 0 0 var(--c), inset 0 0 0 1px color-mix(in oklab, var(--c) 40%, transparent),
              0 2px 8px rgba(0, 0, 0, 0.12);
}
.tl-block:focus-visible { outline: 2px solid var(--accent); z-index: 2; }
.tl-act, .tl-time { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; }
.tl-act { font-weight: 600; }
.tl-time { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 0.7rem; }
.tl-desc {
  color: var(--ink-2); overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--desc-lines); line-clamp: var(--desc-lines);
}
.tl-block.one-line { flex-direction: row; align-items: center; gap: 6px; padding-top: 0; padding-bottom: 0; }
.tl-block.one-line .tl-act { flex: 0 1 auto; min-width: 0; }
.tl-block.bare { padding: 0; }
.tl-block.narrow { padding-left: 6px; padding-right: 3px; }
.tl-now {
  position: absolute; left: -1px; right: 0; height: 2px; background: var(--danger); z-index: 3; pointer-events: none;
  top: calc(var(--y) - 1px);
}
.tl-now::before {
  content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
}
.tl-ghost {
  position: absolute; left: 2px; right: 2px; height: 3px; border-radius: 2px;
  background: var(--accent); pointer-events: none; top: calc(var(--y) - 1px); z-index: 3;
}

@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 3px transparent; } }
.flash { animation: flash 1.6s ease-out; }

/* ---------- column chart ---------- */
.colchart { padding-left: 32px; }
.colchart .plot { position: relative; height: 170px; margin-top: 18px; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); }
.gridline:first-child { border-top-color: var(--axis); }
.gridline span {
  position: absolute; right: calc(100% + 6px); top: -0.6em;
  font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.cols { position: absolute; inset: 0; display: flex; }
.col { flex: 1; position: relative; text-decoration: none; min-width: 0; }
a.col[href]:hover { background: color-mix(in oklab, var(--ink) 4%, transparent); border-radius: 6px 6px 0 0; }
/* A share of the column, so a few wide columns get wide bars rather than
   wide gaps; capped so four bars don't turn into slabs. */
.stack {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(60%, 72px); display: flex; flex-direction: column-reverse; gap: 2px;
  border-radius: 4px 4px 0 0; overflow: hidden;
}
.seg { background: var(--c); flex-basis: 0; min-height: 1px; }
.col-val {
  position: absolute; left: 0; right: 0; text-align: center; margin-bottom: 3px;
  font-size: 0.72rem; color: var(--ink-2); white-space: nowrap; pointer-events: none;
}
.col.current .col-val { color: var(--ink); font-weight: 600; }
.col-labels { display: flex; margin-top: 6px; }
.col-labels span { flex: 1; text-align: center; font-size: 0.75rem; color: var(--muted); white-space: nowrap; min-width: 0; }
.col-labels span.current { color: var(--ink); font-weight: 600; }

/* ---------- breakdown ---------- */
.breakdown { display: flex; flex-direction: column; gap: 10px; }
.bk-group { display: flex; flex-direction: column; gap: 3px; }
.bk-row {
  display: grid; grid-template-columns: minmax(80px, 1.1fr) minmax(40px, 1.4fr) auto 3.2em;
  gap: 10px; align-items: center; font-size: 0.85rem;
}
.breakdown:has(.bk-share + .bk-share) .bk-row { grid-template-columns: minmax(80px, 1.1fr) minmax(40px, 1.6fr) 5.5em 3.2em 5.5em; }
.bk-cat { font-weight: 600; }
.bk-act { color: var(--ink-2); }
.bk-act .bk-name { padding-left: 16px; }
.bk-name { display: flex; align-items: center; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk-bar { height: 10px; display: block; }
.bk-act .bk-bar { height: 6px; }
.fill { display: block; height: 100%; min-width: 2px; background: var(--c); border-radius: 0 4px 4px 0; }
.fill.soft { background: color-mix(in oklab, var(--c) 55%, var(--surface)); }
.bk-val { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bk-share { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bk-heads { display: flex; gap: 10px; font-size: 0.8rem; }

/* ---------- entry form ---------- */
.entry-form { display: flex; flex-direction: column; gap: 10px; }
.entry-form .card-head { margin-bottom: 0; }
.entry-form.editing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field > span { font-size: 0.8rem; color: var(--ink-2); }
.field-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.err { color: var(--danger); font-size: 0.78rem; }
.form-actions { display: flex; gap: 8px; }
.form-actions .danger { margin-left: auto; }
.hint { margin: 0; font-size: 0.78rem; }

/* ---------- entry list ---------- */
.day-title { font-size: 0.85rem; color: var(--ink-2); margin: 14px 0 4px; }
.day-title:first-of-type { margin-top: 0; }
.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 7.5em minmax(140px, 0.9fr) minmax(0, 2fr) 5em;
  gap: 12px; align-items: baseline; padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.entry:hover, .entry:focus-visible { background: var(--surface-2); outline: none; }
.e-time { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.e-act { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.e-desc { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.e-dur { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 700px) {
  .entry { grid-template-columns: 7em minmax(0, 1fr) 4.5em; }
  .e-desc { grid-column: 2 / -1; grid-row: 2; }
}

/* ---------- calendar ---------- */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .cal-layout { grid-template-columns: minmax(0, 1fr); } }
.cal-card { padding: 8px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 64px; gap: 4px; }
.cal-dow { text-align: center; font-size: 0.78rem; color: var(--muted); padding: 4px 0; }
.cal-day {
  display: flex; flex-direction: column; gap: 5px; min-height: 108px; min-width: 0;
  padding: 6px 7px; border-radius: 8px; text-decoration: none;
  background: var(--surface-2);
}
.cal-day:hover { box-shadow: inset 0 0 0 1px var(--axis); }
.cal-day.blank { background: color-mix(in oklab, var(--surface-2) 45%, var(--surface)); }
.cal-day.out { opacity: 0.45; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-top { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.cal-num { font-weight: 600; }
.cal-tot { font-size: 0.78rem; color: var(--ink-2); white-space: nowrap; }
.strip {
  position: relative; height: 8px; border-radius: 3px; flex: none;
  background:
    linear-gradient(90deg, transparent calc(25% - 0.5px), var(--grid) calc(25% - 0.5px), var(--grid) calc(25% + 0.5px), transparent calc(25% + 0.5px),
                           transparent calc(50% - 0.5px), var(--grid) calc(50% - 0.5px), var(--grid) calc(50% + 0.5px), transparent calc(50% + 0.5px),
                           transparent calc(75% - 0.5px), var(--grid) calc(75% - 0.5px), var(--grid) calc(75% + 0.5px), transparent calc(75% + 0.5px)),
    var(--surface);
}
.strip span { position: absolute; top: 0; bottom: 0; background: var(--c); min-width: 2px; border-radius: 1px; }
.cal-acts { list-style: none; margin: 0; padding: 0; font-size: 0.75rem; line-height: 1.35; }
.cal-acts li { display: flex; align-items: center; gap: 0; min-width: 0; }
.cal-acts .swatch { width: 7px; height: 7px; border-radius: 2px; margin-right: 4px; }
.cal-acts .n { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.cal-acts .v { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.cal-acts .more { color: var(--muted); }
.cal-week {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; font-size: 0.8rem; border-radius: 8px; text-align: center;
}
.cal-week:hover { background: var(--surface-2); }
.cal-week .short { display: none; }
@media (max-width: 700px) {
  .cal { grid-template-columns: repeat(7, minmax(0, 1fr)) 44px; gap: 2px; }
  .cal-day { min-height: 64px; padding: 4px; }
  .cal-acts, .cal-tot { display: none; }
}

/* ---------- activities ---------- */
.activities { max-width: 860px; }
.cat-card.archived, .act-list li.archived { opacity: 0.5; }
.cat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.cat-edit { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cat-name { font-weight: 600; width: 220px; }
.cat-tools { display: flex; gap: 6px; }
.color-pick { display: flex; flex-wrap: wrap; gap: 4px; border: 0; margin: 0; padding: 0; max-width: 100%; }
.color-pick label { cursor: pointer; display: block; }
.color-pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.color-pick span { display: block; width: 20px; height: 20px; border-radius: 6px; background: var(--c); }
.color-pick input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.color-pick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.act-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.act-list li { display: flex; align-items: center; gap: 8px; }
.act-edit { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.act-edit input { flex: 1.4; min-width: 0; }
.act-edit select { flex: 1; min-width: 0; }
.act-list .count { width: 6em; text-align: right; font-size: 0.8rem; white-space: nowrap; }
.act-add form, .cat-add { display: flex; gap: 8px; flex: 1; padding-left: 16px; }
.cat-add { padding-left: 0; }


/* ---------- accounts ---------- */
.usermenu { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.usermenu a, .linkish {
  text-decoration: none; padding: 6px 10px; border-radius: 8px; color: var(--ink-2);
  font: inherit; background: none; border: 0; cursor: pointer;
}
.usermenu a:hover, .linkish:hover { background: var(--surface-2); }
.usermenu a[aria-current] { color: var(--ink); background: var(--surface-2); font-weight: 600; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; text-align: center;
  background: var(--danger); color: #fff; font-size: 0.72rem; font-weight: 700; line-height: 18px;
}
.auth-box { max-width: 400px; margin: 48px auto; padding: 24px; }
.auth-box h1 { margin-bottom: 12px; }
.auth-box p { margin: 12px 0 0; }
.stack-form { display: flex; flex-direction: column; gap: 12px; }
.auth-box .stack-form { margin-top: 12px; }
.narrow-form { max-width: 360px; }
.err-box {
  color: var(--danger); background: color-mix(in oklab, var(--danger) 8%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--danger) 30%, transparent); border-radius: 8px; padding: 8px 12px;
}
.err-box ul { margin: 6px 0 0; padding-left: 20px; }
.account { max-width: 860px; }
.account p { margin: 0 0 12px; }
code { font-size: 0.85em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.data-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.import-form { display: flex; align-items: center; gap: 8px; }
.import-form input[type=file] { border: 0; padding: 0; min-height: 0; width: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.8rem; padding: 4px 8px; border-bottom: 1px solid var(--grid); }
.table td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .right { text-align: right; }
.table .num { font-variant-numeric: tabular-nums; }
.table .ua { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tr.dim td { color: var(--muted); }
.actions { white-space: nowrap; }
.actions form { display: inline-block; margin-left: 4px; }
.btn.small.primary { color: #fff; }
.table-wrap { overflow-x: auto; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; max-width: min(520px, calc(100vw - 32px));
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

/* ---------- theme toggle ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px;
  background: none; color: var(--ink-2); cursor: pointer;
}
.brand + .theme-toggle { margin-left: auto; }
.theme-toggle:hover { background: var(--surface-2); color: var(--ink); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: none; }
.theme-toggle[data-choice="system"] .i-system,
.theme-toggle[data-choice="light"] .i-light,
.theme-toggle[data-choice="dark"] .i-dark { display: block; }

/* ---------- small bits ---------- */
.tl-tabs { display: none; }
.now {
  font: inherit; font-size: 0.75rem; color: var(--accent); background: none; border: 0;
  padding: 0 2px; margin-left: 4px; cursor: pointer;
}
.now:hover { text-decoration: underline; }

/* ---------- phones ---------- */
@media (max-width: 700px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .page { padding: 12px 12px 24px; }
  .page-head { margin-bottom: 12px; }
  h1 { font-size: 1.1rem; }
  .card { padding: 12px; margin-bottom: 12px; }

  /* top bar: one row; the main pages move to a tab bar at the bottom */
  .topbar { height: 48px; gap: 4px; padding: 0 8px 0 12px; }
  .brand { font-size: 0; gap: 0; }
  .usermenu .logout { display: none; }
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .mainnav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 0 4px; font-size: 0.7rem; border-radius: 8px;
  }
  .topbar .mainnav a[aria-current] { background: none; color: var(--accent); }
  .mainnav svg {
    display: block; width: 22px; height: 22px; fill: none; stroke: currentColor;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* iOS zooms into inputs with text under 16px */
  input, select, textarea { font-size: 16px; }

  .tiles { gap: 8px; margin-bottom: 12px; }
  .tile { padding: 8px 12px; }
  .tile-value { font-size: 1.15rem; }
  .tile.hero .tile-value { font-size: 1.5rem; }

  /* timeline: one day at a time, picked with the tabs (or a swipe) */
  .tl-tabs { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; margin-bottom: 10px; }
  .tl-tab {
    display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 0;
    font: inherit; font-size: 0.72rem; color: var(--ink-2); cursor: pointer;
    background: var(--surface-2); border: 0; border-radius: 8px;
  }
  .tl-tab .dom { font-size: 0.95rem; font-weight: 600; color: var(--ink); }
  .tl-tab .dtot { color: var(--muted); font-variant-numeric: tabular-nums; }
  .tl-tab.today .dom { color: var(--accent); }
  .tl-tab.sel { background: var(--accent); color: #fff; }
  .tl-tab.sel .dom, .tl-tab.sel .dtot { color: #fff; }
  .timeline { min-width: 0; grid-template-columns: 40px minmax(0, 1fr); grid-template-rows: var(--height); }
  .tl-corner, .tl-dayhead { display: none; }
  .tl-hours, .tl-lines, .tl-day { grid-row: 1; }
  .tl-lines { grid-column: 2; }
  .tl-day { grid-column: 2; border-right: 1px solid var(--grid); cursor: default; }
  .tl-day:not(.sel) { display: none; }
  .tl-block { font-size: 0.8rem; }  /* line-height stays 15px */

  .act-list { gap: 0; }
  .act-list li { flex-wrap: wrap; justify-content: flex-end; padding: 6px 0; border-bottom: 1px solid var(--grid); }
  .act-list li.act-add { border-bottom: 0; }
  .act-edit { flex: 1 1 100%; }
  .act-edit select { flex: 0 1 40%; }
  .act-add form { padding-left: 0; }
  .cat-name { width: 100%; }
  .cat-edit { flex: 1 1 100%; }

  .table .opt { display: none; }
  .actions { white-space: normal; }
  .actions form { margin: 2px 0 2px 4px; }
  .import-form { flex-wrap: wrap; }
  .import-form input[type=file] { max-width: 100%; }

  /* breakdown: numbers on the first line, the bar underneath */
  .bk-row, .breakdown:has(.bk-share + .bk-share) .bk-row {
    grid-template-columns: minmax(0, 1fr) auto 3em; row-gap: 3px;
  }
  .breakdown:has(.bk-share + .bk-share) .bk-row { grid-template-columns: minmax(0, 1fr) auto 3em 4.8em; }
  .bk-bar { grid-column: 1 / -1; grid-row: 2; }
  .bk-act .bk-bar { margin-left: 16px; }
  .bk-heads { display: none; }
  .colchart { padding-left: 26px; }
  .cal-week .long { display: none; }
  .cal-week .short { display: inline; }
  .colchart.dense .col-labels span:nth-child(even) { visibility: hidden; }
  .colchart.dense .col-val { display: none; }
  .colchart.dense .col.current .col-val { display: block; }
}

/* ---------- time zones ---------- */
.tz-chip {
  font-size: 0.75rem; color: var(--muted); text-decoration: none; margin-left: 8px;
  padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; white-space: nowrap;
}
.tz-chip:hover { color: var(--ink); }
.tz-banner { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
.tz-banner[hidden] { display: none; }
.tz-banner-actions { display: flex; gap: 8px; }
.tz-forms { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.tz-form { display: flex; gap: 8px; }
.tz-form select { width: auto; max-width: 260px; }
.js-device-tz[hidden] { display: none; }
@media (max-width: 700px) { .tz-chip { display: none; } }

/* ---------- goals ---------- */
.goals-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .goals-layout { grid-template-columns: minmax(0, 1fr); } }
.goals-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-content: start; }
.goals-list .card { margin-bottom: 0; }
.goals-list > .archived-goals, .goals-list > .empty-goals { grid-column: 1 / -1; }
.empty-goals p { margin: 6px 0 0; }
.archived-goals summary { cursor: pointer; color: var(--ink-2); padding: 4px 0 12px; }
.archived-goals[open] { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.archived-goals[open] summary { grid-column: 1 / -1; }
.goal-card.archived { opacity: 0.75; }
.goal-card { display: flex; flex-direction: column; justify-content: space-between; gap: 12px; }
.goal-actions { display: flex; gap: 6px; justify-content: flex-end; }

.goal { display: flex; flex-direction: column; gap: 6px; }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.goal-name { font-weight: 600; display: flex; align-items: center; min-width: 0; }
.goal-target { color: var(--ink-2); font-size: 0.85rem; white-space: nowrap; }
.goal-note { margin: 0; color: var(--ink-2); font-size: 0.85rem; }
.goal-bar {
  position: relative; height: 10px; border-radius: 999px;
  background: color-mix(in oklab, var(--c) 16%, var(--surface-2));
}
.goal-bar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--c); min-width: 2px; }
.goal-bar .pace {
  position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px;
  background: var(--ink); border-radius: 1px; box-shadow: 0 0 0 2px var(--surface);
}
.goal-figures { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 0.85rem; color: var(--ink-2); }
.goal-figures strong { color: var(--ink); }
.goal-status { white-space: nowrap; }
.state-reached .goal-status { color: light-dark(#006300, #0ca30c); font-weight: 600; }
.state-behind .goal-status { color: light-dark(#a35a00, #fab219); }
.goal-detail { margin: 0; font-size: 0.82rem; color: var(--muted); }
.goal-history-row { display: flex; align-items: flex-end; gap: 12px; margin-top: 4px; }
.goal-history {
  position: relative; flex: 1; height: 36px; display: flex; align-items: flex-end; gap: 3px;
  border-bottom: 1px solid var(--axis);
}
.goal-history .hcol { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 0; }
.goal-history .hbar { display: block; width: 100%; max-width: 18px; margin: 0 auto; min-height: 1px;
  border-radius: 3px 3px 0 0; background: color-mix(in oklab, var(--c) 35%, var(--surface)); }
.goal-history .hbar.hit { background: var(--c); }
.goal-history .target-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--muted); pointer-events: none; }
.goal-streak { font-size: 0.78rem; color: var(--muted); white-space: nowrap; text-align: right; }
.goal-streak strong { color: var(--ink-2); }

.goals-card .goal { padding: 8px 0; border-top: 1px solid var(--grid); }
.goals-card .goal:first-of-type { border-top: 0; padding-top: 0; }
.goal.compact .goal-bar { height: 8px; }
.goal.compact .goal-head { font-size: 0.9rem; }
.goals-card .card-head a { font-size: 0.85rem; text-decoration: none; }

.goal-form .until input:disabled { opacity: 0.45; }
.goal-form .until .when-total, .goal-form[data-period="total"] .until .when-not-total { display: none; }
.goal-form[data-period="total"] .until .when-total { display: inline; }
.btn.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.goal-amount, .goal-dates { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.measure-pick { border: 0; margin: 0; padding: 0; display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.measure-pick legend { float: left; width: 100%; font-size: 0.8rem; color: var(--ink-2); padding: 0; margin-bottom: 3px; }
.measure-pick label { display: flex; align-items: center; gap: 6px; }
.measure-pick input[type=radio] { width: auto; min-height: 0; }
.measure-pick .unit-input { flex: 1; min-width: 140px; }
.measure-pick .err { flex-basis: 100%; }
.goal-form[data-measure="time"] .unit-input, .goal-form .when-count, .goal-form[data-measure="count"] .when-time { display: none; }
.goal-form[data-measure="count"] .when-count { display: inline; }
.goal-form .when-total, .goal-form[data-period="total"] .when-recurring { display: none; }
.goal-form[data-period="total"] .when-total { display: inline; }
.quantity-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.quantity-fields:empty { display: none; }
.e-qty { color: var(--ink-2); font-size: 0.85em; white-space: nowrap; }
.goal-actions .spacer { flex: 1; }
.goal-actions .btn.small.icon { width: 28px; min-height: 26px; }
.unit-suggestions { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 0.78rem; color: var(--muted); }
.goal-form[data-measure="time"] .unit-suggestions { display: none; }
.chip {
  font: inherit; font-size: 0.78rem; color: var(--ink-2); cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px;
}
.chip:hover { color: var(--ink); border-color: var(--axis); }
.more-goals { display: block; padding-top: 8px; border-top: 1px solid var(--grid); font-size: 0.85rem; color: var(--ink-2); text-decoration: none; }
.more-goals:hover { color: var(--ink); }

/* ---------- goals on the Stats page ---------- */
.goal-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px 28px; }
.gstat { display: flex; flex-direction: column; gap: 10px; min-width: 0; padding-top: 12px; border-top: 1px solid var(--grid); }
.gstat-figures { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0; }
.gstat-figures div { min-width: 0; }
.gstat-figures dt { font-size: 0.75rem; color: var(--muted); }
.gstat-figures dd { margin: 0; font-weight: 600; font-size: 0.95rem; white-space: nowrap; }
.gstat-figures small { font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.gstat-bars {
  position: relative; height: 90px; display: flex; align-items: flex-end; gap: 2px;
  border-bottom: 1px solid var(--axis);
}
.gstat-bars .gcol { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 0; }
.gstat-bars .gbar { display: block; width: 100%; max-width: 24px; margin: 0 auto; min-height: 1px;
  border-radius: 4px 4px 0 0; background: color-mix(in oklab, var(--c) 35%, var(--surface)); }
.gstat-bars .gbar.hit { background: var(--c); }
.gstat-bars .gcol.current .gbar { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.gstat-bars .target-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--muted); pointer-events: none; z-index: 1; }
.gstat-labels, .burnup-axis { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); }
.day-grid-wrap { display: flex; flex-direction: column; gap: 6px; overflow-x: auto; }
.day-grid { display: grid; grid-template-rows: repeat(7, 11px); grid-template-columns: repeat(var(--weeks), 11px); gap: 2px; }
.dcell { display: inline-block; width: 11px; height: 11px; border-radius: 2px; background: var(--surface-2); }
.dcell.hit { background: var(--c); }
.dcell.some { background: color-mix(in oklab, var(--c) 35%, var(--surface)); }
.dcell.current { box-shadow: 0 0 0 1.5px var(--ink-2); }
.day-grid-key { display: flex; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--muted); }
.day-grid-key .dcell { margin-left: 6px; }
.burnup svg { display: block; width: 100%; height: 140px; overflow: visible; }
.burnup line, .burnup polyline { vector-effect: non-scaling-stroke; fill: none; }
.burnup .target { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.burnup .pace { stroke: var(--axis); stroke-width: 1.5; stroke-dasharray: 2 3; }
.burnup .actual { stroke: var(--c); stroke-width: 2; stroke-linejoin: round; }
.burnup .area { fill: var(--c); opacity: 0.12; stroke: none; }
@media (max-width: 700px) { .goal-stats { grid-template-columns: minmax(0, 1fr); } }

/* ---------- goals summary (Stats) and goal detail ---------- */
a.goal-name { color: inherit; text-decoration: none; }
a.goal-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.gstat-figures.summary { margin-bottom: 14px; }
.goal-rows { list-style: none; margin: 0; padding: 0; }
.goal-rows li + li { border-top: 1px solid var(--grid); }
.goal-row {
  display: grid; grid-template-columns: minmax(120px, 1.2fr) minmax(90px, 1fr) minmax(120px, 1.4fr) 3em 1em;
  align-items: center; gap: 12px; padding: 8px 4px; text-decoration: none; color: inherit; border-radius: 6px;
}
.goal-row:hover { background: var(--surface-2); }
.goal-row .goal-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal-row-target { font-size: 0.85rem; color: var(--ink-2); white-space: nowrap; }
.goal-row-figure { text-align: right; font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.goal-row-more { color: var(--muted); }
.goal-bar.thin { height: 6px; }
.ticks { display: flex; gap: 3px; }
.tick { width: 10px; height: 10px; border-radius: 3px; background: var(--surface-2); flex: none; }
.tick.some { background: color-mix(in oklab, var(--c) 35%, var(--surface)); }
.tick.hit { background: var(--c); }
.tick.current { box-shadow: 0 0 0 1.5px var(--ink-2) inset; }
.goal-detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 16px; align-items: start; }
.goal-detail-layout .card { margin-bottom: 16px; }
.goal-detail-layout .gstat-figures { margin-bottom: 14px; }
.page-head h1 .swatch { width: 12px; height: 12px; }
.goal-table tr.current td { background: color-mix(in oklab, var(--accent) 5%, transparent); }
.hit-mark { color: light-dark(#006300, #0ca30c); font-weight: 600; }
@media (max-width: 1000px) { .goal-detail-layout { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px) {
  .goal-row { grid-template-columns: minmax(0, 1fr) auto 1em; row-gap: 4px; }
  .goal-row-target { grid-column: 1; grid-row: 2; }
  .goal-row-viz { grid-column: 1 / 3; grid-row: 3; }
  .goal-row-figure { grid-column: 2; grid-row: 1; }
  .goal-row-more { grid-column: 3; grid-row: 1 / 3; }
}

.goal-row-viz .goal-bar { display: block; }
.goal-rows-head {
  display: grid; grid-template-columns: minmax(120px, 1.2fr) minmax(90px, 1fr) minmax(120px, 1.4fr) 3em 1em;
  gap: 12px; padding: 0 4px 6px; font-size: 0.75rem; color: var(--muted);
}
.goal-rows-head span:nth-child(4) { text-align: right; white-space: nowrap; }
.goal-rows li.goal-rows-head + li { border-top: 1px solid var(--grid); }
@media (max-width: 700px) { .goal-rows-head { display: none; } }
