/* ============================================================================
   Munshi — "Executive Slate" design system
   Dark-first, professional/editorial. Space Grotesk headings + Inter body.
   Restyled via ui-ux-pro-max design intelligence (accessibility-first).
   All element ids/classes preserved — recorder.js DOM contract is untouched.
   ============================================================================ */

/* ── Tokens: LIGHT (default :root) ── */
:root {
  --font-head: 'Space Grotesk', 'Inter', 'Hind Siliguri', sans-serif;
  --font-body: 'Inter', 'Hind Siliguri', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;

  --bg-start: #F4F0E5;
  --bg-end: #EDE7D8;
  --card-bg: #FFFFFF;
  --card-header-bg: #F7F1E4;
  --card-header-color: #6B5E45;
  --border: #D8CBAD;
  --border-strong: #C6B58F;
  --text: #1B2430;
  --text-muted: #6B5E45;
  --text-faint: #9A8C72;
  --chat-bg: #FFFFFF;
  --bubble-in-bg: #F0EADB;
  --bubble-in-text: #1B2430;
  --doc-bg: #FFFFFF;
  --doc-h1: #1B2430;
  --doc-h2: #8A6520;
  --doc-text: #2A3342;
  --placeholder: #B3A88E;
  --header-bg: rgba(244,240,229,0.85);
  --header-text: #1B2430;
  --upload-border: #D3C6A9;
  --upload-bg: #FBF8F0;
  --upload-text: #8A6520;
  --upload-hover: #F0EADB;
  --status-bg: rgba(27,36,48,0.05);
  --progress-bg: rgba(27,36,48,0.08);
  --progress-fill: #C9A24A;

  --accent: #C9A24A;
  --accent-strong: #8A6520; /* darkened from #B5852F — AA contrast fix for small gold text on paper */
  --accent-contrast: #1B2430;
  --accent-soft: rgba(201,162,74,0.12);
  --accent-ring: rgba(201,162,74,0.38);

  --success: #16A34A;
  --warn: #B45309;
  --danger: #DC2626;

  --radius-card: 14px;
  --radius-ctl: 10px;
  --shadow-card: 0 1px 2px rgba(74,58,26,0.07), 0 6px 18px rgba(74,58,26,0.10), 0 16px 40px rgba(74,58,26,0.06);

  /* Type scale */
  --fs-eyebrow: 0.6875rem;  /* 11px — uppercase micro labels */
  --fs-caption: 0.75rem;    /* 12 */
  --fs-small: 0.8125rem;    /* 13 */
  --fs-body: 0.9375rem;     /* 15 — default body */
  --fs-lead: 1.0625rem;     /* 17 */
  --fs-h3: 1.25rem;         /* 20 */
  --fs-h2: 1.5rem;          /* 24 */
  --fs-h1: 2rem;            /* 32 */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Motion tokens (transform/opacity/color only — never width/height/top/left) */
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Tokens: DARK (default theme in markup) ── */
[data-theme="dark"] {
  --bg-start: #14181F;
  --bg-end: #191E27;
  --card-bg: #1C222C;
  --card-header-bg: #232A35;
  --card-header-color: #A99B7E;
  --border: #333B47;
  --border-strong: #454F5E;
  --text: #F0EADB;
  --text-muted: #A99B7E;
  --text-faint: #6E6552;
  --chat-bg: #171C24;
  --bubble-in-bg: #262D38;
  --bubble-in-text: #F0EADB;
  --doc-bg: #1C222C;
  --doc-h1: #F4F0E5;
  --doc-h2: #D2AC57;
  --doc-text: #D7CFBE;
  --placeholder: #6E6552;
  --header-bg: rgba(20,24,31,0.78);
  --header-text: #F4F0E5;
  --upload-border: #454F5E;
  --upload-bg: #232A35;
  --upload-text: #D2AC57;
  --upload-hover: #262D38;
  --status-bg: rgba(240,234,219,0.06);
  --progress-bg: rgba(240,234,219,0.07);
  --progress-fill: #C9A24A;

  --accent: #D2AC57;
  --accent-strong: #E0BE6A;
  --accent-contrast: #14181F;
  --accent-soft: rgba(210,172,87,0.16);
  --accent-ring: rgba(210,172,87,0.42);

  --success: #22C55E;
  --warn: #F59E0B;
  --danger: #F87171;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.03), 0 12px 32px rgba(0,0,0,0.45);
}

/* ── Reset ── */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  background:
    radial-gradient(1100px 620px at 82% -12%, color-mix(in srgb, var(--accent) 12%, transparent) 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-start) 0%, var(--bg-end) 100%);
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: background var(--dur-slow) var(--ease-standard), color var(--dur-slow) var(--ease-standard);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Accessible focus ring for every interactive control (skill priority #1).
   Uses --accent-strong (darker gold, ~4.5:1+ on paper) rather than --accent,
   which is too close in luminance to card/paper backgrounds to reliably hit
   the 3:1 non-text contrast minimum. */
:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
  border-radius: 6px;
}
/* On gold-background controls the ring above would blend into its own
   surface — swap to the ink/paper contrast color instead (~6.5:1+ on gold). */
.btn-record:focus-visible,
.composer-record:focus-visible,
#btn-refine:focus-visible,
.auth-form .btn-accent:focus-visible {
  outline-color: var(--accent-contrast);
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--header-bg);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  color: var(--header-text);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  flex-shrink: 0;
  z-index: 10;
}
.app-title {
  font-family: var(--font-head);
  font-size: var(--fs-body);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.app-icon { width: 22px; height: 22px; border-radius: 6px; flex-shrink: 0; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-status {
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  background: var(--status-bg);
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--text-muted);
  white-space: nowrap;
}
.btn-theme {
  background: var(--status-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px; height: 32px;
  cursor: pointer;
  font-size: var(--fs-body);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease-standard), border-color var(--dur) var(--ease-standard), transform var(--dur-fast) var(--ease-out);
}
.btn-theme:hover { background: var(--accent-soft); border-color: var(--accent); transform: translateY(-1px); }
.btn-theme:active { transform: scale(0.97); }

/* ── Progress bar ── */
.progress-bar-wrap {
  height: 2px;
  background: var(--progress-bg);
  flex-shrink: 0;
  display: none;
  overflow: hidden;
}
body[data-state="processing"] .progress-bar-wrap { display: block; }
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.6s ease;
  width: 0%;
}

/* ── Grid ── */
.app-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 5fr 7fr;
  grid-template-rows: 2fr 2.8fr;
  grid-template-areas:
    "recorder canvas"
    "raw      canvas";
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

/* ── Cards ── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  transition: background var(--dur-slow) var(--ease-standard), border-color var(--dur-slow) var(--ease-standard);
  position: relative;
}
.card-recorder { grid-area: recorder; }
.card-raw      { grid-area: raw; }
.card-canvas   { grid-area: canvas; grid-row: 1 / 3; }

/* Loading dot in header */
.card.loading .card-header::after {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 8px;
  animation: pulse-fast 0.9s ease-in-out infinite;
  vertical-align: middle;
}

.loading-hint {
  display: none;
  position: relative;
  overflow: hidden;
  font-size: var(--fs-caption);
  color: var(--text-muted);
  font-family: var(--font-body);
  padding: 7px 16px;
  flex-shrink: 0;
  background: var(--card-header-bg);
  border-bottom: 1px solid var(--border);
  transition: opacity var(--dur) var(--ease-standard);
}
.card.loading .loading-hint { display: block; }
.loading-hint::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 40%, var(--accent-strong) 60%, transparent 100%);
  background-size: 300% 100%;
  animation: card-shimmer 1.4s ease-in-out infinite;
}
@keyframes card-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.card-header {
  padding: 11px 16px;
  font-family: var(--font-head);
  font-size: var(--fs-caption);
  font-weight: var(--fw-semibold);
  color: var(--card-header-color);
  text-transform: uppercase;
  letter-spacing: 1.1px;
  border-bottom: 1px solid var(--border);
  background: var(--card-header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  transition: background var(--dur-slow) var(--ease-standard), border-color var(--dur-slow) var(--ease-standard);
}
.card-body { flex: 1; overflow-y: auto; min-height: 0; }

/* ── Legacy recorder controls (kept for safety; current UI uses composer) ── */
.recorder-body { padding: 20px 28px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.recorder-body > * { width: 100%; }
.status-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: var(--fs-h2); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums;
  font-family: var(--font-mono); color: var(--text);
}
.pulse-ring {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-muted); animation: pulse 2s infinite; flex-shrink: 0;
}
body[data-state="recording"] .pulse-ring { background: var(--danger); animation: pulse-fast 0.6s infinite; }
body[data-state="processing"] .pulse-ring { background: var(--warn); animation: pulse-fast 0.4s infinite; }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)}50%{opacity:.4;transform:scale(1.3)} }
@keyframes pulse-fast { 0%,100%{opacity:1;transform:scale(1)}50%{opacity:.5;transform:scale(1.4)} }

#visualizer {
  width: 100%; height: 56px; border-radius: 10px;
  background: var(--card-header-bg); border: 1px solid var(--border); display: none;
}
body[data-state="recording"] #visualizer { display: block; }

.btn-record, .btn-pause {
  width: 100%; max-width: 280px; color: #fff; border: none;
  padding: 11px 20px; font-size: var(--fs-body); border-radius: var(--radius-ctl);
  cursor: pointer; font-family: var(--font-body); font-weight: var(--fw-semibold);
  transition: opacity var(--dur) var(--ease-standard), transform var(--dur-fast) var(--ease-out), box-shadow var(--dur) var(--ease-standard);
}
.btn-record { background: var(--accent); box-shadow: 0 4px 14px var(--accent-soft); }
.btn-pause  { background: var(--warn); }
.btn-record:hover, .btn-pause:hover { opacity: 0.92; transform: translateY(-1px); }
.btn-record:active, .btn-pause:active { transform: scale(0.97); }
body[data-state="recording"] .btn-record { background: var(--danger); box-shadow: none; }
body[data-state="processing"] .btn-record { background: var(--text-faint); cursor: not-allowed; box-shadow: none; }
body[data-state="processing"] .btn-pause { display: none; }

.divider { width:100%; display:flex; align-items:center; gap:10px; color:var(--text-muted); font-size:var(--fs-caption); }
.divider::before,.divider::after { content:''; flex:1; height:1px; background:var(--border); }

.btn-upload {
  width: 100%; max-width: 280px; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--upload-bg); color: var(--upload-text);
  border: 1.5px dashed var(--upload-border); padding: 10px 20px;
  font-size: var(--fs-body); border-radius: var(--radius-ctl); cursor: pointer;
  font-family: var(--font-body); font-weight: var(--fw-semibold);
  transition: background var(--dur) var(--ease-standard), border-color var(--dur) var(--ease-standard), transform var(--dur-fast) var(--ease-out);
}
.btn-upload:hover { background: var(--upload-hover); border-color: var(--upload-text); }
.btn-upload:active { transform: scale(0.97); }
body[data-state="processing"] .btn-upload,
body[data-state="recording"] .btn-upload { opacity: 0.35; pointer-events: none; }

.upload-filename { font-size: var(--fs-caption); color: var(--upload-text); min-height: 1em; text-align: center; }
.current-filename { font-size: var(--fs-caption); color: var(--text-muted); text-align: center; word-break: break-all; }
.current-filename a { color: var(--accent-strong); text-decoration: none; font-weight: var(--fw-semibold); }
.current-filename a:hover { text-decoration: underline; }

.upload-status {
  width: 100%; max-width: 340px; margin: 0 auto;
  background: var(--status-bg); border: 1px solid var(--border); border-radius: var(--radius-ctl);
  padding: 8px 13px; font-size: var(--fs-small); color: var(--text-muted);
  display: flex; align-items: center; gap: 7px; font-family: var(--font-body);
}
.upload-status.info { color: var(--accent-strong); background: var(--accent-soft); border-color: var(--accent-ring); }
.upload-status.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: color-mix(in srgb, var(--warn) 34%, transparent); }

/* ── Composer (top-left, LLM-style) ── */
.composer-body { padding: 22px 24px; display: flex; flex-direction: column; justify-content: center; }
.composer-inner { width: 100%; max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

.composer-greeting { text-align: center; }
.composer-greeting h2 {
  font-family: var(--font-head);
  font-size: var(--fs-h2); font-weight: var(--fw-semibold); color: var(--text);
  margin: 0 0 7px; letter-spacing: -0.02em;
}
.composer-greeting p { font-size: var(--fs-small); color: var(--text-muted); margin: 0 auto; max-width: 430px; line-height: 1.55; }

.composer-tray { margin: 0; justify-content: center; }
.composer-tray:empty { display: none; }

.composer-recording { display: none; flex-direction: column; gap: 10px; }
body[data-state="recording"] .composer-recording,
body[data-state="paused"] .composer-recording { display: flex; }
.rec-meta {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  font-size: var(--fs-lead); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums;
  font-family: var(--font-mono); color: var(--text);
}

/* Input box: textarea + toolbar */
.composer-box {
  background: var(--card-header-bg); border: 1px solid var(--border);
  border-radius: 16px; padding: 8px; display: flex; flex-direction: column; gap: 4px;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.composer-input {
  width: 100%; box-sizing: border-box; resize: none; min-height: 56px; max-height: 220px;
  background: transparent; color: var(--text); border: none;
  padding: 9px 11px; font-family: var(--font-body); font-size: var(--fs-body); line-height: 1.55;
}
.composer-input::placeholder { color: var(--placeholder); }
.composer-input:focus { outline: none; }

.composer-toolbar { display: flex; align-items: center; gap: 4px; padding: 0 2px 2px; }

.composer-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-ctl); cursor: pointer; flex-shrink: 0;
  background: transparent; color: var(--text-muted); border: none;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.composer-icon-btn:hover { background: var(--accent-soft); color: var(--accent-strong); }
.composer-icon-btn:active { transform: scale(0.97); }
.composer-icon-btn[hidden] { display: none; }   /* hidden attr must beat inline-flex */
.composer-icon-btn svg { width: 19px; height: 19px; }

.composer-record {
  margin-left: auto; height: 34px; display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent); color: var(--accent-contrast); border: none; border-radius: var(--radius-ctl);
  padding: 0 16px; font-family: var(--font-head); font-weight: var(--fw-semibold); font-size: var(--fs-small);
  cursor: pointer;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
  box-shadow: 0 2px 10px var(--accent-soft);
}
.composer-record:hover { transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-ring); }
.composer-record:active { transform: scale(0.97); }
.composer-record svg { width: 17px; height: 17px; }
body[data-state="recording"] .composer-record { background: var(--danger); color: #fff; box-shadow: none; }
body[data-state="processing"] .composer-record { background: var(--text-faint); color: #fff; cursor: not-allowed; pointer-events: none; box-shadow: none; }

body[data-state="processing"] .composer-toolbar label,
body[data-state="recording"] .composer-toolbar label { opacity: 0.4; pointer-events: none; }
body[data-state="processing"] .composer-input { opacity: 0.6; pointer-events: none; }

/* Image thumbnails in the tray */
.ref-chip-img { padding: 0; position: relative; background: none; border: none; }
.ref-chip-img img { width: 46px; height: 46px; object-fit: cover; border-radius: 9px; display: block; border: 1px solid var(--border); }
.ref-chip-img button {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; padding: 0;
  display: flex; align-items: center; justify-content: center; font-size: var(--fs-caption); line-height: 1;
  border-radius: 50%; background: var(--card-bg); border: 1px solid var(--border); color: var(--text-muted); cursor: pointer;
}
.ref-chip-img button:hover { color: var(--danger); border-color: var(--danger); }

/* ── Chat / Raw transcription ── */
.chat-window { padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--chat-bg); }
.chat-placeholder { color: var(--placeholder); font-size: var(--fs-small); text-align: center; margin: auto; }

.msg-row { display: flex; align-items: flex-end; gap: 8px; }
.msg-row.right { justify-content: flex-end; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 5px;
}
.avatar svg { width:100%; height:100%; }
.av1 { background: #0EA5E9; }
.av2 { background: #6366F1; }
.av3 { background: #8B5CF6; }
.av4 { background: #F59E0B; }
[data-theme="dark"] .av1 { background: #38BDF8; }
[data-theme="dark"] .av2 { background: #818CF8; }
[data-theme="dark"] .av3 { background: #A78BFA; }
[data-theme="dark"] .av4 { background: #FBBF24; }

.msg-content { display:flex; flex-direction:column; gap:3px; max-width:78%; }
.msg-row.right .msg-content { align-items: flex-end; }
.msg-label { font-size:var(--fs-eyebrow); color:var(--text-muted); font-weight:var(--fw-semibold); padding:0 4px; font-family:var(--font-body); }

.bubble {
  padding: 8px 12px; border-radius: 14px; font-size: var(--fs-body); line-height: 1.65;
  word-wrap: break-word; font-family: 'Hind Siliguri', var(--font-body);
}
.bubble.sp1 { background: #0EA5E9; color: #fff; border-bottom-right-radius: 4px; }
.bubble.sp2 { background: #6366F1; color: #fff; border-bottom-left-radius: 4px; }
.bubble.sp3 { background: #8B5CF6; color: #fff; border-bottom-right-radius: 4px; }
.bubble.sp4 { background: #D97706; color: #fff; border-bottom-left-radius: 4px; }
.bubble.sp-solo { background: #0EA5E9; color: #fff; border-bottom-right-radius: 4px; }
[data-theme="dark"] .bubble.sp1 { background: #0C4A6E; color: #E6EDF6; }
[data-theme="dark"] .bubble.sp2 { background: #312E81; color: #E6EDF6; }
[data-theme="dark"] .bubble.sp3 { background: #4C1D95; color: #E6EDF6; }
[data-theme="dark"] .bubble.sp4 { background: #78350F; color: #E6EDF6; }
[data-theme="dark"] .bubble.sp-solo { background: #0C4A6E; color: #E6EDF6; }
.bubble.left-in { background: var(--bubble-in-bg); color: var(--bubble-in-text); }

.card-badge {
  font-family: var(--font-body);
  font-size: var(--fs-eyebrow); background: var(--accent-soft); color: var(--accent-strong);
  padding: 3px 9px; border-radius: 999px; font-weight: var(--fw-semibold); letter-spacing: 0.3px; white-space: nowrap;
}

/* ── Document canvas ── */
.doc-canvas {
  padding: 44px 56px; background: var(--doc-bg); overflow-y: auto; transition: background var(--dur-slow) var(--ease-standard);
}
/* Doc-type chooser */
.doc-choice { display: flex; flex-direction: column; height: 100%; justify-content: center; padding: 8px 4px; gap: 6px; }
.doc-choice-title { font-family: var(--font-head); font-size: var(--fs-lead); font-weight: var(--fw-semibold); color: var(--text); text-align: center; letter-spacing: -0.01em; }
.doc-choice-sub { font-size: var(--fs-small); color: var(--text-muted); text-align: center; margin-bottom: 18px; min-height: 1.2em; }
.doc-choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; max-width: 640px; width: 100%; margin: 0 auto; }
.doc-choice-card {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 18px 18px 18px 50px; background: var(--card-header-bg); border: 1px solid var(--border);
  border-radius: 12px; cursor: pointer; text-align: left;
  transition: border-color var(--dur) var(--ease-standard), transform var(--dur-fast) var(--ease-out), background var(--dur) var(--ease-standard), box-shadow var(--dur) var(--ease-standard);
  font-family: inherit;
}
.doc-choice-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 22px var(--accent-soft); }
.doc-choice-card:active { transform: scale(0.97); }
.doc-choice-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.doc-choice-num {
  position: absolute; left: 16px; top: 18px; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center; border-radius: 8px;
  background: var(--accent); color: var(--accent-contrast); font-family: var(--font-head);
  font-size: var(--fs-small); font-weight: var(--fw-semibold);
}
.doc-choice-name { font-family: var(--font-head); font-size: var(--fs-body); font-weight: var(--fw-semibold); color: var(--text); }
.doc-choice-desc { font-size: var(--fs-small); line-height: 1.45; color: var(--text-muted); }

/* Executive document output */
.exec-doc { font-family: var(--font-body); max-width: 860px; }
.doc-title {
  font-family: var(--font-head);
  font-size: var(--fs-h1); font-weight: var(--fw-bold); color: var(--doc-h1); line-height: 1.2;
  border-bottom: 2px solid var(--border-strong); padding-bottom: 16px; margin-bottom: 26px; letter-spacing: -0.02em;
}
.callout-box {
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0; padding: 18px 22px; margin-bottom: 28px;
}
.callout-label {
  font-family: var(--font-head);
  font-size: var(--fs-eyebrow); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--accent-strong); margin-bottom: 8px;
}
.metrics-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 28px; }
.metric-card {
  flex: 1; min-width: 110px; background: var(--card-header-bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; text-align: center;
}
.metric-value { font-family: var(--font-head); font-size: var(--fs-h2); font-weight: var(--fw-bold); color: var(--accent-strong); line-height: 1.1; margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.metric-label { font-size: var(--fs-eyebrow); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.7px; font-weight: var(--fw-semibold); }

.doc-section { margin-bottom: 28px; }
.doc-h2 {
  font-family: var(--font-head);
  font-size: var(--fs-caption); font-weight: var(--fw-bold); color: var(--doc-h2); text-transform: uppercase; letter-spacing: 1.3px;
  margin-bottom: 12px; padding-bottom: 7px; border-bottom: 1px solid var(--border);
}
.doc-h3 { font-family: var(--font-head); font-size: var(--fs-body); font-weight: var(--fw-semibold); color: var(--doc-h1); margin: 16px 0 7px; }
.doc-p { font-size: var(--fs-body); line-height: 1.8; color: var(--doc-text); margin-bottom: 11px; }
.doc-ul { list-style: none; padding: 0; margin-bottom: 11px; display: flex; flex-direction: column; gap: 7px; }
.doc-li { font-size: var(--fs-body); line-height: 1.7; color: var(--doc-text); padding-left: 22px; position: relative; }
.doc-li::before { content: '▸'; position: absolute; left: 2px; color: var(--accent-strong); font-size: var(--fs-caption); top: 5px; }

.doc-table { width: 100%; border-collapse: collapse; font-size: var(--fs-body); margin-bottom: 11px; }
.doc-table th {
  background: var(--accent); color: var(--accent-contrast); padding: 10px 13px; text-align: left;
  font-family: var(--font-head); font-weight: var(--fw-semibold); font-size: var(--fs-caption); text-transform: uppercase; letter-spacing: 0.6px;
}
.doc-table th:first-child { border-top-left-radius: 8px; }
.doc-table th:last-child { border-top-right-radius: 8px; }
.doc-table td { padding: 9px 13px; color: var(--doc-text); border-bottom: 1px solid var(--border); vertical-align: top; line-height: 1.5; }
.doc-table tr:nth-child(even) td { background: var(--accent-soft); }

.chart-wrap { background: var(--card-header-bg); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 11px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 11px; }

/* Document header actions */
.doc-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn-copy {
  background: var(--status-bg); color: var(--text); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 7px; font-size: var(--fs-caption); cursor: pointer;
  font-family: var(--font-body); font-weight: var(--fw-semibold); letter-spacing: 0.2px; white-space: nowrap;
  transition: background var(--dur) var(--ease-standard), border-color var(--dur) var(--ease-standard), transform var(--dur-fast) var(--ease-out);
}
.btn-copy:hover { background: var(--upload-hover); border-color: var(--border-strong); }
.btn-copy:active { transform: scale(0.97); }
.model-select {
  background: var(--card-bg); color: var(--text); border: 1px solid var(--border);
  padding: 5px 9px; border-radius: 7px; font-size: var(--fs-caption); font-family: var(--font-body);
  font-weight: var(--fw-semibold); letter-spacing: 0.2px; cursor: pointer; transition: border-color var(--dur) var(--ease-standard);
}
.model-select:hover { border-color: var(--accent); }
.model-select option { background: var(--card-bg); color: var(--text); }

/* Refinement bar */
.refine-bar { display: flex; gap: 9px; padding: 12px 14px; border-top: 1px solid var(--border); background: var(--card-header-bg); flex-shrink: 0; }
#refine-input {
  flex: 1; background: var(--card-bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; font-family: var(--font-body); font-size: var(--fs-small); resize: none; min-height: 34px; max-height: 80px;
  transition: border-color var(--dur) var(--ease-standard), box-shadow var(--dur) var(--ease-standard);
}
#refine-input::placeholder { color: var(--placeholder); }
#refine-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
#btn-refine {
  background: var(--accent); color: var(--accent-contrast); border: none; border-radius: 8px; padding: 8px 18px;
  font-family: var(--font-head); font-size: var(--fs-small); font-weight: var(--fw-semibold); cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur) var(--ease-standard);
}
#btn-refine:hover { transform: translateY(-1px); box-shadow: 0 4px 14px var(--accent-ring); }
#btn-refine:active { transform: scale(0.97); }
.card.loading #btn-refine { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* Reference chips */
.btn-upload-ref { margin-top: 8px; }
.ref-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ref-chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--text);
  border: 1px solid var(--accent-ring); border-radius: 999px; padding: 4px 11px; font-size: var(--fs-caption); font-weight: var(--fw-semibold);
}
.ref-chip button { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: var(--fs-small); line-height: 1; padding: 0; }
.ref-chip button:hover { color: var(--danger); }

/* Markdown playbook rendering */
.md-doc { font-family: var(--font-body); font-size: var(--fs-body); line-height: 1.75; color: var(--doc-text); max-width: 860px; }
.md-doc h1 { font-family: var(--font-head); font-size: var(--fs-h2); font-weight: var(--fw-bold); color: var(--doc-h1); margin: 0 0 18px; padding-bottom: 12px; border-bottom: 2px solid var(--border-strong); letter-spacing: -0.02em; }
.md-doc h2 { font-family: var(--font-head); font-size: var(--fs-lead); font-weight: var(--fw-semibold); margin: 24px 0 10px; color: var(--doc-h2); }
.md-doc h3 { font-family: var(--font-head); font-size: var(--fs-body); font-weight: var(--fw-semibold); color: var(--doc-h1); margin: 16px 0 6px; }
.md-doc p { margin: 0 0 11px; }
.md-doc ul, .md-doc ol { margin: 0 0 12px; padding-left: 22px; }
.md-doc li { margin-bottom: 6px; }
.md-doc code { background: var(--status-bg); padding: 1px 6px; border-radius: 5px; font-family: var(--font-mono); font-size: 0.86em; }
.md-doc pre { background: var(--card-header-bg); border: 1px solid var(--border); padding: 13px 15px; border-radius: 10px; overflow-x: auto; }
.md-doc pre code { background: none; padding: 0; }
.md-doc table { width: 100%; border-collapse: collapse; margin: 0 0 14px; font-size: var(--fs-body); }
.md-doc th { background: var(--accent); color: var(--accent-contrast); padding: 9px 12px; text-align: left; font-family: var(--font-head); font-weight: var(--fw-semibold); }
.md-doc td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.md-doc strong { font-weight: var(--fw-bold); color: var(--text); }
.md-doc blockquote { border-left: 3px solid var(--accent); margin: 0 0 12px; padding: 6px 16px; color: var(--text-muted); background: var(--accent-soft); border-radius: 0 8px 8px 0; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: #0B1120; color: #E6EDF6; padding: 11px 20px; border-radius: 10px;
  border: 1px solid var(--border-strong);
  opacity: 0; transition: opacity var(--dur-slow) var(--ease-standard), transform var(--dur-slow) var(--ease-standard); pointer-events: none; z-index: 1000;
  font-size: var(--fs-small); font-family: var(--font-body); font-weight: var(--fw-medium);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}
.toast.show { opacity:1; transform:translateX(-50%) translateY(0); pointer-events:auto; }
.toast.success { background: var(--success); color: #fff; border-color: transparent; }
.toast.error { background: var(--danger); color: #fff; border-color: transparent; }

/* ── Print ── */
@media print {
  body { background: #fff !important; overflow: auto; }
  .app-header, .app-grid > .card-recorder, .app-grid > .card-raw,
  .progress-bar-wrap, .toast, .card-header .doc-actions, .refine-bar { display: none !important; }
  .app-grid { display: block !important; padding: 0 !important; }
  .card-canvas { box-shadow: none !important; border: none !important; border-radius: 0 !important; height: auto !important; }
  .card-canvas .card-header { display: none !important; }
  .doc-canvas { padding: 20mm 25mm !important; overflow: visible !important; height: auto !important; }
  .exec-doc, .md-doc { max-width: 100% !important; }
  .doc-title, .md-doc h1 { color: #0B1120 !important; }
  .doc-h2, .md-doc h2 { color: var(--doc-h2) !important; }
  .doc-p, .doc-li, .doc-table td { color: #26324A !important; }
  .metric-card { border: 1px solid #DCE3EE !important; background: #F4F7FB !important; }
  .metric-value { color: var(--accent-strong) !important; }
  .chart-wrap { border: 1px solid #DCE3EE !important; background: #fff !important; }
  .doc-table th, .md-doc th { background: var(--accent) !important; color: var(--accent-contrast) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .callout-box { border-left: 3px solid var(--accent) !important; background: var(--accent-soft) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Responsive ── */
@media (max-width: 860px) {
  html, body { overflow: auto; }
  .app-grid {
    grid-template-columns: 1fr; grid-template-rows: auto;
    grid-template-areas: "recorder" "raw" "canvas"; height: auto;
  }
  .card { min-height: 280px; }
  .card-canvas { grid-row: auto; }
  .doc-canvas { padding: 24px; }
}

/* ── Reduced motion (skill accessibility priority) ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  /* Neutralize the press/hover lift+scale effects (Task 5) — but not base
     positioning transforms like .toast's translateX(-50%) centering, which
     aren't tied to :hover/:active and so are untouched by this selector. */
  :hover, :active {
    transform: none !important;
  }
}

/* ── Auth (login/signup page) ──
   No standalone --bg / --card tokens exist; nearest equivalents used:
   --bg-start (page background start stop) and --card-bg (card surface). */
.auth-body { display: grid; place-items: center; min-height: 100vh; background: var(--bg-start); }
.auth-card { width: 360px; max-width: 92vw; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 32px; box-shadow: var(--shadow-card); }
.auth-title { font-family: var(--font-head); font-size: var(--fs-h2); margin: 0 0 4px; color: var(--text); display: flex; flex-direction: column; align-items: center; line-height: 1; }
.auth-title small { font-family: var(--font-body); font-weight: var(--fw-medium); font-size: var(--fs-eyebrow); letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-muted); margin-top: 6px; }
.auth-tagline { color: var(--text-muted); font-size: var(--fs-small); text-align: center; margin: 0 0 16px; }
.auth-sub { color: var(--text-muted); margin: 0 0 20px; text-align: center; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-small); color: var(--text-muted); }
.auth-form input { padding: 10px 12px; border-radius: var(--radius-ctl); border: 1px solid var(--border-strong); background: var(--bg-start); color: var(--text); font-size: var(--fs-body); }
.auth-form .btn-accent { margin-top: 6px; padding: 11px; border: none; border-radius: var(--radius-ctl); background: var(--accent); color: var(--accent-contrast); font-weight: var(--fw-semibold); cursor: pointer; }
.auth-error { color: var(--danger); font-size: var(--fs-small); min-height: 1.2em; margin: 4px 0 0; }
.auth-switch { margin: 18px 0 0; font-size: var(--fs-small); color: var(--text-muted); text-align: center; }
.auth-switch a { color: var(--accent-strong); }

/* ── Header usage figure (tiny, unobtrusive cost/token readout) ── */
.usage-figure { background: none; padding: 0 2px; font-size: var(--fs-caption); color: var(--text-muted); }

/* Regenerate overlay — covers the document card; the current doc stays underneath. */
.regen-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--card-bg) 92%, transparent);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 24px;
}
.regen-panel[hidden] { display: none; }
.regen-panel-inner {
  width: 100%;
  max-width: 640px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.regen-panel-title { font-family: var(--font-head); font-weight: var(--fw-bold); color: var(--text); }
.regen-panel-label { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-small); color: var(--text-muted); }
.regen-feedback {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: var(--radius-ctl);
  border: 1px solid var(--border-strong);
  background: var(--bg-start);
  color: var(--text);
  font: inherit;
}
.regen-panel-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ── Brand tile + name (Munshi wordmark) ── */
.brand-tile { display:inline-flex; align-items:center; justify-content:center; width:30px; height:30px; border-radius:8px; background:#F4F0E5; padding:3px; box-sizing:border-box; }
.brand-tile .app-icon { width:100%; height:100%; object-fit:contain; }
.brand-name { display:inline-flex; flex-direction:column; line-height:1; font-family:var(--font-head); font-weight:var(--fw-bold); color:var(--header-text); }
.brand-name small { font-family:var(--font-body); font-weight:var(--fw-medium); font-size:var(--fs-eyebrow); letter-spacing:1.5px; text-transform:uppercase; color:var(--text-muted); margin-top:2px; }

/* ── Mobile: bottom-nav app layout (≤820px) ── */
.mobile-nav { display: none; }

@media (max-width: 820px) {
  body { overflow: hidden; }
  .app-grid {
    display: block;
    height: auto;
    padding: 0;
  }
  /* each card becomes a full-screen view under the header, above the nav */
  .app-grid > .card {
    position: fixed;
    left: 0; right: 0;
    top: var(--app-header-h, 56px);
    bottom: calc(60px + env(safe-area-inset-bottom));
    margin: 0;
    border-radius: 0;
    border-left: none; border-right: none;
    display: none;
    min-height: 0;
  }
  body.mv-compose   .card-recorder,
  body.mv-transcript .card-raw,
  body.mv-document  .card-canvas { display: flex; }
  /* default when no class yet */
  body:not([class*="mv-"]) .card-recorder { display: flex; }

  .mobile-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(60px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    z-index: 50;
  }
  .mnav-btn {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: var(--fs-eyebrow); font-family: var(--font-body);
    position: relative;
    transition: color var(--dur) var(--ease-standard), transform var(--dur-fast) var(--ease-out);
  }
  .mnav-btn svg { width: 22px; height: 22px; }
  .mnav-btn.active { color: var(--accent-strong); }
  .mnav-btn:active { transform: scale(0.97); }
  .mnav-dot { position: absolute; top: 8px; right: calc(50% - 20px); width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
  .mnav-dot[hidden] { display: none; }

  /* header condenses */
  .app-header { padding: 0 14px; height: 56px; }
  .brand-name small { display: none; }
  #usage-figure { display: none; }
  #status-text { display: none; }

  /* regen overlay + refine bar full-bleed on phones */
  .regen-panel { padding: 12px; }
  .regen-panel-inner { max-width: 100%; }
  #regen-grid.doc-choice-grid { grid-template-columns: 1fr; }
  .refine-bar { flex-wrap: wrap; }

  /* comfortable touch targets + fluid type */
  .composer-icon-btn, .btn-record, .mnav-btn { min-height: 44px; }
  .doc-title { font-size: clamp(1.3rem, 5vw, 1.7rem); }

  /* Prevent iOS Safari auto-zoom on focus (mobile only — desktop keeps the type scale) */
  input, textarea, select { font-size: 16px; }
}

/* Theme-toggle icon: sun shown in dark mode (tap → light), moon in light mode */
.btn-theme svg { display: block; }
.btn-theme .icon-sun, .btn-theme .icon-moon { display: none; }
[data-theme="dark"] .btn-theme .icon-sun { display: block; }
[data-theme="light"] .btn-theme .icon-moon { display: block; }

/* Signature: the document reads like a manuscript page */
.doc-canvas { background: var(--doc-bg); }
.exec-doc .doc-title, .doc-title {
  border-bottom: 2px solid var(--accent);
  padding-bottom: 10px;
}
.exec-doc { position: relative; }

.doc-placeholder { display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; gap:10px; height:100%; color:var(--text-muted); }
.doc-placeholder-mark { width:72px; height:72px; opacity:0.12; margin-bottom:6px; }
.doc-placeholder-title { font-family:var(--font-head); font-weight:var(--fw-semibold); font-size:var(--fs-lead); color:var(--text); }
.doc-placeholder-sub { font-size:var(--fs-small); max-width:320px; line-height:1.6; }
