:root {
  /* Light & clinical */
  --bg: #f1f5f9; --card: #ffffff; --field: #ffffff; --fg: #0f172a;
  --muted: #64748b; --accent: #0284c7; --accent-fg: #ffffff;
  --err: #dc2626; --ok: #15803d; --border: #e2e8f0;
  --tabbar: 64px;  /* height reserved for the bottom icon tab bar */
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.view { min-height: 100vh; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--err); min-height: 1.2em; }

#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; width: 100%; max-width: 360px; text-align: center;
}
.card h1 { margin: 0 0 4px; }

input, textarea, select, button {
  font: inherit; width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--field); color: var(--fg);
  margin-top: 10px;
}
button {
  background: var(--accent); color: var(--accent-fg); border: none;
  font-weight: 600; cursor: pointer;
}
button:active { opacity: .85; }
button.link, .link {
  background: none; color: var(--accent); width: auto; padding: 4px 8px;
  margin: 0; font-weight: 500;
}
button.danger, .danger { color: var(--err); }
/* A SOLID danger button — red text on the blue fill was unreadable. Make
   it a proper red button. Link / segmented / outline danger keep
   red-on-light. */
button.danger:not(.link):not(.aseg):not(.seg):not(.btn-o) {
  background: var(--err); color: #fff;
}
/* Outline buttons — white fill, 2px coloured outline + matching text:
   the airy scheme of the record button and the Capture icons. Used by
   Capture Process/Clear, Clip Send/Clear, and clip-card Copy/Download. */
.btn-o {
  background: var(--card); color: var(--accent);
  border: 2px solid var(--accent);
}
.btn-o.danger { color: var(--err); border-color: var(--err); }
.link.sm { font-size: 12px; padding: 4px 6px; }     /* compact "Install" */
.cogbtn { font-size: 22px; padding: 2px 8px; line-height: 1; }  /* bigger ⚙ */

header {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--card); z-index: 6;
}
header strong { flex: 1; font-size: 18px; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: #dcfce7; color: var(--ok);
}
.badge.off { background: #fee2e2; color: var(--err); }
.badge.warn { background: #fef3c7; color: #b45309; }   /* worker delayed */
.badge.cost { background: #e0e7ff; color: #3730a3; }   /* today's API spend */
.badge.cost:empty { display: none; }

/* Bottom icon tab bar (iOS-style) */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 3px; background: none; color: var(--muted); border: none;
  border-radius: 0; padding: 8px 4px 7px; margin: 0; font-weight: 500;
  font-size: 11px; cursor: pointer;
}
.tab .ic { line-height: 0; }
.tab.active { color: var(--accent); }

main {
  padding: 16px 16px calc(var(--tabbar) + 24px);
  max-width: 720px; margin: 0 auto;
}
.row { display: flex; gap: 10px; }
.row > * { margin-top: 10px; }
.btnrow > * { flex: 1; width: auto; }              /* equal-width button row */
/* Capture / Clip icon buttons: white cards with an accent icon + thin
   border, matching the predominantly-white History look (they used to be
   solid blue, which made those pages feel heavy). */
.capicons button {
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: var(--card); color: var(--accent);
  border: 1px solid var(--border); border-radius: 12px;
}
.capicons button:active { background: #e0f2fe; }

/* Clip: text box + a Send-over-Clear column the same height as the box;
   Send is twice the height of the red Clear. */
.cliprow { align-items: stretch; }
.cliprow #clipText { flex: 1; margin-top: 10px; }
.sendcol { display: flex; flex-direction: column; gap: 10px;
  flex: 0 0 110px; margin-top: 10px; }
.sendcol button { width: 100%; margin: 0; }
.sendcol #clipSendText { flex: 2; }       /* 2× the Clear button */
.sendcol #clipClearText { flex: 1; }

/* Capture: Clear (red) left, Process right & more prominent */
.procrow #capClear { flex: 1; }
.procrow #capGo { flex: 2; }

button:disabled { opacity: .45; cursor: default; }
.tabpane.hot { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 12px; }

/* Settings sub-tabs */
.subtabs {
  display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.subtab {
  flex: 0 0 auto; width: auto; margin: 0; background: none; border: none;
  border-radius: 0; padding: 10px 12px; color: var(--muted);
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.subtab.active { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.subpane.hidden { display: none; }
/* 16px minimum on focusable fields so iOS Safari doesn't auto-zoom on tap
   (the Update box zoom). The read-only diagnostics <pre> can stay small. */
textarea.diag { min-height: 220px; resize: vertical; color: var(--fg); font-size: 16px; }

/* Segmented control (Accurate ⇄ Fast) */
.seg-row { display: flex; gap: 0; margin-top: 10px;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg { flex: 1; width: auto; margin: 0; border: none; border-radius: 0;
  background: var(--field); color: var(--muted); font-weight: 600; }
.seg + .seg { border-left: 1px solid var(--border); }
.seg.on { background: var(--accent); color: var(--accent-fg); }

/* Raw / Processed / Edited switch on a note */
.vrow { margin: 10px 0 8px; }
.vseg {
  flex: 1; width: auto; margin: 0; border: none; border-radius: 0;
  background: var(--field); color: var(--muted); font-weight: 600; font-size: 13px;
}
.vseg + .vseg { border-left: 1px solid var(--border); }
.vseg.on { background: var(--accent); color: var(--accent-fg); }
.vseg:disabled { color: #cbd5e1; background: var(--field); cursor: not-allowed; }

/* Action row on a result/history card — one continuous strip of icon+
   label buttons, same border-radius family as the Raw/Processed/Edited
   switch above it. Six buttons share width evenly (flex: 1 1 0). */
.actrow { margin: 10px 0 6px; }
.aseg {
  flex: 1 1 0; min-width: 0; width: auto; margin: 0; border: none;
  border-radius: 0; background: var(--field); color: var(--accent);
  font-weight: 600; font-size: 12px; padding: 7px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.aseg + .aseg { border-left: 1px solid var(--border); }
.aseg.danger { color: var(--err); }
.aseg:active { background: #e0f2fe; }
.aseg svg { display: block; }
.aseg .lbl { font-size: 10px; font-weight: 600; letter-spacing: .01em; }

/* Second action row — the share targets. Sits snug under row 1; icons
   are brand-tinted for fast recognition while row 1 stays accent-blue,
   so the two rows read as "act on the note" vs "send the note". */
.actrow.share { margin-top: 6px; }
.aseg.wa  { color: #25855a; }    /* WhatsApp — green  */
.aseg.em  { color: #b45309; }    /* Email — amber     */
.aseg.sms { color: #0369a1; }    /* SMS — blue        */
.aseg.nt  { color: #7c3aed; }    /* Note → Obsidian — purple */
.aseg.shr { color: #475569; }    /* Share — slate     */

/* Top row of a card: the Raw/AI/Edited view switch beside a big Copy
   button — Copy is by far the most-used action, so it gets the prominent
   top-right slot with a light-blue tint to mark it as primary. */
.toprow { display: flex; gap: 8px; margin: 10px 0 8px; }
.toprow .seg-row { margin: 0; }        /* row owns the spacing now */
.toprow .vrow { flex: 1 1 auto; }      /* view switch grows */
.toprow .copybox { flex: 0 0 44%; background: #e0f2fe; }
.toprow .copybox .aseg { background: #e0f2fe; }

/* Live recording state — Edit records in place (the button IS the Stop
   control); Append shows it as a status while the addendum records on
   the main recorder. Solid red with a white icon+label, clearly distinct
   from idle and from the red-text-on-grey Delete button. A gentle
   brightness pulse signals "recording now". */
.aseg.recording {
  background: var(--err); color: #fff;
  animation: asegRec 1.5s ease-in-out infinite;
}
.aseg.recording svg { stroke: #fff; }
.aseg.recording:active { background: #dc2626; }
@keyframes asegRec {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.17); }
}

/* Record button + waveform float below the header while the result scrolls,
   so on a long transcription the controls are always reachable. */
#dictBar {
  position: sticky; top: var(--hdr, 56px); z-index: 4;
  background: var(--bg); padding-bottom: 8px;
}
/* Record + Pause. Idle: one full-width record button. Recording: the
   two fuse into a single pill — a large Stop region and a large Pause
   region side by side — so Pause is a big target right under the thumb
   (it used to be a small link button on its own). */
#recRow { display: flex; margin-top: 8px; }
#recRow #recordBtn { flex: 1; min-width: 0; }
#recRow #pauseBtn  { flex: 0 0 38%; min-width: 0; }
/* Record / Pause — white with a coloured 2px outline (matches the
   Option-4 Start button). Idle = blue; Stop = red; Pause = amber;
   Resume = green. The tinted-white fills keep each state obvious while
   staying light, in keeping with the rest of the app. */
.record {
  height: 110px; font-size: 20px; font-weight: 600; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--card); color: var(--accent);
  border: 2px solid var(--accent);
  box-shadow: 0 6px 18px rgba(2, 132, 199, .12);
}
.record .ricon { display: flex; line-height: 0; }
.record.rec {                          /* Stop */
  background: #fef2f2; color: var(--err); border-color: var(--err);
  box-shadow: 0 6px 18px rgba(220, 38, 38, .14);
}
.record.pause {                        /* Pause */
  background: #fffbeb; color: #b45309; border-color: #f59e0b;
  box-shadow: 0 6px 18px rgba(245, 158, 11, .14);
}
.record.pause.paused {                 /* Resume */
  background: #f0fdf4; color: #15803d; border-color: #16a34a;
  box-shadow: 0 6px 18px rgba(22, 163, 74, .14);
}
/* While recording the two fuse into one pill: Pause keeps its full amber
   outline (its right edge is the seam); Stop drops its left border so
   there's no double line. A soft red glow gently pulses = "recording". */
#recRow.dual { border-radius: 16px; animation: recPulse 1.9s ease-in-out infinite; }
#recRow.dual .record { box-shadow: none; }
#recRow.dual #pauseBtn  { border-radius: 16px 0 0 16px; }
#recRow.dual #recordBtn { border-radius: 0 16px 16px 0; border-left: none; }
@keyframes recPulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(220, 38, 38, .10); }
  50%      { box-shadow: 0 7px 22px rgba(220, 38, 38, .24); }
}
.viz {
  width: 100%; height: 72px; display: block; margin-top: 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
}
.drop {
  display: block; margin-top: 16px; padding: 28px 16px; text-align: center;
  border: 2px dashed var(--border); border-radius: 14px; color: var(--muted);
  cursor: pointer;
}
.drop.hot { border-color: var(--accent); color: var(--accent); }

.note {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-top: 12px;
}
.note .meta { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.note .st { padding: 1px 8px; border-radius: 999px; background: #e0f2fe; color: var(--accent); }
.note .st.done { background: #dcfce7; color: var(--ok); }
.note .st.error { background: #fee2e2; color: var(--err); }
.note .final { white-space: pre-wrap; margin: 10px 0; }
.note .raw { white-space: pre-wrap; color: var(--muted); font-size: 14px; }
.note .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.note .actions button { width: auto; padding: 8px 12px; margin: 0; }

/* Narrow screens (iPhone): compact, wrapping action buttons. (.aseg now
   has icon+label and is sized compactly at every width — no override
   needed; the action row fits 6 buttons edge-to-edge from base styles.) */
@media (max-width: 560px) {
  .note .actions { gap: 6px; }
  .note .actions button { padding: 6px 8px; font-size: 13px; }
  .tabs .tab { padding: 10px 8px; font-size: 14px; }
}

.modal-ov {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; width: 90%; max-width: 360px;
}
.modal h3 { margin: 0 0 12px; }
.modal button { width: 100%; }

/* 14-day calendar above History — heatmap grid (2 weeks × 7 days), tap a day
   to filter the notes list, tap selected day or the chip to clear. */
#calendar { margin: 14px 0 10px; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  text-align: center; user-select: none;
}
.cal-hd { color: var(--muted); font-size: 11px; padding-bottom: 2px; }
.cal-day {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 0 5px;
  cursor: pointer; line-height: 1.15;
  transition: transform .08s ease;
}
.cal-day:active { transform: scale(.95); }
.cal-day .d { font-size: 12px; color: var(--muted); }
.cal-day .n { font-size: 15px; font-weight: 600; color: var(--text); }
/* Activity heat — light to dark using the accent colour at increasing alpha. */
.cal-day.lv0 .n { color: var(--muted); font-weight: 400; }
.cal-day.lv1 { background: rgba(2, 132, 199, 0.10); }
.cal-day.lv2 { background: rgba(2, 132, 199, 0.22); }
.cal-day.lv3 { background: rgba(2, 132, 199, 0.40); }
.cal-day.lv3 .d, .cal-day.lv3 .n { color: #fff; }
.cal-day.lv4 { background: rgba(2, 132, 199, 0.65); }
.cal-day.lv4 .d, .cal-day.lv4 .n { color: #fff; }
.cal-day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day.selected {
  outline: 2px solid #fbbf24; outline-offset: -2px;
  box-shadow: 0 0 0 1px #fbbf24;
}
.cal-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 6px; color: var(--muted); font-size: 12px;
}
.cal-foot button { font-size: 12px; padding: 2px 6px; }

#dayFilterBar {
  display: flex; align-items: center; gap: 10px;
  background: rgba(251, 191, 36, .14); border: 1px solid #fbbf24;
  border-radius: 10px; padding: 8px 12px; margin: 4px 0 8px;
  font-size: 14px;
}
#dayFilterBar.hidden { display: none; }
#dayFilterBar .clr {
  margin-left: auto; background: none; border: none; color: var(--err);
  font-size: 14px; cursor: pointer; padding: 4px 8px;
}

/* File-clip preview (Clip tab + History) — image thumbnail or icon + size. */
.filecard {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 10px; padding: 6px; margin: 6px 0;
  min-height: 64px;
}
.filecard .thumb {
  max-width: 100%; max-height: 280px; display: block;
  border-radius: 6px; background: var(--card);
}
.filecard .fileicon { color: var(--muted); flex-shrink: 0; }
.filecard .filemeta { color: var(--muted); font-size: 13px; font-weight: 500; }

/* Snippets tab — draggable list of reusable text. */
.snip {
  display: flex; gap: 10px; align-items: stretch;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; margin-top: 8px;
  touch-action: pan-y;                 /* let vertical scroll through; we handle drag */
}
.snip.drag { opacity: .55; }           /* the one currently being dragged */
.snip.over { border-color: var(--accent); }
.snip .grip {
  display: flex; align-items: center; color: var(--muted);
  cursor: grab; user-select: none; padding-right: 2px;
  touch-action: none;                  /* the grip OWNS the gesture (touch + mouse) */
}
.snip .grip:active { cursor: grabbing; }
.snip .body { flex: 1; min-width: 0; }
.snip .title { font-weight: 600; }
.snip .title.untitled { color: var(--muted); font-weight: 500; font-style: italic; }
.snip .preview {
  color: var(--muted); font-size: 13px; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.snip .acts { display: flex; align-items: center; gap: 4px; }
.snip .acts button {
  background: none; border: none; color: var(--accent);
  padding: 6px 8px; font-size: 13px; cursor: pointer; width: auto;
}
.snip .acts button.danger { color: var(--err); }
.snip-empty { text-align: center; color: var(--muted); padding: 24px 0; }
#snipEditTitle { width: 100%; box-sizing: border-box; margin-bottom: 8px; }
#snipEditBody {
  width: 100%; box-sizing: border-box; min-height: 160px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px;
}

#clipText { min-height: 140px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; }
#promptBody { min-height: 320px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; }
.diag {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; max-height: 320px; overflow: auto; white-space: pre-wrap;
  word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--muted); margin-top: 8px;
}
