/* Colour tokens, named for their role. The palette itself is documented in
   CLAUDE.md → Brand; the manifest, icons, and emails carry the same values. */
:root {
  --bg: #f7f5f1;            /* page: warm off-white */
  --surface: #ffffff;       /* cards, sheets, rows */
  --surface-2: #efece6;     /* inputs, chips, secondary buttons */
  --line: #e2ded6;          /* dividers and borders */
  --text: #26231f;          /* charcoal */
  --text-dim: #655f56;
  --accent: #56735f;        /* sage green: focus rings, borders, checkboxes */
  --accent-text: #44604e;   /* accent-coloured text: active tab, links, highlights */
  --accent-fill: #56735f;   /* record button, primary buttons, level bar */
  --on-accent: #ffffff;     /* text and glyphs on --accent-fill */
  --accent-halo: rgba(86, 115, 95, 0.12);
  --accent-ring: rgba(86, 115, 95, 0.45);
  --shadow: rgba(38, 35, 31, 0.14);
  --bar-bg: rgba(255, 255, 255, 0.94);
  --backdrop: rgba(38, 35, 31, 0.35);
  --toast-bg: #26231f;
  --toast-text: #ffffff;
  --danger: #a8402a;
  --on-danger: #ffffff;
  --ok: #2a6e44;
  /* Area chip tones, assigned by an area's position in config. */
  --tone-0: #9a3552;
  --tone-1: #1f5f99;
  --tone-2: #5b4a9e;
  --tone-3: #4a5560;
  --tone-4: #a3452f;
  --tone-5: #8a3f6e;
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0; }

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  max-width: 480px;
  margin: 0 auto;
}

.view { display: flex; flex-direction: column; flex: 1; }
.view[hidden] { display: none; }

/* Sign-in and new-password screens */
.masthead { text-align: center; padding: 48px 0 32px; }
.masthead h1 {
  font-size: 40px;
  background: var(--accent-fill);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 8px 0 0; color: var(--text-dim); font-size: 15px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
label { font-size: 13px; color: var(--text-dim); margin-top: 8px; }
input {
  font: inherit;
  font-size: 17px; /* 16px+ keeps iOS Safari from zooming the page on focus */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
input:focus { border-color: var(--accent); }

.button-primary {
  margin-top: 16px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent-fill);
  border: 0;
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
}
.button-primary:disabled { opacity: 0.6; }
.button-text {
  font: inherit;
  font-size: 15px;
  color: var(--accent-text);
  background: none;
  border: 0;
  padding: 8px;
  cursor: pointer;
}
.error { color: var(--danger); font-size: 14px; margin: 4px 0 0; }
.error[hidden] { display: none; }

/* Home / record screen */
.topbar { display: flex; align-items: center; justify-content: space-between; }
.topbar-date { font-family: var(--serif); font-size: 20px; }

.record-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.record-button {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border: 0;
  background: var(--accent-fill);
  box-shadow: 0 0 0 12px var(--accent-halo), 0 18px 40px var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 120ms ease;
}
.record-button:active { transform: scale(0.96); }
.record-dot {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--on-accent);
}
.record-hint { color: var(--text-dim); font-size: 16px; margin: 0; }

.status { text-align: center; color: var(--text-dim); font-size: 13px; }
.status p { margin: 0; }

/* ---- Milestone 2: recording, typed notes, recent list, settings ---- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.record-stage { gap: 16px; padding: 12px 0 8px; flex: 0 0 auto; }
.record-timer {
  font-family: var(--serif);
  font-size: 40px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  transition: color 200ms ease;
}
.record-stage[data-state="recording"] .record-timer { color: var(--text); }
.record-stage[data-state="ending"] .record-timer { color: var(--danger); }

.level-meter {
  width: 200px;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.level-bar {
  width: 0%;
  height: 100%;
  background: var(--accent-fill);
  transition: width 80ms linear;
}

.record-button { width: 176px; height: 176px; position: relative; }
.record-glyph {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--on-accent);
  transition: border-radius 160ms ease, transform 160ms ease;
}
.record-stage[data-state="recording"] .record-glyph,
.record-stage[data-state="ending"] .record-glyph { border-radius: 12px; transform: scale(0.8); }
.record-stage[data-state="recording"] .record-button::after,
.record-stage[data-state="ending"] .record-button::after {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 2px solid var(--accent-ring);
  animation: pulse 1.4s ease-out infinite;
}
.record-stage[data-state="starting"] .record-button { opacity: 0.7; }
.record-button:disabled { opacity: 0.5; cursor: default; }
@keyframes pulse {
  0% { transform: scale(0.94); opacity: 0.9; }
  100% { transform: scale(1.12); opacity: 0; }
}

/* Typed note */
.text-note { display: flex; gap: 8px; align-items: flex-end; margin-top: 8px; }
textarea {
  flex: 1;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  resize: none;
  outline: none;
  min-height: 48px;
}
textarea:focus { border-color: var(--accent); }
.button-secondary {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--surface-2);
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  cursor: pointer;
}
.button-secondary:disabled { opacity: 0.5; }

/* Recent list */
.recent { margin-top: 24px; }
.recent h2 { font-size: 20px; margin-bottom: 8px; }
.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.recent-empty { color: var(--text-dim); font-size: 14px; margin: 4px 0; }
.recent-empty[hidden] { display: none; }
.recent-item {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
}
.recent-meta { display: flex; gap: 10px; align-items: baseline; font-size: 14px; color: var(--text-dim); }
.recent-time { font-family: var(--serif); font-size: 17px; color: var(--text); }
.recent-text { grid-column: 1 / -1; font-size: 15px; color: var(--text); margin: 2px 0 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.recent-body { grid-column: 1 / -1; }
.recent-text.is-expanded { display: block; -webkit-line-clamp: unset; overflow: visible; }
.button-link {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-text);
  background: none;
  border: 0;
  padding: 6px 0 0;
  cursor: pointer;
}
.button-link[hidden] { display: none; }
.recent-actions { display: flex; gap: 6px; align-items: center; }
.chip {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.chip[data-tone="busy"] { color: var(--accent-text); }
.chip[data-tone="ok"] { color: var(--ok); }
.chip[data-tone="warn"] { color: var(--danger); }
.button-small {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent-fill);
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}
.button-small[data-kind="ghost"] { background: var(--surface-2); color: var(--accent-text); }

/* Settings */
.settings { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.switch-row { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--text); margin: 0; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
.settings-hint { font-size: 13px; color: var(--text-dim); margin: 8px 0 0; line-height: 1.45; }
.settings-hint code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--text); }
.status { margin-top: 16px; }

/* ---- Milestone 4: sorted items, review badge, privacy reminder ---- */
.item-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item { padding: 8px 10px; border-left: 2px solid var(--line); }
.item-text { margin: 0 0 6px; font-size: 15px; color: var(--text); line-height: 1.4; }
.item-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-area[data-tone="0"] { color: var(--tone-0); }
.chip-area[data-tone="1"] { color: var(--tone-1); }
.chip-area[data-tone="2"] { color: var(--tone-2); }
.chip-area[data-tone="3"] { color: var(--tone-3); }
.chip-area[data-tone="4"] { color: var(--tone-4); }
.chip-area[data-tone="5"] { color: var(--tone-5); }
.processing-note { margin: 6px 0 0; font-size: 13px; color: var(--text-dim); font-style: italic; }
.recent-transcript { margin: 6px 0 0; font-size: 14px; color: var(--text-dim); white-space: pre-wrap; }
.recent-transcript[hidden] { display: none; }
.reminder {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--accent);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  max-width: 340px;
}
.reminder[hidden] { display: none; }
.reminder p { margin: 0; font-size: 14px; color: var(--text); line-height: 1.4; }

/* ---- Milestone 5a: tab bar, day view, open view, editing sheets ---- */
.app { padding-bottom: calc(var(--safe-bottom) + 76px); }
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-around;
  padding: 8px 8px calc(var(--safe-bottom) + 8px);
  background: var(--bar-bg);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.tabbar[hidden] { display: none; }
.tabbar button {
  flex: 1;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  background: none;
  border: 0;
  border-radius: 10px;
  padding: 10px 0;
  cursor: pointer;
}
.tabbar button[aria-current="page"] { color: var(--accent-text); background: var(--surface); }

.view-heading { font-size: 24px; }
.dayhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.button-icon {
  font: inherit;
  font-size: 22px;
  line-height: 1;
  color: var(--accent-text);
  background: var(--surface);
  border: 0;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  cursor: pointer;
}
.button-icon:disabled { opacity: 0.4; }
.day-title-wrap { position: relative; flex: 1; text-align: center; }
.day-title { font-family: var(--serif); font-size: 22px; color: var(--text); }
/* The native date picker sits invisibly over the title so tapping the title opens it. */
.day-title-wrap input[type="date"] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }

.carry { margin: 8px 0 16px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border-left: 3px solid var(--accent); }
.carry h2 { font-size: 15px; margin: 0 0 6px; color: var(--accent-text); }
.area-group { margin-top: 18px; }
.area-heading { font-size: 20px; margin: 0 0 4px; }
.area-heading[data-tone="0"] { color: var(--tone-0); } .area-heading[data-tone="1"] { color: var(--tone-1); }
.area-heading[data-tone="2"] { color: var(--tone-2); } .area-heading[data-tone="3"] { color: var(--tone-3); }
.area-heading[data-tone="4"] { color: var(--tone-4); } .area-heading[data-tone="5"] { color: var(--tone-5); }
.type-heading { font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); margin: 10px 0 4px; }

.item-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.item-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
}
.item-row.is-done .item-text { text-decoration: line-through; color: var(--text-dim); }
.item-row.is-selectable { cursor: pointer; outline: 2px solid transparent; }
.item-row.is-selectable[aria-selected="true"] { outline-color: var(--accent); background: var(--surface-2); }
.item-done { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); }
.item-body { min-width: 0; }
.item-row .item-text { margin: 0 0 6px; }
.item-meta { margin: 6px 0 0; font-size: 12px; color: var(--text-dim); }
.item-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.merge-bar {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--safe-bottom) + 84px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  z-index: 21;
}
.merge-bar[hidden] { display: none; }
.merge-bar span { flex: 1; font-size: 14px; }

.sheet {
  border: 0;
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  width: 100%;
  max-width: 480px;
  /* Bottom sheet on phones; centred at the bottom on wider screens. */
  margin: auto auto 0;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: var(--backdrop); }
.sheet-heading { font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); margin: 12px 0 6px; }
.sheet-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-pick { font-size: 14px; padding: 8px 12px; border: 1px solid transparent; background: var(--surface-2); color: var(--text); cursor: pointer; }
.chip-pick[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-text); }
.sheet-action {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: none;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 14px 4px;
  cursor: pointer;
}
.sheet-action:first-of-type { margin-top: 12px; }
.sheet-action[data-kind="danger"] { color: var(--danger); }
.sheet-action[data-kind="ghost"] { color: var(--text-dim); text-align: center; }
.sheet textarea { width: 100%; }
.sheet-hint { font-size: 13px; color: var(--text-dim); margin: 8px 0 0; }
.sheet-buttons { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.spacer { flex: 1; }
.button-small[data-kind="danger"] { background: var(--danger); color: var(--on-danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 92px);
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 14px;
  z-index: 30;
  max-width: 90vw;
}
.toast[hidden] { display: none; }

/* ---- Milestone 5b: search ---- */
.search-form { display: flex; gap: 8px; margin-bottom: 8px; }
.search-form input[type="search"] { flex: 1; min-width: 0; }
.search-meta { display: flex; align-items: baseline; gap: 10px; }
.search-summary { font-size: 13px; color: var(--text-dim); }
.search-filters { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 12px; padding: 12px; border-radius: 12px; background: var(--surface); }
.search-filters[hidden] { display: none; }
.search-filters label { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.search-filters select, .search-filters input[type="date"] {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface-2);
  border: 1px solid transparent; border-radius: 10px; padding: 10px 12px;
}
.date-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface-2);
  border: 1px solid transparent; border-radius: 999px; padding: 7px 12px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-text); }
.search-count { font-size: 13px; color: var(--text-dim); margin: 4px 0 8px; min-height: 1em; }
.item-text.is-link { cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.tabbar button { font-size: 13px; }

/* ---- Milestone 5b additions: History ---- */
.history-day { margin-top: 16px; }
.history-day .recent-list { margin-top: 6px; }
.history-more { display: block; margin: 16px auto 0; }
.history-more[hidden] { display: none; }
.tabbar button { font-size: 12px; padding: 10px 0; }

/* Shown only if the app fails to start (see boot-guard.js). */
.boot-failed {
  position: fixed; inset: auto 16px calc(var(--safe-bottom) + 96px) 16px;
  max-width: 440px; margin: 0 auto; padding: 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--accent); color: var(--text); z-index: 50;
}
.boot-failed p { margin: 0 0 12px; font-size: 15px; line-height: 1.4; }

.search-field { position: relative; flex: 1; min-width: 0; display: flex; }
.search-field input[type="search"] { flex: 1; min-width: 0; padding-right: 44px; }
/* Hide the platform's own clear control so there is exactly one. */
.search-field input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }
.search-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--text); font-size: 15px; cursor: pointer;
}
.search-clear[hidden] { display: none; }

.sheet-transcript { margin: 0 0 8px; font-size: 15px; line-height: 1.45; color: var(--text); white-space: pre-wrap; max-height: 50vh; overflow-y: auto; }

/* ---- Milestone 6: reminders, Reminder sheet, email ---- */
.switch-row-spaced { margin-top: 18px; }
.settings-button { margin-top: 10px; }
.day-tools { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.sheet-item-text { margin: 0 0 6px; font-size: 16px; line-height: 1.45; color: var(--text); }
.sheet .switch-row { margin-top: 12px; }
.sheet-action:disabled { color: var(--text-dim); opacity: 0.5; cursor: default; }

/* ---- Two-step sign-in ---- */
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; font-size: 15px; color: var(--text); }
.totp-link { display: inline-block; text-decoration: none; margin: 6px 0 4px; }
.totp-key { font-family: ui-monospace, Menlo, monospace; font-size: 16px; letter-spacing: 0.04em; color: var(--text); background: var(--surface-2); padding: 10px 12px; border-radius: 10px; margin: 4px 0 12px; user-select: all; -webkit-user-select: all; word-break: normal; }
#totp-code, #mfa-code { width: 100%; font-size: 22px; letter-spacing: 0.3em; text-align: center; }
