/* Kitt Online — the mobile variation of contents/css/common.css.
 *
 * THE SAME DESIGN SYSTEM, DRAWN FOR A THUMB. Every token below is copied
 * verbatim from the desktop file, and every component class that means the same
 * thing keeps the same name — .card, .btn, .badge, .field, .input, .alert,
 * .toolbar, .text-muted. That is the whole discipline: markup written for a
 * Kitt view reads the same here, and a person moving between the two apps is
 * looking at one product.
 *
 * WHAT IS DELIBERATELY DIFFERENT, and it is only the layout primitives:
 *
 *   .app-shell   a column (topbar / main / tabbar), not a grid with a sidebar
 *   .tabbar      the mobile variation of .sidebar — the same js/nav.js entries,
 *                drawn as four thumb-sized tabs at the bottom of the screen
 *   .sheet       the mobile variation of .drawer — it rises from the bottom
 *                edge instead of sliding in from the right
 *
 * Everything else a phone needs is a size, not a new idea: 44px minimum tap
 * targets, `env(safe-area-inset-*)` so the tab bar clears the home indicator,
 * and 16px inputs so iOS does not zoom the page when one is focused.
 *
 * NOT a copy of the desktop file with overrides. Two thirds of that file is
 * a sidebar, a workspace bar, data tables and charts, none of which exists
 * here — and a stylesheet carrying rules for markup that cannot occur is one
 * nobody can safely change.
 */

/* ——— Tokens: identical to contents/css/common.css ——— */

:root {
  --bg: oklch(98% 0.005 250);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(96% 0.006 250);
  --fg: oklch(22% 0.02 240);
  --muted: oklch(50% 0.018 240);
  --border: oklch(90% 0.008 240);
  --accent: oklch(58% 0.16 145);
  --accent-fg: oklch(100% 0 0);
  --accent-muted: oklch(58% 0.16 145 / 0.12);
  --danger: oklch(55% 0.2 25);
  --danger-muted: oklch(55% 0.2 25 / 0.12);
  --warn: oklch(72% 0.16 85);
  --warn-muted: oklch(72% 0.16 85 / 0.18);
  --success: oklch(58% 0.16 145);
  --success-muted: oklch(58% 0.16 145 / 0.12);
  --info: oklch(58% 0.14 250);
  --info-muted: oklch(58% 0.14 250 / 0.12);
  --shadow: 0 1px 2px oklch(0% 0 0 / 0.06), 0 4px 16px oklch(0% 0 0 / 0.04);
  --radius: 8px;
  --radius-lg: 12px;
  --topbar-h: 56px;
  --tabbar-h: 56px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font-display: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --transition: 150ms ease;
  /* The smallest thing a thumb can hit reliably. Every control below is at
     least this tall, which is the single biggest difference from the desktop
     sheet of rules. */
  --tap: 44px;
}

[data-theme="dark"] {
  --bg: oklch(16% 0.015 250);
  --surface: oklch(20% 0.015 250);
  --surface-2: oklch(24% 0.015 250);
  --fg: oklch(94% 0.01 250);
  --muted: oklch(62% 0.012 250);
  --border: oklch(30% 0.012 250);
  --accent: oklch(68% 0.16 145);
  --accent-fg: oklch(14% 0.02 145);
  --accent-muted: oklch(68% 0.16 145 / 0.15);
  --danger: oklch(65% 0.18 25);
  --danger-muted: oklch(65% 0.18 25 / 0.15);
  --warn: oklch(78% 0.14 85);
  --warn-muted: oklch(78% 0.14 85 / 0.15);
  --success: oklch(68% 0.16 145);
  --success-muted: oklch(68% 0.16 145 / 0.15);
  --info: oklch(68% 0.12 250);
  --info-muted: oklch(68% 0.12 250 / 0.15);
  --shadow: 0 1px 2px oklch(0% 0 0 / 0.3), 0 4px 16px oklch(0% 0 0 / 0.25);
}

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

/*
  `hidden`, said twice, and it is not belt-and-braces. The UA stylesheet's
  `[hidden] { display: none }` is a USER-AGENT rule, and any author rule beats a
  user-agent rule whatever the specificity — so a `.sheet-wrap { display: flex }`
  silently leaves an invisible full-screen backdrop swallowing every tap. That
  was a real bug here before this line existed.
*/
[hidden] { display: none !important; }

html {
  font-size: 16px;              /* 14px on the desktop; a phone is held further away */
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

/* ——— Typography ——— */

h1 { font: 600 1.125rem/1.3 var(--font-display); }
h2 { font: 600 0.75rem/1.3 var(--font-display); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
h3 { font: 600 0.9375rem/1.35 var(--font-display); }
a { color: var(--accent); text-decoration: none; }

.text-muted { color: var(--muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-mono { font-family: var(--font-mono); }

/* ——— App shell: topbar / main / tabbar ——— */

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: calc(var(--safe-t) + 8px) 12px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left { flex: 1; min-width: 0; }
.topbar-left h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-sub { font-size: 0.8125rem; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 6px; }

/* The scroll container, like `.main` on the desktop — so a view's scroll
   position is the view's, and the chrome above and below never moves. */
.main {
  min-width: 0;
  padding: 12px 12px calc(16px + var(--safe-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ——— Tab bar: the mobile variation of .sidebar ———
   Same js/nav.js entries, same `hidden` rule, drawn along the bottom edge
   because that is where a thumb is. */

.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}

.tab-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tabbar-h);
  border: 0;
  background: none;
  color: var(--muted);
  font: 600 0.6875rem/1 var(--font-body);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tab-link.active { color: var(--accent); }
.tab-link .nav-icon { display: block; }

.nav-icon { width: 22px; height: 22px; }

/* ——— Buttons ——— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  font: 600 0.9375rem/1 var(--font-body);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:active { filter: brightness(0.94); }
.btn-ghost { background: none; border-color: transparent; }
.btn-danger { color: var(--danger); border-color: var(--border); }
.btn-danger.btn-primary { background: var(--danger); border-color: var(--danger); color: var(--accent-fg); }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 0.8125rem; }
.btn-block { width: 100%; }

.btn-icon {
  min-width: var(--tap);
  width: var(--tap);
  padding: 0;
  background: var(--surface-2);
}

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn-row + .btn-row { margin-top: 10px; }

/* ——— Form controls ——— */

.field + .field { margin-top: 14px; }
.field label,
label.field-label {
  display: block;
  margin-bottom: 5px;
  font: 600 0.8125rem/1.3 var(--font-body);
}
.field-hint { display: block; margin-top: 5px; font-size: 0.75rem; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row .field + .field { margin-top: 0; }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  /* 16px exactly: anything smaller and iOS Safari zooms the page on focus and
     never zooms back out. This is the one place a font size is a bug fix. */
  font: 400 16px/1.4 var(--font-body);
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--accent-muted);
  outline-offset: -1px;
  border-color: var(--accent);
}
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; background-image: none; }

/* ——— Cards ——— */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card + .card { margin-top: 10px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.card-body { padding: 14px; }

/* ——— Badges ——— */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font: 600 0.6875rem/1.5 var(--font-body);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge-open { background: var(--info-muted); color: var(--info); border-color: transparent; }
.badge-current { background: var(--info-muted); color: var(--info); border-color: transparent; }
.badge-confirmed { background: var(--success-muted); color: var(--success); border-color: transparent; }
.badge-planned { background: var(--surface-2); color: var(--muted); }
.badge-failed { background: var(--danger-muted); color: var(--danger); border-color: transparent; }
.badge-excluded { background: var(--surface-2); color: var(--muted); }

/* ——— Alerts ——— */

.alert-stack { display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.875rem;
}
.alert-icon { flex: 0 0 auto; margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 600; }
.alert-text { color: var(--muted); }
.alert-actions { display: flex; gap: 6px; }
.alert-close {
  flex: 0 0 auto;
  border: 0; background: none; color: var(--muted);
  font-size: 1rem; line-height: 1; cursor: pointer;
  min-width: 28px; min-height: 28px;
}
.alert-info { border-left-color: var(--info); background: var(--info-muted); }
.alert-success { border-left-color: var(--success); background: var(--success-muted); }
.alert-warn { border-left-color: var(--warn); background: var(--warn-muted); }
.alert-danger { border-left-color: var(--danger); background: var(--danger-muted); }
.alert-info .alert-icon { color: var(--info); }
.alert-success .alert-icon { color: var(--success); }
.alert-warn .alert-icon { color: var(--warn); }
.alert-danger .alert-icon { color: var(--danger); }

/* ——— Toolbar ——— */

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar-spacer { flex: 1; }

/* ——— Lists: the phone's table ———
   The desktop shows rows in a .data-table. A phone cannot, so the same rows are
   .list-item inside a .card — same information, one column. */

.list-group { margin-top: 18px; }
.list-group:first-child { margin-top: 0; }
.list-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 4px 8px;
}
.list-head .count { font-size: 0.75rem; color: var(--muted); }
.list-head.is-today h2 { color: var(--accent); }

.list-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 14px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.list-item:first-child { border-top: 0; }
.list-item:active { background: var(--surface-2); }

.list-tick {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  margin-top: 1px;
  display: grid; place-items: center;
  border: 2px solid var(--border);
  border-radius: 6px;
  color: var(--success);
  font-size: 0.875rem; line-height: 1;
}
.list-tick.is-done { border-color: var(--success); }
.list-tick.is-none { visibility: hidden; }

.list-body { flex: 1; min-width: 0; }
.list-title { font-weight: 600; overflow-wrap: anywhere; }
.list-title.is-done { text-decoration: line-through; color: var(--muted); }
.list-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 3px;
  font-size: 0.75rem; color: var(--muted);
}
.list-time {
  flex: 0 0 auto;
  font: 600 0.8125rem/1.4 var(--font-body);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.view-pending { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ——— Sheet: the mobile variation of .drawer ———
   Same contract as the desktop drawer — the page owns the boolean, the
   component never hides itself — rising from the bottom edge because that is
   the edge a thumb reaches. */

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: oklch(0% 0 0 / 0.45);
}

.sheet {
  position: relative;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  animation: sheet-rise 160ms ease-out;
}
@keyframes sheet-rise { from { transform: translateY(16px); opacity: 0.5; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet-grip {
  flex: 0 0 auto;
  width: 44px; height: 4px;
  margin: 8px auto 4px;
  border-radius: 2px;
  background: var(--border);
}
.sheet-header { flex: 0 0 auto; padding: 8px 16px 4px; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px; }
.sheet-footer {
  flex: 0 0 auto;
  padding: 12px 16px calc(16px + var(--safe-b));
  border-top: 1px solid var(--border);
}

/* ——— Toasts ——— */

.toast-stack {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
  pointer-events: auto;
}
.toast-text { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; }
.toast-close { border: 0; background: none; color: var(--muted); min-width: 28px; min-height: 28px; cursor: pointer; }
.toast-success { border-left-color: var(--success); }
.toast-danger { border-left-color: var(--danger); }
.toast-warn { border-left-color: var(--warn); }
.toast-info { border-left-color: var(--info); }
.toast-enter-active, .toast-leave-active { transition: opacity var(--transition), transform var(--transition); }
.toast-enter-from, .toast-leave-to { opacity: 0; transform: translateY(8px); }

/* ——— Sign-in: the one screen with no shell ——— */

.signin {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.signin-mark {
  width: 64px; height: 64px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-fg);
  font: 700 32px/1 var(--font-display);
}

/* ——— Odds and ends the views share ——— */

.pill {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.6875rem;
  white-space: nowrap;
}
.pill-overdue { color: var(--danger); border-color: var(--danger-muted); background: var(--danger-muted); }
.pill-generated { color: var(--warn); border-color: var(--warn-muted); background: var(--warn-muted); }
.pill-online { color: var(--info); border-color: var(--info-muted); background: var(--info-muted); }

.token-box {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  font: 12px/1.5 var(--font-mono);
  overflow-wrap: anywhere;
}

.stack-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.stack-row:first-child { border-top: 0; }
.stack-row-body { flex: 1; min-width: 0; }
