/* ============================================================
   SV HQ design system
   Direction D "The Terminal", dark always.
   Tokens are the brand JSON cssVariables, verbatim.
   ============================================================ */

/* Cross-document view transitions: same-origin /admin navigations animate
   like an app. The chrome (sidebar, top bar, tab bar) keeps a stable
   view-transition-name so it stays put while the main content cross-fades.
   Progressive: browsers without support just navigate normally. */
@view-transition { navigation: auto; }
.hq-side { view-transition-name: hq-side; }
.hq-topbar { view-transition-name: hq-topbar; }
.hq-tabbar { view-transition-name: hq-tabbar; }
::view-transition-old(root), ::view-transition-new(root) {
  animation-duration: 170ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}

:root {
  --bg: #070C09;
  --panel: #0B1A11;
  --panel2: #0E2417;
  --surface: #18241E;
  --surface-hi: #203028;
  --sborder: #2C3E34;
  --hi: #F1F6F2;
  --mid: #A9BAAE;
  --low: #7E9086;
  --g600: #16A34A;
  --g500: #22C55E;
  --g400: #4ADE80;
  --amber: #FEBC2E;
  --dot-r: #FF5F57;
  --dot-a: #FEBC2E;
  --dot-g: #28C840;
  --chip-bg: #F5FAF6;
  --chip-bd: #C7CBD1;
  --grid: rgba(173,199,183,0.05);
  --hairline: rgba(173,199,183,0.1);
  --greenline: rgba(34,197,94,0.34);
  /* fill tokens: constant brand color regardless of theme, used only where
     a saturated swatch/button needs dark text on top (never used for text itself) */
  --g-fill: #22C55E;
  --g-fill-hover: #4ADE80;
  /* text-safe ink tokens: identical to the brand color in dark (no visual change),
     remapped to an AA-contrast shade in light mode. Use these for color:, never for fills. */
  --red: #FF5F57;
  --amber-ink: #FEBC2E;
  /* skeleton fill: reuses --surface in dark (already contrasts against --bg);
     light mode needs a more visible shade since surface/canvas sit very close there */
  --skel-bg: var(--surface);
  --sborder-hover: #3A5245;
  --kb-col-bg: rgba(24,36,30,0.45);
  --overdue-wash-end: rgba(24,36,30,0.6);
  --font-display: 'Outfit', 'Noto Sans Thai', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-thai: 'Noto Sans Thai', sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-chip: 11px;
  --radius-tile: 22px;
  --shadow-card: 0 24px 60px rgba(0,0,0,0.5);
  --shadow-soft: 0 6px 18px rgba(0,0,0,0.35);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);      /* ease-out expo */
  --ease-quart: cubic-bezier(0.25, 1, 0.5, 1); /* ease-out quart */
  --side-w: 236px;
  --topbar-h: 52px;
  color-scheme: dark;
}

/* ---------- light theme ----------
   Same family, different weather: green-tinted paper instead of green-tinted
   ink. Never pure white. Text greens/reds/ambers move to AA-contrast shades;
   fill tokens (--g-fill, --dot-r, --dot-a, --dot-g, --amber) stay put since
   they're brand-constant swatches/dots, not body text. */
:root[data-theme="light"] {
  --bg: #F7FAF8;
  --panel: #EEF6F1;
  --panel2: #E3F2E8;
  --surface: #FBFDFB;
  --surface-hi: #F0F6F2;
  --sborder: #D4E2D8;
  --hi: #102016;
  --mid: #48604F;
  --low: #62766B; /* 4.9:1 on the light surfaces, AA for meta text */
  --g600: #166534;
  --g500: #15803D;
  --g400: #166534;
  --red: #B91C1C;
  --amber-ink: #B45309;
  --grid: rgba(16,32,22,0.045);
  --hairline: rgba(16,32,22,0.08);
  --skel-bg: #E7EEE9;
  --sborder-hover: #B9CCBF;
  --kb-col-bg: rgba(16,32,22,0.035);
  --overdue-wash-end: var(--surface);
  --shadow-card: 0 24px 50px rgba(16,32,22,0.12);
  --shadow-soft: 0 6px 16px rgba(16,32,22,0.09);
  color-scheme: light;
}

/* ---------- reset / base ---------- */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* the hidden attribute always wins, even over component display rules */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-display);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--mid);
  background-color: var(--bg);
  /* 34px grid texture on the page canvas */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 34px 34px;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: rgba(34,197,94,0.28); color: var(--hi); }

a { color: inherit; text-decoration: none; }
a.link { color: var(--g500); }
a.link:hover { color: var(--g400); }

button { font-family: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font-family: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
h1, h2, h3 { color: var(--hi); font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
strong { color: var(--hi); font-weight: 600; }

:focus-visible { outline: 2px solid var(--g500); outline-offset: 2px; border-radius: 4px; }

.mono { font-family: var(--font-mono); }

/* ---------- signature motifs ---------- */

.dots { display: inline-flex; gap: 6px; flex: none; }
.dots i { width: 9px; height: 9px; border-radius: 50%; display: block; }
.dots i:nth-child(1) { background: var(--dot-r); }
.dots i:nth-child(2) { background: var(--dot-a); }
.dots i:nth-child(3) { background: var(--dot-g); }

/* shell-prompt section label: author text only, '>' comes from CSS */
.prompt {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--g500);
}
.prompt::before { content: '> '; }

.meta-line {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--low);
  letter-spacing: 1.5px;
  text-transform: lowercase;
}
.meta-line::before { content: '> '; color: var(--g500); }

.cursor {
  display: inline-block;
  width: 8px;
  height: 15px;
  background: var(--g400);
  vertical-align: -2px;
  margin-left: 5px;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.rule {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--g600), transparent);
}

/* accent panel: gradient glow, scanlines live here and only here */
.panel-accent {
  position: relative;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(34,197,94,0.18), transparent 55%),
    linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid rgba(34,197,94,0.28);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.panel-accent::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(74,222,128,0.05) 0 1px, transparent 1px 5px);
  opacity: 0.6;
  pointer-events: none;
}
.panel-accent > * { position: relative; z-index: 1; }

/* ---------- shared components ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s, transform 0.15s var(--ease-quart);
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary { background: var(--g-fill); color: #07120B; }
.btn-primary:hover { background: var(--g-fill-hover); }
.btn-ghost { background: transparent; color: var(--hi); border-color: var(--sborder); }
.btn-ghost:hover { border-color: var(--g600); color: var(--g400); }
.btn-danger { background: transparent; color: var(--red); border-color: rgba(255,95,87,0.35); }
.btn-danger:hover { background: rgba(255,95,87,0.08); }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 36px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--low);
  font-size: 20px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-hi); color: var(--hi); }

.input, .textarea, .cmd-select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-md);
  color: var(--hi);
  font-size: 15px;
  padding: 10px 13px;
  min-height: 44px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .textarea:focus, .cmd-select:focus {
  outline: none;
  border-color: var(--g600);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.15);
}
.input::placeholder, .textarea::placeholder { color: var(--low); }
.textarea { resize: vertical; line-height: 1.55; }
.input-mono { font-family: var(--font-mono); font-size: 13.5px; letter-spacing: 0.5px; }
input[type="date"].input { font-family: var(--font-mono); font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--low);
}
.field-err {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--red);
}

/* command-line style input row (quick add, composer) */
.cmdline {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: 12px;
  padding: 6px 6px 6px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.cmdline:focus-within { border-color: var(--g600); box-shadow: 0 0 0 3px rgba(34,197,94,0.12); }
.cmdline-prompt { font-family: var(--font-mono); font-weight: 700; color: var(--g500); font-size: 14px; }
.cmdline-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  color: var(--hi);
  font-size: 14.5px;
  min-height: 40px;
}
.cmdline-input:focus { outline: none; }
.cmdline-input::placeholder { color: var(--low); }
.cmd-select {
  width: auto;
  min-height: 40px;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--mid);
  border-radius: 8px;
}

/* avatar: rounded tile with founder initial */
.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--surface-hi);
  border: 1px solid var(--sborder);
  color: var(--g400);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; border-radius: 7px; }
.avatar-xs { width: 22px; height: 22px; font-size: 10.5px; border-radius: 6px; }
.avatar-empty { color: var(--low); border-style: dashed; }
/* stacked avatars for multi-assignee (slight overlap) */
.avatar-stack { display: inline-flex; align-items: center; }
.avatar-stack .avatar { margin-left: -6px; box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* chips: mono value + label */
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-chip);
  padding: 9px 13px;
}
.chip-k {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--low);
}
.chip-v { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--hi); }

/* tiny status tag */
.tag {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sborder);
  color: var(--mid);
  background: var(--surface-hi);
  white-space: nowrap;
  flex: none;
}
.tag-green { color: var(--g400); border-color: rgba(34,197,94,0.35); background: rgba(34,197,94,0.08); }
.tag-red { color: var(--red); border-color: rgba(255,95,87,0.35); background: rgba(255,95,87,0.08); }
.tag-amber { color: var(--amber-ink); border-color: rgba(254,188,46,0.3); background: rgba(254,188,46,0.07); }

/* toast */
.toast-tray {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--hi);
  background: var(--surface-hi);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow-soft);
  max-width: min(92vw, 420px);
  animation: toast-in 0.3s var(--ease) both;
  pointer-events: auto;
}
.toast.success { border-color: rgba(34,197,94,0.4); background: rgba(34,197,94,0.1); color: var(--g400); }
.toast.error { border-color: rgba(255,95,87,0.4); background: rgba(255,95,87,0.09); color: var(--red); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* skeleton + empty + error */
.skel {
  border-radius: var(--radius-md);
  background: var(--skel-bg);
  animation: skel 1.1s ease-in-out infinite alternate;
}
@keyframes skel { from { opacity: 0.4; } to { opacity: 0.85; } }

.empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--low);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.5px;
}
.empty a { color: var(--g500); }
.empty a:hover { color: var(--g400); }

.err-box {
  background: rgba(255,95,87,0.06);
  border: 1px solid rgba(255,95,87,0.3);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.err-box p { font-family: var(--font-mono); font-size: 12.5px; color: var(--red); flex: 1; min-width: 180px; }

/* staggered fade-up entrance for lists */
.stagger > * {
  animation: fade-up 0.5s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- app shell ---------- */

.hq-main {
  padding: 26px 28px 72px;
  max-width: 1140px;
}
.hq-main.wide { max-width: 1420px; }

/* desktop sidebar: the green identity panel */
.hq-side {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--side-w);
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: 18px 12px calc(14px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(34,197,94,0.14), transparent 55%),
    linear-gradient(180deg, var(--panel2), var(--panel));
  border-right: 1px solid rgba(34,197,94,0.22);
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 16px;
  border-radius: var(--radius-md);
}
.side-brand-name {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  color: var(--hi);
  letter-spacing: 0.5px;
}
.side-brand-name small {
  display: block;
  font-size: 9.5px;
  font-weight: 500;
  color: var(--low);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 1px;
}
/* visible search bar: opens the command palette */
.side-search {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  margin: 4px 0 14px;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-md);
  color: var(--low);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.side-search:hover { border-color: var(--g500); color: var(--mid); background: var(--surface-hi); }
.side-search:focus-visible { outline: 2px solid var(--g500); outline-offset: 1px; }
.side-search svg { width: 16px; height: 16px; flex: none; }
.side-search-label { flex: 1; text-align: left; }
.side-search-kbd {
  flex: none;
  font-size: 10.5px;
  color: var(--low);
  background: var(--panel);
  border: 1px solid var(--sborder);
  border-radius: 5px;
  padding: 1px 6px;
  letter-spacing: 0.5px;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; }
.side-group {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: rgba(34,197,94,0.75);
  margin: 18px 10px 6px;
}
.side-group::before { content: '> '; }
.side-link {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--mid);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.side-link svg { width: 17px; height: 17px; flex: none; }
.side-link:hover { background: rgba(34,197,94,0.07); color: var(--hi); }
.side-link.active { background: rgba(34,197,94,0.12); color: var(--g400); font-weight: 600; }
.side-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-top: 1px solid var(--hairline);
  padding-top: 10px;
  margin-top: 10px;
}
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.side-user-text { min-width: 0; line-height: 1.25; }
.side-user-text strong { display: block; font-size: 13px; color: var(--hi); }
.side-user-text .mono { font-size: 10.5px; color: var(--low); }

/* theme toggle: sun/moon pair, CSS shows the icon matching the live theme */
.theme-toggle .i-sun { display: none; }
.theme-toggle .i-moon { display: block; }
:root[data-theme="light"] .theme-toggle .i-sun { display: block; }
:root[data-theme="light"] .theme-toggle .i-moon { display: none; }
.icon-btn.theme-toggle svg { width: 19px; height: 19px; }

/* mobile top bar */
.hq-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: env(safe-area-inset-top) 14px 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--hairline);
}
.hq-topbar .side-brand-name { font-size: 14px; }
.sva-logo { width: 34px; height: 34px; border-radius: 8px; flex: none; display: block; }
.hq-topbar .sva-logo { width: 28px; height: 28px; border-radius: 7px; }
.login-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.login-logo svg { width: 56px; height: 56px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }
.topbar-user { margin-left: auto; border-radius: 7px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.topbar-actions .topbar-user { margin-left: 0; }

/* mobile bottom tab bar */
.hq-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  background: var(--panel);
  border-top: 1px solid var(--hairline);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 52px;
  padding: 6px 4px;
  border-radius: var(--radius-md);
  color: var(--low);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  transition: color 0.15s, background 0.15s;
}
.tab-item svg { width: 20px; height: 20px; }
.tab-item.active { color: var(--g400); }
.tab-item:active { background: rgba(34,197,94,0.08); }

@media (min-width: 900px) {
  .hq-topbar, .hq-tabbar { display: none; }
  .hq-main { margin-left: var(--side-w); }
}
@media (max-width: 899px) {
  .hq-side { display: none; }
  body.hq { padding-top: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .hq-main { padding: 18px 16px calc(92px + env(safe-area-inset-bottom)); }
  .btn-sm { min-height: 44px; }
}

/* ---------- page scaffold ---------- */

.page-head { margin-bottom: 18px; animation: fade-up 0.5s var(--ease) both; }
.page-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.page-head .meta-line { margin-top: 4px; }
@media (max-width: 899px) { .page-title { font-size: 22px; } }

.sec { margin-top: 30px; animation: fade-up 0.5s var(--ease) both; }
.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.sec-count { font-family: var(--font-mono); font-size: 11px; color: var(--low); letter-spacing: 1px; }

/* ---------- today view ---------- */

.qadd { margin: 18px 0 22px; }

.miles { display: grid; grid-template-columns: 1fr 1fr; }
.mile { padding: 20px 24px 18px; display: flex; flex-direction: column; gap: 7px; }
.mile + .mile { box-shadow: -1px 0 0 var(--hairline); }
.mile-top { display: flex; align-items: baseline; gap: 9px; }
.mile-n {
  font-family: var(--font-mono);
  font-size: 46px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1px;
  color: var(--g400);
}
.mile-unit {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--g500);
}
.mile-label { font-size: 14px; font-weight: 600; color: var(--hi); line-height: 1.3; }
.mile-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--mid);
  letter-spacing: 1px;
  text-transform: lowercase;
}
@media (max-width: 520px) {
  .miles { grid-template-columns: 1fr; }
  .mile + .mile { box-shadow: 0 -1px 0 var(--hairline); }
  .mile-n { font-size: 40px; }
}

.tgroup { margin-top: 16px; }
.tgroup:first-child { margin-top: 0; }
.tgroup-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--low);
  margin: 0 0 8px 2px;
}
.tgroup-label.red { color: var(--red); }
.tgroup-label.amber { color: var(--amber-ink); }
.tgroup-label.green { color: var(--g500); }
.trows { display: flex; flex-direction: column; gap: 6px; }
.trow {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-md);
  transition: border-color 0.15s, transform 0.2s var(--ease-quart);
}
.trow:hover { border-color: var(--sborder-hover); transform: translateY(-1px); }
.trow.is-overdue {
  border-color: rgba(255,95,87,0.35);
  background: linear-gradient(180deg, rgba(255,95,87,0.06), var(--overdue-wash-end));
}
.trow.is-today { border-color: rgba(254,188,46,0.28); }
.trow-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--hi);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trow-id { font-family: var(--font-mono); font-size: 11px; color: var(--low); letter-spacing: 1px; flex: none; }
.trow-due { font-family: var(--font-mono); font-size: 11px; color: var(--mid); text-transform: lowercase; flex: none; }
.trow-due.overdue { color: var(--red); }

.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 899px) { .duo { grid-template-columns: 1fr; gap: 0; } .duo > .sec { margin-top: 30px; } }

.team-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.team-tile {
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-md);
  padding: 13px 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  align-items: flex-start;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s var(--ease-quart, ease);
}
a.team-tile:hover { border-color: var(--g500); transform: translateY(-1px); }
a.team-tile:focus-visible { outline: 2px solid var(--g500); outline-offset: 1px; }
.team-name { font-size: 13.5px; font-weight: 600; color: var(--hi); line-height: 1.2; }
.team-counts {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--mid);
  letter-spacing: 0.3px;
  margin-top: 2px;
}

.snap-row { display: flex; flex-wrap: wrap; gap: 8px; }

.act-list { display: flex; flex-direction: column; }
.act {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 2px;
  border-top: 1px solid var(--hairline);
}
.act:first-child { border-top: 0; }
.act-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--g600); flex: none; align-self: center; }
.act-text {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--mid);
  overflow-wrap: anywhere;
}
.act-text strong { color: var(--hi); font-weight: 600; }
.act-time { font-family: var(--font-mono); font-size: 11px; color: var(--low); flex: none; }

/* ---------- legend (shared status-color key) ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 2px 0 18px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: lowercase;
  color: var(--low);
}
.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  display: inline-block;
}
.legend-swatch[data-k="inbox"] { background: var(--low); }
.legend-swatch[data-k="todo"] { background: var(--hi); }
.legend-swatch[data-k="doing"] { background: var(--amber); }
.legend-swatch[data-k="done"] { background: var(--g-fill); }
.legend-swatch[data-k="overdue"] { background: var(--dot-r); }

/* ---------- kanban board ---------- */

.kb-seg {
  display: none;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
  position: sticky;
  top: calc(var(--topbar-h) + 8px);
  z-index: 30;
}
.seg-btn {
  flex: 1;
  min-height: 44px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--mid);
  transition: background 0.15s, color 0.15s;
}
.seg-btn .seg-n { font-size: 10px; color: var(--low); }
.seg-btn[aria-selected="true"] { background: var(--surface-hi); color: var(--g400); box-shadow: inset 0 0 0 1px rgba(34,197,94,0.3); }
.seg-btn[aria-selected="true"] .seg-n { color: var(--g500); }

.kb {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}
.kb-col {
  background: var(--kb-col-bg);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 180px;
}
.kb-head { display: flex; align-items: center; gap: 8px; padding: 13px 14px 6px; }
.kb-count { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--low); }
.kb-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px 12px;
  min-height: 64px;
  flex: 1;
}
.kb-empty { padding: 14px 8px 18px; }

.kb-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: border-color 0.15s, transform 0.2s var(--ease-quart);
}
.kb-card:hover { border-color: var(--sborder-hover); transform: translateY(-1px); }
.kb-card.dragging { opacity: 0.35; }
.kb-card-title { font-size: 14px; font-weight: 500; color: var(--hi); line-height: 1.45; overflow-wrap: anywhere; }
.kb-card.is-done .kb-card-title {
  color: var(--low);
  text-decoration: line-through;
  text-decoration-color: var(--low);
}
.kb-card-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; min-height: 22px; }
.kb-id { font-family: var(--font-mono); font-size: 11px; color: var(--low); letter-spacing: 1px; }
.kb-due { font-family: var(--font-mono); font-size: 11px; color: var(--mid); text-transform: lowercase; }
.kb-due.overdue { color: var(--red); }
.kb-due.today { color: var(--amber-ink); }
.kb-card-meta .avatar-xs { margin-left: auto; }

/* task-complete micro-stamp */
.stamp {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  background: rgba(34,197,94,0.16);
  color: var(--g400);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  pointer-events: none;
  animation: stamp 0.9s var(--ease) forwards;
}
@keyframes stamp {
  0% { opacity: 0; transform: scale(0.92); }
  18% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: scale(1); }
}

@media (max-width: 899px) {
  .kb-seg { display: flex; }
  .kb { grid-template-columns: 1fr; }
  .kb[data-active="inbox"] .kb-col:not([data-status="inbox"]),
  .kb[data-active="todo"] .kb-col:not([data-status="todo"]),
  .kb[data-active="doing"] .kb-col:not([data-status="doing"]),
  .kb[data-active="done"] .kb-col:not([data-status="done"]) { display: none; }
  .kb-card { padding: 13px 14px; }
}
@media (min-width: 900px) and (max-width: 1180px) {
  .kb { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- task editor: sheet on mobile, slide-over on desktop ---------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(3,6,4,0.62);
  opacity: 0;
  transition: opacity 0.25s;
}
.scrim.open { opacity: 1; }

.editor {
  position: fixed;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--sborder);
}
.editor-grab { display: none; }
.editor-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--hairline);
}
.editor-head .icon-btn { margin-left: auto; }
.editor-id { font-family: var(--font-mono); font-size: 11.5px; color: var(--low); letter-spacing: 1px; }
.editor-body {
  overflow-y: auto;
  padding: 18px 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 17px;
  overscroll-behavior: contain;
}
.ed-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--low);
  letter-spacing: 0.5px;
  text-transform: lowercase;
}
.ed-danger {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-top: 1px solid var(--hairline);
  padding-top: 16px;
}
.ed-confirm { display: inline-flex; align-items: center; gap: 8px; }
.ed-confirm .mono { font-size: 12px; color: var(--red); }
.due-row { display: flex; gap: 8px; align-items: center; }
.due-row .input { flex: 1; }

.seg {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-md);
  padding: 4px;
}
.seg-opt {
  flex: 1;
  min-height: 40px;
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--mid);
  transition: background 0.15s, color 0.15s;
}
.seg-opt:hover { color: var(--hi); }
.seg-opt.active { background: var(--surface-hi); color: var(--g400); box-shadow: inset 0 0 0 1px rgba(34,197,94,0.3); }

@media (min-width: 900px) {
  .editor {
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    transform: translateX(102%);
    transition: transform 0.3s var(--ease);
  }
  .editor.open { transform: none; }
}
@media (max-width: 899px) {
  .editor {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 88dvh;
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(103%);
    transition: transform 0.3s var(--ease);
  }
  .editor.open { transform: none; }
  .editor-grab {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--sborder);
    margin: 10px auto 0;
    flex: none;
  }
}

body.locked { overflow: hidden; }

/* ---------- settings ---------- */

.set-sec {
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-top: 14px;
  animation: fade-up 0.45s var(--ease) both;
}
.set-sec:nth-of-type(1) { animation-delay: 0ms; }
.set-sec:nth-of-type(2) { animation-delay: 60ms; }
.set-sec:nth-of-type(3) { animation-delay: 120ms; }
.set-sec:nth-of-type(4) { animation-delay: 180ms; }
.set-sec:nth-of-type(5) { animation-delay: 240ms; }
.set-sec .prompt { display: block; margin-bottom: 14px; }
.set-form { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.kv {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 5px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.kv dt { color: var(--low); text-transform: lowercase; }
.kv dd { color: var(--hi); overflow-wrap: anywhere; }

.sess-list { display: flex; flex-direction: column; }
.sess-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--hairline);
}
.sess-row:first-child { border-top: 0; }
.sess-info { flex: 1; min-width: 0; }
.sess-dev {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--hi);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.sess-meta { font-family: var(--font-mono); font-size: 11px; color: var(--low); margin-top: 3px; }
.sess-actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- login ---------- */

.login-body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background-color: var(--bg);
  background-image:
    radial-gradient(120% 85% at 50% 118%, rgba(34,197,94,0.14), transparent 60%),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 100% 100%, 34px 34px, 34px 34px;
}
.login-wrap { width: 100%; max-width: 408px; display: flex; flex-direction: column; gap: 14px; }
.term {
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.term-bar {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--sborder);
}
.term-title {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--low);
  letter-spacing: 1.5px;
  text-transform: lowercase;
}
.term-body { padding: 22px 22px 24px; }
.boot { display: flex; flex-direction: column; gap: 5px; min-height: 66px; margin-bottom: 18px; }
.boot-line { font-family: var(--font-mono); font-size: 12px; color: var(--mid); letter-spacing: 0.4px; }
.boot-line.ok { color: var(--g500); }
.login-form { display: flex; flex-direction: column; gap: 15px; animation: fade-up 0.4s var(--ease) both; }
.login-err {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--dot-r);
  background: rgba(255,95,87,0.08);
  border: 1px solid rgba(255,95,87,0.3);
  border-radius: 8px;
  padding: 10px 12px;
}
.login-err.warn { color: var(--amber); background: rgba(254,188,46,0.07); border-color: rgba(254,188,46,0.3); }
.granted { font-family: var(--font-mono); font-size: 13px; color: var(--g400); letter-spacing: 1px; padding: 6px 0 2px; }
.login-foot {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--low);
  letter-spacing: 1.5px;
  text-transform: lowercase;
}

/* ---------- command palette (Cmd+K) ---------- */

.palette-scrim {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(3,6,4,0.66);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
}
.palette-scrim.open { opacity: 1; pointer-events: auto; }

.palette {
  width: 100%;
  max-width: 560px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--sborder);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transform: translateY(-8px) scale(0.98);
  opacity: 0;
  transition: transform 0.22s var(--ease), opacity 0.22s var(--ease);
}
.palette-scrim.open .palette { transform: translateY(0) scale(1); opacity: 1; }

.palette-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--hairline);
  flex: none;
}
.palette-prompt { color: var(--g500); font-size: 16px; flex: none; }
.palette-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  color: var(--hi);
  font-family: var(--font-display);
  font-size: 15px;
}
.palette-input::placeholder { color: var(--low); }
.palette-input:focus { outline: none; }

.palette-results { overflow-y: auto; padding: 8px; flex: 1; }
.palette-group + .palette-group { margin-top: 6px; }
.palette-group-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--low);
  padding: 8px 10px 4px;
}
.palette-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.palette-row-label {
  color: var(--hi);
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-row-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--low);
  letter-spacing: 0.5px;
  flex: none;
}
.palette-row.active {
  background: rgba(34,197,94,0.12);
  box-shadow: inset 0 0 0 1px rgba(34,197,94,0.3);
}
.palette-empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--low);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.palette-foot {
  flex: none;
  padding: 9px 16px;
  border-top: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.5px;
  color: var(--low);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.palette-capture-hint { color: var(--g400); margin-left: auto; }

@media (max-width: 599px) {
  .palette-scrim {
    padding: max(6vh, calc(10px + env(safe-area-inset-top))) 10px calc(10px + env(safe-area-inset-bottom));
  }
  .palette { max-height: 82vh; }
  .palette-capture-hint { display: none; }
  /* 16px keeps iOS Safari from zooming the page when the field focuses */
  .palette-input { font-size: 16px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .cursor { animation: none; }
  .skel { animation: none; opacity: 0.6; }
}

/* ---------- image lightbox ---------- */
.hq-lightbox {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 20px;
  background: rgba(0,0,0,0.82);
  backdrop-filter: blur(3px);
  animation: lb-in 0.16s var(--ease, ease) both;
}
.hq-lightbox[hidden] { display: none; }
@keyframes lb-in { from { opacity: 0 } to { opacity: 1 } }
.hq-lb-fig { margin: 0; display: flex; flex-direction: column; gap: 10px; max-width: 100%; max-height: 100%; }
.hq-lb-img {
  max-width: min(1100px, 100%); max-height: calc(100vh - 110px);
  object-fit: contain; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 30px 80px -30px rgba(0,0,0,0.9);
}
.hq-lb-cap {
  font-family: var(--font-mono); font-size: 12px; color: rgba(255,255,255,0.62);
  text-align: center; max-width: 640px; margin: 0 auto;
}
.hq-lb-close {
  position: fixed; top: 14px; right: 16px; z-index: 1;
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1; cursor: pointer;
  color: #fff; background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.18);
  transition: background 0.15s, border-color 0.15s;
}
.hq-lb-close:hover { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.4); }
/* a thumbnail that opens the viewer should say so */
[data-lightbox] { cursor: zoom-in; }
@media (max-width: 640px) {
  .hq-lightbox { padding: 60px 12px 24px; }
  .hq-lb-close { top: 10px; right: 10px; }
}
@media (prefers-reduced-motion: reduce) { .hq-lightbox { animation: none } }

/* ---------- touch targets ----------
   Last in the file on purpose: .seg-opt sets min-height 40px around line 1037,
   so the same rule earlier in a media query loses the cascade to it. Apple's
   floor for a reliable tap is 44px, and every seg, chip and select was under it.
   Page-scoped stylesheets load after this file, so anything they redeclare
   (finance's .chip-opt) needs the same rule in the page. */
@media (max-width: 899px) {
  /* iOS zooms the page when a focused field is under 16px and never zooms back
     out. Must live at the end of the file: .input is redefined further up, so
     the same rule inside the earlier media block loses the cascade to it. */
  .input, .input-mono, .textarea, .cmd-select,
  input[type="text"], input[type="date"], input[type="search"],
  input[type="password"], input[type="number"], select, textarea { font-size: 16px; }
  /* line 277 sets input[type="date"].input at 13px, specificity (0,2,1), so the
     override has to match it exactly rather than rely on the rules above. */
  input[type="date"].input, input[type="search"].input { font-size: 16px; }

  .seg-opt, .chip-opt, .cmd-select, .btn, .icon-btn { min-height: 44px; }
  /* a 17px native checkbox is not a tap target; grow its hit area */
  .split-toggle { min-height: 44px; }
  .split-toggle input { width: 22px; height: 22px; }
}

/* ---------- lazy list sentinel ---------- */
/* keeps a layout box even when empty, so IntersectionObserver can see it */
.pager-sentinel { display: flex; justify-content: center; min-height: 24px; padding: 14px 0 4px; }
.pager-status {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.4px;
  color: var(--mid); text-transform: lowercase;
  background: var(--surface); border: 1px solid var(--sborder);
  border-radius: var(--radius-chip); padding: 9px 18px; min-height: 40px;
  cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.pager-status:hover:not(:disabled) { color: var(--g400); border-color: var(--g600); }
.pager-status:disabled { cursor: default; background: transparent; border-color: transparent; }
.pager-status:empty { display: none; }
.pager-status.busy { color: var(--g400); }
.pager-status.warn { color: var(--amber-ink); cursor: pointer; }
.pager-status.end { color: var(--low); opacity: 0.6; }
