:root {
  /* Catppuccin Mocha — same tokens as the Mac app and SketchyBar */
  --bg: #1e1e2e;
  --surface: #181825;
  --surface-2: #313244;
  --ink: #cdd6f4;
  --muted: #7f849c;
  --faint: #6c7086;
  --line: #45475a;
  --accent: #89b4fa;
  --accent-ink: #1e1e2e;
  --accent-soft: #313244;
  --warn: #fab387;
  --warn-soft: rgba(250, 179, 135, .14);
  --danger: #f38ba8;
  --danger-soft: rgba(243, 139, 168, .14);
  --ok: #a6e3a1;
  --mauve: #cba6f7;
  --radius: 10px;
  --shadow: none;
  --font: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  /* iOS home-screen apps can report an inflated bottom inset at launch; 34px is the real home-indicator height */
  --safe-bottom: min(env(safe-area-inset-bottom), 34px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom on iOS */
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

/* ── login ─────────────────────────────────────────── */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 4px 0 0; font-size: 26px; letter-spacing: -.02em; }
.login-card p { margin: 0; color: var(--muted); }
.login-mark, .brand-mark {
  width: 44px; height: 44px; border-radius: 12px; margin: 0 auto;
  background: url(icon.svg) center/100% no-repeat;
}
.error { color: var(--danger); }

/* ── shell ─────────────────────────────────────────── */
.shell { min-height: 100%; }
.side { display: none; }
.main {
  max-width: 760px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0 10px; }
.top-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.top h1 { margin: 0; font-size: 20px; line-height: 1.3; color: var(--mauve); text-transform: lowercase; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; min-height: 18px; }
.sub .over { color: var(--warn); font-weight: 600; }

.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.capture {
  display: flex; gap: 8px; margin-top: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 6px 6px 14px; box-shadow: var(--shadow);
}
.capture:focus-within { border-color: var(--accent); }
.capture input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; }
.capture-btn {
  border: 0; width: 40px; height: 40px; flex: none; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}

.chips { display: flex; gap: 6px; overflow-x: auto; margin: 12px -16px 0; padding: 0 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }

/* ── list ──────────────────────────────────────────── */
.list { list-style: none; margin: 4px 0 0; padding: 0; }
.group-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 18px 4px 6px; }
.item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.check {
  flex: none; width: 22px; height: 22px; margin-top: 1px; border-radius: 5px;
  border: 2px solid var(--faint); background: transparent; padding: 0;
  display: grid; place-items: center; transition: border-color .15s, background .15s;
}
.check:hover { border-color: var(--accent); }
.check.high { border-color: var(--warn); }
.check.done { background: var(--ok); border-color: var(--ok); }
.check.done::after { content: ""; width: 10px; height: 6px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.check.idea { border-radius: 7px; border-style: dashed; }
.body { flex: 1; min-width: 0; cursor: pointer; }
.title { word-wrap: break-word; }
.item.is-done .title { color: var(--faint); text-decoration: line-through; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.meta .late { color: var(--danger); font-weight: 600; }
.meta .soon { color: var(--warn); }
.tier { border-radius: 6px; padding: 0 6px; font-weight: 600; font-size: 11.5px; }
.tier.t1 { background: var(--warn-soft); color: var(--warn); }
.tier.t2 { background: var(--danger-soft); color: var(--danger); }
.id { color: var(--faint); font-variant-numeric: tabular-nums; }

.triage { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.triage select, .tbtn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 5px 10px; font-size: 13px; min-height: 32px;
}
.tbtn.go { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tbtn:hover { border-color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 56px 16px; }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.queued { margin-top: 10px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 13px; }

/* ── bottom tabs (phone) ───────────────────────────── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(var(--safe-bottom) + 4px);
}
.tab {
  border: 0; background: transparent; color: var(--muted);
  display: grid; justify-items: center; gap: 2px; font-size: 10px; padding: 4px 0; position: relative;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--accent); }
.badge {
  position: absolute; top: 0; left: calc(50% + 6px);
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; padding: 0 4px;
  display: grid; place-items: center;
}

/* ── detail sheet ──────────────────────────────────── */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  /* leave a visible strip of backdrop under the status bar to tap */
  max-height: calc(100vh - env(safe-area-inset-top) - 48px);
  max-height: calc(100dvh - env(safe-area-inset-top) - 48px);
  overflow-y: auto; overscroll-behavior: contain; background: var(--surface);
  border-radius: 18px 18px 0 0; padding: 0 16px calc(var(--safe-bottom) + 20px);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, .18);
}
.sheet-head {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  display: grid; grid-template-columns: 40px 1fr 40px; align-items: center;
  margin: 0 -16px; padding: 6px 8px 2px; touch-action: none; /* swipe down to close */
}
.sheet-head .grab { grid-column: 2; }
.sheet-head .icon-btn { grid-column: 3; font-size: 22px; line-height: 1; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto; }
.f-title { width: 100%; border: 0; outline: 0; background: transparent; font-size: 20px; font-weight: 600; line-height: 1.3; padding: 4px 0; resize: none; field-sizing: content; min-height: 1.3em; }
.f-notes {
  width: 100%; min-height: 72px; resize: vertical; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); padding: 10px 12px; outline: 0; margin-top: 6px;
}
.f-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-top: 14px; }
.field { min-width: 0; display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.field input, .field select {
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  padding: 8px 10px; font-size: 15px; min-height: 40px; width: 100%; min-width: 0;
}
.field.full { grid-column: 1 / -1; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--bg); padding: 8px 4px; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 14px; min-height: 42px; font-weight: 500;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.quiet { color: var(--muted); }
.btn.danger { color: var(--danger); }
.history { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
.history h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.history ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.history time { color: var(--faint); margin-right: 6px; font-variant-numeric: tabular-nums; }
.note-row { display: flex; gap: 8px; margin-top: 10px; }
.note-row input { flex: 1; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 8px 10px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}

/* ── phone ─────────────────────────────────────────── */
@media (max-width: 899px) {
  /* App shell pinned to the screen: header + list scroll inside .main and the tab bar is the
     last row, not position:fixed. iOS (home-screen mode, and after the keyboard closes) leaves
     fixed bottom bars floating too high; an in-flow bar can't drift. */
  html, body { overflow: hidden; overscroll-behavior: none; }
  .shell {
    position: fixed; inset: 0; display: flex; flex-direction: column;
    padding-top: env(safe-area-inset-top);
  }
  .main {
    flex: 1; min-height: 0; width: 100%; overflow-y: auto; overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch; padding: 0 16px 24px;
  }
  .tabs { position: static; flex: none; }
  .toast { bottom: calc(var(--safe-bottom) + 80px); }
  /* under 16px iOS zooms in on focus and stays zoomed, pushing buttons off screen */
  input, select, textarea, .triage select, .field input, .field select { font-size: 16px; }
}

/* ── desktop ───────────────────────────────────────── */
@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .side {
    display: block; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    border-right: 1px solid var(--line); padding: 20px 12px;
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 8px 18px; }
  .brand-mark { width: 26px; height: 26px; margin: 0; }
  .side-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); padding: 18px 8px 6px; }
  .side-views, .side-areas { display: grid; gap: 2px; }
  .side-link {
    display: flex; align-items: center; gap: 10px; border: 0; background: transparent;
    padding: 7px 10px; border-radius: 8px; text-align: left; color: var(--muted);
  }
  .side-link:hover { background: var(--surface-2); color: var(--ink); }
  .side-link[aria-current="page"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
  .side-link .n { margin-left: auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
  .side-link svg { width: 18px; height: 18px; }
  .tabs, #area-chips { display: none; }
  .main { padding: 24px 32px 48px; }
  .sheet {
    left: auto; top: 0; width: 440px; max-height: none; border-radius: 0;
    padding: 0 24px 20px; box-shadow: -8px 0 32px rgba(0, 0, 0, .12);
  }
  .sheet-head { margin: 0 -24px 4px; padding: 12px 16px 4px; }
  .grab { display: none; }
  .toast { bottom: 24px; }
}
