/* Tidy — light by default (Things is a light app; the dark theme is
   there for the truck at night). Vanilla CSS, no build step.

   The whole look rests on three things: a warm off-white sidebar against a
   pure-white content pane, one accent blue used sparingly, and a lot of empty
   space. Resist adding borders — separation here comes from spacing and
   background tone, not lines. */

:root {
  --bg:            #ffffff;
  --bg-sidebar:    #f3f3f5;
  --bg-hover:      #f6f6f8;
  --bg-sel:        #dbeafe;   /* selected row */
  --bg-sunken:     #fafafb;
  --card:          #ffffff;

  --text:          #1c1c1e;
  --text-2:        #6c6c72;
  --text-3:        #a3a3aa;
  --line:          #e6e6ea;
  --line-2:        #d9d9df;

  --accent:        #2b72d4;
  --accent-soft:   #e8f1fd;
  --blue:          #2b72d4;
  --yellow:        #f0b429;
  --green:         #34a853;
  --teal:          #17a2a2;
  --sand:          #b99a5b;
  --red:           #e0453e;
  --purple:        #8e5bd4;

  --radius:        10px;
  --radius-sm:     6px;
  --shadow-card:   0 1px 3px rgba(0,0,0,.07), 0 6px 20px rgba(0,0,0,.07);
  --shadow-pop:    0 8px 34px rgba(0,0,0,.16), 0 1px 3px rgba(0,0,0,.10);
  --sb-w:          252px;

  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto,
          'Helvetica Neue', Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg:            #1c1c1e;
  --bg-sidebar:    #161618;
  --bg-hover:      #26262a;
  --bg-sel:        #24405e;
  --bg-sunken:     #202024;
  --card:          #26262a;

  --text:          #f2f2f5;
  --text-2:        #9a9aa2;
  --text-3:        #6e6e76;
  --line:          #303036;
  --line-2:        #3c3c44;

  --accent:        #4a9bf0;
  --accent-soft:   #1e3550;
  --blue:          #4a9bf0;
  --shadow-card:   0 1px 3px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  --shadow-pop:    0 8px 34px rgba(0,0,0,.55), 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
/* [hidden] must always beat author display rules, or overlays get stuck open. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14.5px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
/* No grey flash on tap, and no 300ms wait for a double-tap that never comes. */
button, a, .task, .pop-item, .pal-item, .proj-row, .cal-day, .chk-box, .tick {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
/* Sidebar entries and inline links are anchors so they get real URLs (middle
   click, copy link), but they must not look like web links. */
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.015em; }
::selection { background: var(--bg-sel); }

/* ── Boot / gate ───────────────────────────────────────────────────────── */
.fullscreen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 100; }
.spinner { width: 26px; height: 26px; border: 2.5px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.gate-card { text-align: center; max-width: 340px; padding: 32px; }
.gate-card h1 { font-size: 25px; margin: 14px 0 2px; }
.gate-card .tagline { color: var(--text-3); font-size: 14px; margin: 0 0 18px; letter-spacing: .01em; }
.gate-card p { color: var(--text-2); margin: 0 0 22px; }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.shell { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: var(--sb-w); flex: 0 0 var(--sb-w);
  background: var(--bg-sidebar);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  user-select: none;
}
.sb-top { height: 46px; display: flex; align-items: center; gap: 8px; padding: 0 14px; flex: 0 0 46px; }
.sb-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; }
.sb-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.sb-group { margin-bottom: 16px; }
.sb-group:empty { display: none; }
.sb-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); padding: 4px 8px 5px; }

/* One row style for every sidebar entry — views, areas, projects, people. */
.sb-row {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 5px 8px; border: 0; background: none;
  border-radius: var(--radius-sm); cursor: pointer; text-align: left;
  color: var(--text); font-size: 14px; line-height: 1.3;
}
.sb-row:hover { background: rgba(0,0,0,.045); }
:root[data-theme="dark"] .sb-row:hover { background: rgba(255,255,255,.06); }
.sb-row.active { background: var(--bg-sel); font-weight: 600; }
.sb-row .sb-icon { width: 17px; height: 17px; flex: 0 0 17px; display: grid; place-items: center; }
.sb-row .sb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-row .sb-count { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.sb-row.active .sb-count { color: var(--accent); }
.sb-row.indent { padding-left: 24px; }
.sb-row.drop-target { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }

.sb-foot { flex: 0 0 auto; padding: 8px; display: flex; gap: 6px; align-items: center; border-top: 1px solid var(--line); }
.sb-newbtn { flex: 1; display: flex; align-items: center; gap: 7px; padding: 6px 9px; border: 0; background: none; color: var(--text-2); border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; font-weight: 500; }
.sb-newbtn:hover { background: rgba(0,0,0,.05); color: var(--text); }
:root[data-theme="dark"] .sb-newbtn:hover { background: rgba(255,255,255,.07); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); position: relative; }
.topbar { height: 46px; flex: 0 0 46px; display: flex; align-items: center; gap: 8px; padding: 0 16px; }
.topbar-spacer { flex: 1; }
.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.view { max-width: 760px; margin: 0 auto; padding: 4px 30px 220px; }
/* The calendar layouts use the whole window — a month grid squeezed into a
   reading column wastes the one thing a calendar is for. The task list below
   the grid in Split keeps its reading width, centred under it. */
.view.wide { max-width: none; padding-left: 26px; padding-right: 26px; }
.view.wide .task-list,
.view.wide .group-head,
.view.wide .empty { max-width: 820px; margin-left: auto; margin-right: auto; }
/* ...except inside the split, where the list already has its own column. */
.view.wide .cal-split-list .task-list,
.view.wide .cal-split-list .group-head,
.view.wide .cal-split-list .empty { max-width: none; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.icon-btn { width: 30px; height: 30px; border-radius: var(--radius-sm); border: 0; background: none; color: var(--text-2); cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.chip-btn { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text-2); border-radius: 7px; cursor: pointer; font-size: 13px; }
.chip-btn:hover { border-color: var(--accent); color: var(--text); }
.kbd { font-size: 11.5px; color: var(--text-3); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); cursor: pointer; font-size: 13.5px; font-weight: 500; }
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.danger { color: var(--red); border-color: var(--line-2); }
.btn.danger:hover { background: rgba(224,69,62,.09); }
.btn.sm { height: 27px; padding: 0 10px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff; background: var(--text-3);
  flex: 0 0 26px; letter-spacing: .01em;
}
.avatar.sm { width: 19px; height: 19px; flex-basis: 19px; font-size: 9px; }
.avatar.lg { width: 34px; height: 34px; flex-basis: 34px; font-size: 13px; }
.avatar.ghost { background: none; border: 1.5px dashed var(--line-2); color: var(--text-3); }

/* ── Page header ───────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-start; gap: 12px; padding: 22px 0 10px; }
.page-head .ph-icon { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; margin-top: -2px; }
.page-head h1 { font-size: 27px; line-height: 1.15; }
.page-head .ph-sub { color: var(--text-2); font-size: 13.5px; margin-top: 3px; }
.page-head .ph-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* ── Task rows ─────────────────────────────────────────────────────────── */
.task-list { margin-top: 4px; }

.task {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 5px 8px; border-radius: var(--radius);
  cursor: default; position: relative;
}
.task:hover { background: var(--bg-hover); }
.task.selected { background: var(--bg-sel); }
.task.dragging { opacity: .3; }
/* The clone that follows the pointer during a drag. pointer-events:none is
   load-bearing: elementFromPoint has to see through it to the row underneath. */
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 80;
  pointer-events: none; width: auto;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); opacity: .96;
  transform: scale(1.02); transform-origin: left center;
}
.task.drop-above { box-shadow: inset 0 2px 0 var(--accent); }
.task.drop-below { box-shadow: inset 0 -2px 0 var(--accent); }

/* Rounded-square checkbox, Things style — not a circle. */
.tick {
  width: 17px; height: 17px; flex: 0 0 17px; margin-top: 2px;
  border: 1.5px solid var(--line-2); border-radius: 5px;
  background: var(--bg); cursor: pointer; display: grid; place-items: center;
  padding: 0; transition: background .12s, border-color .12s;
}
.tick:hover { border-color: var(--accent); }
.tick svg { opacity: 0; }
.tick.done { background: var(--accent); border-color: var(--accent); }
.tick.done svg { opacity: 1; }
.tick.canceled { background: var(--text-3); border-color: var(--text-3); }
.tick.canceled svg { opacity: 1; }

.task-main { flex: 1; min-width: 0; }
.task-title { font-size: 14.5px; line-height: 1.35; word-break: break-word; }
.task.done .task-title { color: var(--text-3); }
.task.done .task-title span.t { text-decoration: line-through; }

/* The metadata line under a title: dates, project, checklist, badges. */
.task-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; font-size: 12.5px; color: var(--text-2); }
.task-meta .m { display: inline-flex; align-items: center; gap: 4px; }
.task-meta .m.overdue { color: var(--red); font-weight: 600; }
.task-meta .m.due-soon { color: var(--yellow); font-weight: 600; }
.task-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; margin-top: 1px; }

.tag-pill { display: inline-flex; align-items: center; height: 18px; padding: 0 7px; border-radius: 9px; font-size: 11.5px; font-weight: 600; background: var(--bg-sunken); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
:root[data-theme="dark"] .tag-pill { background: var(--bg-hover); }

/* ── Expanded task editor (click a row -> it becomes a card in place) ──── */
.task-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow-card); padding: 12px 14px 10px;
  margin: 6px 0; position: relative;
}
.task-card .tc-head { display: flex; gap: 10px; align-items: flex-start; }
.task-card .tc-title {
  flex: 1; border: 0; background: none; font-size: 15.5px; font-weight: 600;
  padding: 0; outline: none; resize: none; overflow: hidden; line-height: 1.35;
  min-height: 21px; font-family: inherit; color: var(--text);
}
.task-card .tc-notes {
  width: 100%; border: 0; background: none; outline: none; resize: none;
  font-size: 14px; color: var(--text-2); margin-top: 6px; padding: 0;
  line-height: 1.5; overflow: hidden; min-height: 20px; font-family: inherit;
}
.task-card .tc-notes::placeholder, .task-card .tc-title::placeholder { color: var(--text-3); }
.tc-section { margin-top: 10px; }
.tc-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.tc-foot .spacer { flex: 1; }

.mini-btn { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; border-radius: 7px; border: 1px solid transparent; background: var(--bg-sunken); color: var(--text-2); cursor: pointer; font-size: 12.5px; font-weight: 500; }
.mini-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--line-2); }
.mini-btn.on { background: var(--accent-soft); color: var(--accent); }
.mini-btn.danger:hover { color: var(--red); border-color: var(--red); }
:root[data-theme="dark"] .mini-btn { background: rgba(255,255,255,.06); }

/* Checklist inside the card */
.chk-item { display: flex; align-items: center; gap: 9px; padding: 3px 0; }
.chk-item .chk-box { width: 15px; height: 15px; flex: 0 0 15px; border: 1.5px solid var(--line-2); border-radius: 4px; background: var(--bg); cursor: pointer; display: grid; place-items: center; padding: 0; }
.chk-item .chk-box.done { background: var(--text-3); border-color: var(--text-3); }
.chk-item .chk-box svg { opacity: 0; }
.chk-item .chk-box.done svg { opacity: 1; }
/* Not scoped to .chk-item — the comment box reuses this class, and without a
   standalone rule it kept the browser's default focus ring. */
.chk-text { flex: 1; border: 0; background: none; outline: none; font-size: 13.5px; padding: 0; }
.chk-text:focus { outline: none; }
.chk-item.done input.chk-text { color: var(--text-3); text-decoration: line-through; }
.chk-item .chk-del { opacity: 0; }
.chk-item:hover .chk-del { opacity: 1; }

/* Comments + activity */
.cmt { display: flex; gap: 9px; padding: 7px 0; }
.cmt-body { flex: 1; min-width: 0; }
.cmt-who { font-size: 12.5px; font-weight: 600; }
.cmt-when { font-size: 11.5px; color: var(--text-3); font-weight: 400; margin-left: 6px; }
.cmt-text { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; margin-top: 1px; }
.act-line { font-size: 12.5px; color: var(--text-3); padding: 2px 0; display: flex; gap: 6px; }

/* Attachments */
.att-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.att { position: relative; width: 74px; }
.att a { display: block; }
.att img { width: 74px; height: 74px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.att .att-file { width: 74px; height: 74px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-sunken); display: grid; place-items: center; font-size: 10.5px; color: var(--text-2); text-align: center; padding: 6px; overflow: hidden; word-break: break-all; }
.att .att-x { position: absolute; top: -6px; right: -6px; width: 19px; height: 19px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); cursor: pointer; font-size: 12px; line-height: 1; opacity: 0; }
.att:hover .att-x { opacity: 1; }

/* ── Group headings inside a list ──────────────────────────────────────── */
.group-head { display: flex; align-items: center; gap: 8px; margin: 22px 0 4px; padding: 0 8px 5px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 700; color: var(--text-2); letter-spacing: .01em; }
.group-head:first-child { margin-top: 6px; }
.group-head .gh-count { margin-left: auto; font-weight: 500; color: var(--text-3); font-variant-numeric: tabular-nums; }
.group-head.big { font-size: 15px; color: var(--text); border-bottom-color: var(--line-2); }

/* Project rows shown inside a list (Areas, Upcoming) */
.proj-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius); cursor: pointer; }
.proj-row:hover { background: var(--bg-hover); }
.proj-row .pr-title { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-row .pr-sub { font-size: 12.5px; color: var(--text-2); }

/* ── Empty states ──────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 60px 20px; color: var(--text-3); }
.empty .e-icon { opacity: .5; margin-bottom: 10px; }
.empty .e-title { font-size: 15px; color: var(--text-2); font-weight: 600; }
.empty .e-sub { font-size: 13.5px; margin-top: 4px; }

/* ── Magic Plus ────────────────────────────────────────────────────────── */
.magic-plus {
  position: absolute; right: 26px; bottom: 26px;
  width: 50px; height: 50px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; cursor: pointer;
  box-shadow: 0 4px 14px rgba(43,114,212,.42); display: grid; place-items: center;
  z-index: 20; transition: transform .12s ease;
}
.magic-plus:hover { transform: scale(1.07); }
.magic-plus:active { transform: scale(.94); }

/* ── Overlays ──────────────────────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 60; }
:root[data-theme="dark"] .scrim { background: rgba(0,0,0,.5); }

.popover {
  /* Above .modal (70): a popover is always opened FROM something, and that
     something is sometimes a modal — the icon picker, for one. */
  position: fixed; z-index: 78; background: var(--card);
  border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow-pop);
  padding: 6px; min-width: 210px; max-height: 70vh; overflow: auto;
}
.pop-item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 9px; border: 0; background: none; border-radius: 7px; cursor: pointer; text-align: left; font-size: 13.5px; color: var(--text); }
.pop-item:hover { background: var(--bg-hover); }
.pop-item.active { background: var(--bg-sel); font-weight: 600; }
.pop-item .pi-key { margin-left: auto; font-size: 11.5px; color: var(--text-3); }
.pop-sep { height: 1px; background: var(--line); margin: 5px 6px; }
.pop-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); padding: 7px 9px 4px; }
.pop-input { width: 100%; height: 32px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--bg); padding: 0 10px; outline: none; margin: 4px 0 6px; }
.pop-input:focus { border-color: var(--accent); }

/* Calendar inside the When popover */
.cal { padding: 4px 6px 8px; }
.cal-head { display: flex; align-items: center; gap: 6px; padding: 2px 2px 8px; }
.cal-head .cal-title { flex: 1; text-align: center; font-weight: 600; font-size: 13.5px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: 10.5px; font-weight: 700; color: var(--text-3); padding-bottom: 3px; }
.cal-day { height: 28px; border: 0; background: none; border-radius: 7px; cursor: pointer; font-size: 12.5px; color: var(--text); font-variant-numeric: tabular-nums; }
.cal-day:hover { background: var(--bg-hover); }
.cal-day.other { color: var(--text-3); }
.cal-day.today { font-weight: 700; color: var(--accent); }
.cal-day.sel { background: var(--accent); color: #fff; font-weight: 600; }

.modal {
  position: fixed; z-index: 70; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: min(480px, 94vw); max-height: 88vh; overflow: auto;
  background: var(--card); border-radius: 13px; box-shadow: var(--shadow-pop);
}
.modal-head { padding: 16px 18px 4px; }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 10px 18px 4px; }
.modal-foot { padding: 14px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; height: 34px; border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--bg); padding: 0 10px; outline: none;
}
.field textarea { height: auto; min-height: 70px; padding: 8px 10px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.form-err { color: var(--red); font-size: 13px; margin-bottom: 10px; }

/* ⌘K palette */
.palette {
  position: fixed; z-index: 70; top: 14vh; left: 50%; transform: translateX(-50%);
  width: min(560px, 94vw); background: var(--card); border-radius: 13px;
  box-shadow: var(--shadow-pop); overflow: hidden;
}
.palette input { width: 100%; height: 50px; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 0 18px; font-size: 16px; outline: none; }
.palette-results { max-height: 54vh; overflow-y: auto; padding: 6px; }
.pal-item { display: flex; align-items: center; gap: 10px; padding: 8px 11px; border-radius: 8px; cursor: pointer; }
.pal-item.active { background: var(--bg-sel); }
.pal-item .pal-sub { margin-left: auto; font-size: 12px; color: var(--text-3); }

/* Toasts */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-pop); font-size: 13.5px; max-width: 92vw; animation: rise .18s ease; }
.toast button { border: 0; background: none; color: var(--blue); font-weight: 700; cursor: pointer; font-size: 13.5px; }
:root[data-theme="dark"] .toast { background: #f2f2f5; color: #1c1c1e; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* Progress pie for projects */
.pie { display: block; }
.pie circle.bg { fill: none; stroke: var(--line-2); }
/* The wedge's rotation is an SVG transform attribute (see pie() in app.js),
   not a CSS one — CSS transform-origin resolves against the view box. */
.pie circle.fg { fill: none; stroke: var(--accent); }

/* ── Mobile ────────────────────────────────────────────────────────────── */
.only-mobile { display: none !important; }
@media (max-width: 780px) {
  .only-mobile { display: inline-grid !important; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 65;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: none; }
  .view { padding: 4px 16px 200px; }
  .magic-plus { right: 18px; bottom: 18px; }
  .palette { top: 6vh; }
}


/* ── Touch devices ─────────────────────────────────────────────────────────
   Keyed off `pointer: coarse` rather than a width breakpoint: a tablet in
   landscape is still a finger, and a narrow desktop window is still a mouse.

   The visual design does not change much — Things' restraint is the point —
   but every hit area grows to roughly 44px, the platform minimum. Where a
   control has to stay visually small (the checkbox), the box stays small and
   an invisible ::after does the catching. */
@media (pointer: coarse) {
  .task { padding: 9px 8px; gap: 14px; }

  /* The checkbox is the most-tapped control in the app and gets tapped with
     gloves on. It keeps its look but catches a 44px box — expanded left and
     vertically into the row's own dead space, and rightward only as far as
     the gap to the title, so a tap meant for the title never completes it. */
  .tick { width: 22px; height: 22px; flex-basis: 22px; border-radius: 6px; position: relative; }
  .tick::after { content: ''; position: absolute; inset: -11px -10px -11px -11px; }

  .icon-btn { width: 42px; height: 42px; }
  .chip-btn { height: 40px; padding: 0 14px; }
  .mini-btn { height: 38px; padding: 0 13px; font-size: 13.5px; }
  .btn { height: 42px; padding: 0 18px; }
  .btn.sm { height: 36px; }
  .avatar { width: 30px; height: 30px; flex-basis: 30px; font-size: 12px; }
  .avatar.sm { width: 24px; height: 24px; flex-basis: 24px; font-size: 10px; }

  .sb-row { padding: 10px 10px; }
  .pop-item { padding: 11px 11px; }
  .pal-item { padding: 12px 12px; }
  .cal-day { height: 40px; font-size: 14px; }
  .cal-dow { font-size: 12px; }
  .popover { min-width: 260px; padding: 8px; }

  /* Checklist rows and their delete button — the hover-to-reveal trick has no
     equivalent on touch, so the delete is simply always visible. */
  .chk-item { padding: 7px 0; }
  .chk-item .chk-box { width: 20px; height: 20px; flex-basis: 20px; }
  .chk-item .chk-del { opacity: 1; }
  .att .att-x { opacity: 1; }

  /* The keyboard hint is noise on a device with no ⌘ key. */
  #search-btn .kbd { display: none; }
  #search-btn { padding: 0 12px; }

  /* Inputs below 16px make iOS Safari zoom the whole page on focus. */
  .field input, .field select, .field textarea, .pop-input,
  .palette input, .chk-text, .tc-title, .tc-notes { font-size: 16px; }
}

/* Notched phones: keep the floating button and the end of the list clear of
   the home indicator. */
@supports (padding: env(safe-area-inset-bottom)) {
  .magic-plus { bottom: calc(18px + env(safe-area-inset-bottom)); }
  .view { padding-bottom: calc(200px + env(safe-area-inset-bottom)); }
  .sidebar { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── Offline ───────────────────────────────────────────────────────────── */
.offline-bar {
  flex: 0 0 auto; padding: 7px 16px; font-size: 13px; font-weight: 600;
  text-align: center; border-bottom: 1px solid var(--line);
}
.offline-bar.off { background: var(--bg-sunken); color: var(--text-2); }
.offline-bar.syncing { background: var(--accent-soft); color: var(--accent); }
:root[data-theme="dark"] .offline-bar.off { background: var(--bg-hover); }
/* A row carrying edits the server hasn't seen yet. */
.pending-chip {
  color: var(--text-3); font-style: italic;
}

/* ── Business / Personal filter ────────────────────────────────────────── */
.realm-btn { gap: 6px; font-weight: 600; }
.realm-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; background: var(--text-3); }
/* A space's colour is set inline from its own record — see renderSpaceButton. */
.realm-btn.filtered { border-color: var(--accent); color: var(--text); }

/* Sidebar group labels carry the same dot when both realms are on screen. */
.sb-label .realm-dot { display: inline-block; margin-right: 2px; flex: 0 0 8px; }

@media (max-width: 780px) {
  /* Keep the label — the dot alone is not self-explanatory — but let it shrink. */
  .realm-btn { padding: 0 9px; }
}

/* ── Demo mode ─────────────────────────────────────────────────────────── */
.demo-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--red); color: #fff;
  font-size: 13px; font-weight: 500;
}
.demo-bar strong { font-weight: 700; }
.demo-bar .demo-btn {
  margin-left: auto; border: 1px solid rgba(255,255,255,.55); background: transparent;
  color: #fff; border-radius: 7px; padding: 5px 11px; cursor: pointer;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.demo-bar .demo-btn + .demo-btn { margin-left: 0; }
.demo-bar .demo-btn:hover { background: rgba(255,255,255,.16); }
.demo-bar .demo-btn.primary { background: #fff; color: var(--red); border-color: #fff; }
@media (max-width: 780px) {
  .demo-bar { font-size: 12.5px; padding: 8px 12px; }
  .demo-bar span { flex: 1 1 100%; }
  .demo-bar .demo-btn { margin-left: 0; flex: 1; }
}
@media (pointer: coarse) { .demo-bar .demo-btn { padding: 9px 12px; } }

/* ── Sidebar: collapsible groups ───────────────────────────────────────── */
.sb-item { display: flex; align-items: stretch; }
.sb-item .sb-row { flex: 1; min-width: 0; }
.sb-twisty {
  width: 16px; flex: 0 0 16px; border: 0; background: none; padding: 0;
  color: var(--text-3); cursor: pointer; display: grid; place-items: center;
  transition: transform .13s ease;
}
.sb-twisty.spacer { cursor: default; }
.sb-twisty:not(.spacer):hover { color: var(--text); }
.sb-twisty.open { transform: rotate(90deg); }
.sb-group-head { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.sb-group-head .sb-twisty { width: 14px; flex-basis: 14px; }
.sb-group-head:hover { color: var(--text-2); }

/* ── Icons ─────────────────────────────────────────────────────────────── */
.ic { display: block; }
.sb-icon .ic { opacity: .85; }
.sb-row.active .sb-icon .ic { opacity: 1; }

.icon-pick {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 10px; border: 1px solid var(--line-2);
  border-radius: 8px; background: var(--bg); color: var(--text); cursor: pointer;
}
.icon-pick:hover { border-color: var(--accent); }
.icon-pick-caret { color: var(--text-3); transform: rotate(90deg); display: grid; place-items: center; }

.icon-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  padding: 2px; max-width: 320px;
}
.icon-cell {
  width: 34px; height: 34px; border: 0; background: none; border-radius: 7px;
  color: var(--text-2); cursor: pointer; display: grid; place-items: center;
}
.icon-cell:hover { background: var(--bg-hover); color: var(--text); }
.icon-cell.active { background: var(--bg-sel); color: var(--accent); }

/* ── Colour swatches ───────────────────────────────────────────────────── */
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0;
}
.swatch.active { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--bg); }

@media (pointer: coarse) {
  .sb-twisty { width: 30px; flex-basis: 30px; }
  .icon-cell { width: 42px; height: 42px; }
  .icon-grid { grid-template-columns: repeat(6, 1fr); max-width: 300px; }
  .swatch { width: 36px; height: 36px; }
  .icon-pick { height: 42px; }
}

/* ── Calendar ──────────────────────────────────────────────────────────── */
.cal-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: 26px; align-items: start; }
.cal-split-list { position: sticky; top: 8px; }
.cal-split-list .group-head { margin-top: 0; }
/* Below this the two columns are narrower than either wants; stack them. */
@media (max-width: 1000px) {
  .cal-split { grid-template-columns: 1fr; gap: 4px; }
  .cal-split-list { position: static; }
}
.seg-switch { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg-switch button {
  border: 0; background: var(--bg); color: var(--text-2); cursor: pointer;
  padding: 6px 11px; font-size: 12.5px; font-weight: 600;
}
.seg-switch button + button { border-left: 1px solid var(--line-2); }
.seg-switch button:hover { background: var(--bg-hover); color: var(--text); }
.seg-switch button.on { background: var(--accent); color: #fff; }

.cal-month { margin: 6px 0 18px; }
.cal-month-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.cal-month-title { font-size: 16px; font-weight: 700; letter-spacing: -.01em; min-width: 150px; }
.cal-month-head .mini-btn { margin-left: auto; }
.cal-dows { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.cal-dows span { font-size: 11px; font-weight: 700; color: var(--text-3); text-align: center; letter-spacing: .04em; }
.cal-cells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }

.cal-cell {
  position: relative; border: 1px solid transparent; background: var(--bg-sunken);
  border-radius: 9px; cursor: pointer; padding: 5px 5px 4px; min-height: 54px;
  display: flex; flex-direction: column; align-items: stretch; gap: 3px; text-align: left;
  font: inherit; color: inherit; overflow: hidden;
}
.cal-cell.dense { min-height: 96px; }
.view.wide .cal-cell { min-height: 74px; }
.view.wide .cal-cell.dense { min-height: 122px; }
.cal-cell:hover { border-color: var(--line-2); }
.cal-cell.outside { opacity: .42; }
.cal-cell.today .cc-num { background: var(--accent); color: #fff; }
.cal-cell.sel { border-color: var(--accent); background: var(--accent-soft); }
.cc-num {
  font-size: 12px; font-weight: 650; align-self: flex-start;
  min-width: 19px; height: 19px; border-radius: 50%;
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.cc-dots { display: flex; gap: 3px; flex-wrap: wrap; padding: 0 1px; }
.cc-dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.cc-task {
  display: flex; align-items: center; gap: 4px; font-size: 11px; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2);
}
.cc-task.done { text-decoration: line-through; opacity: .55; }
.cc-stripe { width: 3px; height: 11px; border-radius: 2px; flex: 0 0 3px; }
.cc-more { font-size: 10.5px; color: var(--text-3); }
.cc-flag { position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--red); }

@media (max-width: 780px) {
  .cal-cell { min-height: 44px; padding: 4px 3px; }
  .cal-cell.dense { min-height: 70px; }
  .cc-task { font-size: 10px; }
  .cal-month-title { font-size: 15px; min-width: 0; flex: 1; }
  .seg-switch button { padding: 6px 9px; font-size: 12px; }
}
@media (pointer: coarse) {
  .cal-cell { min-height: 52px; }
  .seg-switch button { padding: 9px 12px; }
}

/* ── Sharing ───────────────────────────────────────────────────────────── */
.share-switch { display: flex; width: 100%; }
.share-switch button { flex: 1; }
.share-people {
  margin-top: 10px; display: flex; flex-direction: column; gap: 2px;
  max-height: 190px; overflow-y: auto;
}
/* Each person is a <label> inside a .field, and `.field label` sets
   display:block with form-label typography. This has to out-specify that or
   the checkbox, avatar and name stack vertically. */
.field label.share-person {
  display: flex; align-items: center; gap: 9px; padding: 6px 7px;
  border-radius: 7px; cursor: pointer;
  font-size: 13.5px; font-weight: 500; color: var(--text); margin-bottom: 0;
}
.field label.share-person:hover { background: var(--bg-hover); }
.field label.share-person input { width: auto; height: auto; margin: 0; flex: 0 0 auto; }
/* A quiet marker on lists other people can see. Private is the default and
   carries no badge — a mark on every row would say nothing. */
/* Both the status and the control. Faint when private, lit when shared. */
.share-mark {
  display: inline-flex; align-items: center; gap: 3px; flex: 0 0 auto;
  border: 0; background: none; padding: 2px 3px; border-radius: 5px;
  color: var(--text-3); opacity: .38; cursor: pointer;
}
.sb-row:hover .share-mark { opacity: .85; }
.share-mark:hover { background: rgba(0,0,0,.07); opacity: 1; color: var(--text); }
:root[data-theme="dark"] .share-mark:hover { background: rgba(255,255,255,.1); }
.share-mark.on { opacity: 1; color: var(--accent); }
.share-count { font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (pointer: coarse) { .share-mark { padding: 7px 5px; opacity: .7; } }

/* ── API tokens ────────────────────────────────────────────────────────── */
.token-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.token-row:last-child { border-bottom: 0; }
.token-main { flex: 1; min-width: 0; }
.token-name { font-weight: 600; font-size: 13.5px; }
.token-meta { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.token-meta code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.token-secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  background: var(--bg-sunken); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 10px 12px; word-break: break-all; user-select: all;
}
