/*
  Design direction - "field notes for a clinic front desk."
  Palette: warm paper background, a deep spruce-green ink for structure,
  a single clay-coral used ONLY for things that need a human's attention
  (flags), and a muted gold reserved for pending/in-progress states.
  Type: Fraunces (a warm, slightly editorial serif) carries page titles -
  this is a clinical *operations* tool, not a hospital-brand marketing
  site, so the serif is dialed back to a supporting role, used only at
  large sizes. Inter carries every UI/body/data surface.
  Layout: a fixed left rail + content column, left-aligned throughout.
  Status is communicated with a left border stripe + text label, never
  color alone.
*/

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --paper: #f6f4ef;
  --paper-raised: #ffffff;
  --ink: #1f2a24;
  --ink-soft: #52605a;
  --spruce: #1f4d43;
  --spruce-dim: #2e6358;
  --line: #dfdacf;
  --line-soft: #ebe7dc;
  --clay: #c1531f;
  --clay-bg: #fbe9de;
  --gold: #9a7418;
  --gold-bg: #f7edd2;
  --moss: #3e6b4d;
  --moss-bg: #e4ede4;
  --radius-sm: 4px;
  --radius-md: 8px;
  --shadow-card: 0 1px 2px rgba(31, 42, 36, 0.06), 0 1px 0 rgba(31, 42, 36, 0.04);
  font-size: 16px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
img, svg { max-width: 100%; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
  width: 100%;
}

h1, h2, h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 0.4em;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.9rem; font-weight: 600; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; font-family: 'Inter', sans-serif; font-weight: 600; }

p { margin: 0 0 0.9em; color: var(--ink-soft); max-width: 68ch; }
a { color: var(--spruce-dim); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--spruce-dim);
  outline-offset: 2px;
}

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.rail {
  width: 232px;
  flex-shrink: 0;
  background: var(--spruce);
  color: #eef3ef;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rail-brand {
  font-family: 'Fraunces', serif;
  font-size: 1.15rem;
  color: #fff;
  margin-bottom: 4px;
  padding: 0 8px;
}
.rail-brand small { display: block; font-family: 'Inter', sans-serif; font-size: 0.72rem; color: #b9d0c4; font-weight: 500; }
.rail-clinic { padding: 0 8px 18px; font-size: 0.82rem; color: #b9d0c4; border-bottom: 1px solid rgba(255,255,255,0.14); margin-bottom: 14px; }
.rail nav { display: flex; flex-direction: column; gap: 2px; }
.rail a {
  color: #dbe8e0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
}
.rail a:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.rail a.active { background: rgba(255,255,255,0.14); color: #fff; }
.rail-section-label { font-size: 0.72rem; color: #8fae9f; margin: 16px 10px 4px; font-weight: 600; }
.rail-user { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.14); font-size: 0.82rem; color: #cfe0d7; }
.rail-user form { margin-top: 6px; }
.rail-user button { background: none; border: none; color: #cfe0d7; padding: 0; cursor: pointer; font-size: 0.82rem; text-decoration: underline; }

.content { flex: 1; min-width: 0; padding: 32px 40px 60px; max-width: 1180px; width: 100%; }
.content-narrow { max-width: 760px; }

/* ---------- Mobile topbar + off-canvas nav ---------- */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--spruce);
  color: #fff;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
}
.mobile-topbar-title {
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle span { display: block; height: 2px; width: 18px; margin: 0 auto; background: #fff; border-radius: 2px; }
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 24, 0.4);
  z-index: 35;
}


/* ---------- Header row ---------- */
.page-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-header .subtitle { color: var(--ink-soft); font-size: 0.95rem; margin-top: -6px; }

/* ---------- KPI strip ---------- */
.kpi-strip { display: flex; gap: 0; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper-raised); overflow: hidden; margin-bottom: 28px; }
.kpi { flex: 1; padding: 16px 20px; border-right: 1px solid var(--line-soft); }
.kpi:last-child { border-right: none; }
.kpi-value { font-family: 'Fraunces', serif; font-size: 1.7rem; color: var(--spruce); font-weight: 600; line-height: 1; }
.kpi-label { font-size: 0.82rem; color: var(--ink-soft); margin-top: 6px; }

/* ---------- Cards & sections ---------- */
.panel { background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: 20px 22px; margin-bottom: 24px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-header h2 { margin: 0; font-size: 1.1rem; font-family: 'Inter', sans-serif; font-weight: 600; }

/* ---------- Lists / tables ---------- */
.record-list { display: flex; flex-direction: column; gap: 0; }
.record-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border-left: 3px solid var(--line);
  border-bottom: 1px solid var(--line-soft);
  text-decoration: none;
  color: var(--ink);
}
.record-row:last-child { border-bottom: none; }
.record-row:hover { background: var(--paper); text-decoration: none; }
.record-row.flag-attention { border-left-color: var(--clay); }
.record-row.flag-pending { border-left-color: var(--gold); }
.record-row.flag-ok { border-left-color: var(--moss); }
.record-main { flex: 1; min-width: 0; }
.record-title { font-weight: 600; font-size: 0.95rem; }
.record-meta { font-size: 0.82rem; color: var(--ink-soft); margin-top: 2px; }
.record-side { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.empty-state { padding: 28px 12px; text-align: center; color: var(--ink-soft); }
.empty-state h3 { color: var(--ink-soft); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 0.76rem; font-weight: 600; white-space: nowrap; }
.badge-attention { background: var(--clay-bg); color: var(--clay); }
.badge-pending { background: var(--gold-bg); color: var(--gold); }
.badge-ok { background: var(--moss-bg); color: var(--moss); }
.badge-neutral { background: var(--line-soft); color: var(--ink-soft); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 0.9rem; font-weight: 600; cursor: pointer; font-family: 'Inter', sans-serif;
  text-decoration: none;
}
.btn-primary { background: var(--spruce); color: #fff; }
.btn-primary:hover { background: var(--spruce-dim); text-decoration: none; }
.btn-secondary { background: var(--paper-raised); border-color: var(--line); color: var(--ink); }
.btn-secondary:hover { border-color: var(--spruce-dim); text-decoration: none; }
.btn-danger { background: var(--clay-bg); color: var(--clay); }
.btn-small { padding: 5px 11px; font-size: 0.8rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */
form .field { margin-bottom: 16px; }
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 5px; color: var(--ink); }
.help-text { font-size: 0.78rem; color: var(--ink-soft); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=tel],
select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif; font-size: 0.92rem; background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--spruce-dim); }
.radio-group label { font-weight: 500; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--clay); font-size: 0.82rem; }

/* ---------- Messages ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 20px; }
.messages li { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 8px; font-size: 0.9rem; }
.messages .success { background: var(--moss-bg); color: var(--moss); }
.messages .error { background: var(--clay-bg); color: var(--clay); }
.messages .warning { background: var(--gold-bg); color: var(--gold); }

/* ---------- Call transcript ---------- */
.transcript { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.transcript-line { max-width: 80%; padding: 10px 14px; border-radius: var(--radius-md); font-size: 0.9rem; }
.transcript-line.ai { background: var(--paper); border: 1px solid var(--line); align-self: flex-start; }
.transcript-line.patient { background: var(--spruce); color: #fff; align-self: flex-end; }
.transcript-speaker { font-size: 0.72rem; text-transform: none; font-weight: 600; opacity: 0.7; margin-bottom: 2px; }

/* ---------- Scribe review split pane ---------- */
.split-pane { display: flex; gap: 22px; align-items: flex-start; }
.split-left { flex: 0 0 360px; position: sticky; top: 24px; }
.split-right { flex: 1; min-width: 0; }
.segment { padding: 8px 10px; border-radius: var(--radius-sm); font-size: 0.86rem; margin-bottom: 4px; border-left: 3px solid transparent; }
.segment.speaker-physician { background: var(--paper); }
.segment.speaker-patient { background: #fff; border: 1px solid var(--line-soft); }
.segment.linked { border-left-color: var(--gold); background: var(--gold-bg); }
.segment-speaker { font-size: 0.72rem; font-weight: 700; color: var(--ink-soft); margin-bottom: 2px; }
.segment-id { font-size: 0.7rem; color: var(--ink-soft); font-family: monospace; }

.note-section { border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; margin-bottom: 14px; }
.note-section-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.note-section-header h3 { margin: 0; font-size: 0.95rem; }
.note-section-body { padding: 12px 14px; }
.note-section textarea { min-height: 70px; border: none; padding: 0; }
.ai-tag { font-size: 0.68rem; font-weight: 700; color: var(--gold); background: var(--gold-bg); padding: 2px 7px; border-radius: 12px; }
.source-refs { margin-top: 6px; font-size: 0.75rem; color: var(--ink-soft); }
.source-refs a { font-family: monospace; }

.problem-card { border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; padding: 14px; margin-bottom: 14px; }
.problem-card h4 { margin: 0 0 8px; font-size: 1rem; }
.coding-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px 3px 3px; font-size: 0.78rem; margin: 3px 4px 0 0; background: var(--paper); }
.coding-chip .code { font-family: monospace; font-weight: 700; background: var(--spruce); color: #fff; border-radius: 20px; padding: 2px 7px; }
.coding-chip.confirmed { border-color: var(--moss); }
.coding-chip.rejected { opacity: 0.5; text-decoration: line-through; }

/* ---------- Save confirmation indicator ---------- */
.save-status {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  vertical-align: middle;
}
.save-status.saving { color: var(--ink-soft); }
.save-status.success { color: var(--moss); }
.save-status.error { color: var(--clay); }

/* ---------- Mic / recording ---------- */
.mic-panel { text-align: center; padding: 40px 20px; }
.mic-button {
  width: 92px; height: 92px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--spruce); color: #fff; font-size: 1.6rem; box-shadow: var(--shadow-card);
}
.mic-button.recording { background: var(--clay); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(193,83,31,0.35);} 70% { box-shadow: 0 0 0 16px rgba(193,83,31,0);} 100% { box-shadow: 0 0 0 0 rgba(193,83,31,0);} }
.mic-status { margin-top: 14px; font-weight: 600; color: var(--ink-soft); }
.mic-timer { font-family: monospace; font-size: 1.3rem; margin-top: 4px; }
@media (prefers-reduced-motion: reduce) { .mic-button.recording { animation: none; } }

/* ---------- Roadmap ---------- */
.roadmap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.roadmap-card { border: 1px dashed var(--line); border-radius: var(--radius-md); padding: 14px; background: var(--paper); }
.roadmap-card h4 { margin: 0 0 6px; font-size: 0.92rem; }
.roadmap-card p { font-size: 0.82rem; margin: 0; }
.roadmap-tag { font-size: 0.68rem; font-weight: 700; color: var(--ink-soft); }

/* ---------- Misc ---------- */
.muted { color: var(--ink-soft); }
.step-nav { display: flex; gap: 10px; margin-top: 22px; }
.divider { border: none; border-top: 1px solid var(--line-soft); margin: 20px 0; }
.definition-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 0.9rem; }
.definition-list dt { color: var(--ink-soft); }
.definition-list dd { margin: 0; }

@media (max-width: 1024px) {
  .content { padding: 28px 24px 50px; }
  .split-left { flex: 0 0 300px; }
  .rail { width: 200px; }
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }

  .mobile-topbar { display: flex; }

  /* Off-canvas drawer: fixed, slid off-screen until body.nav-open */
  .rail {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 84vw);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    padding-top: max(22px, env(safe-area-inset-top));
    box-shadow: 2px 0 18px rgba(0,0,0,0.18);
  }
  body.nav-open .rail { transform: translateX(0); }
  body.nav-open .nav-backdrop { display: block; }
  body.nav-open { overflow: hidden; }

  .content { padding: 20px 16px 48px; max-width: 100%; }
  .content-narrow { max-width: 100%; }

  .page-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-header h1 { font-size: 1.5rem; }
  .step-nav { flex-direction: column; }
  .step-nav .btn, .step-nav form { width: 100%; }
  .step-nav form .btn { width: 100%; }

  /* KPI strip becomes a 2-column grid instead of squeezing 5 across */
  .kpi-strip { display: grid; grid-template-columns: 1fr 1fr; border-radius: var(--radius-md); }
  .kpi { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
  .kpi:nth-child(2n) { border-right: none; }

  .panel { padding: 16px; }

  /* Record rows: stack the side badges under the main content instead of
     squeezing everything onto one line */
  .record-row { flex-wrap: wrap; align-items: flex-start; gap: 8px; }
  .record-side { width: 100%; justify-content: flex-start; flex-wrap: wrap; }

  .definition-list { grid-template-columns: 1fr; gap: 2px 0; }
  .definition-list dt { margin-top: 10px; font-size: 0.78rem; text-transform: none; }
  .definition-list dt:first-child { margin-top: 0; }

  .transcript-line { max-width: 92%; }

  .split-pane { flex-direction: column; gap: 16px; }
  .split-left { position: static; flex-basis: auto; width: 100%; flex: none; }
  .split-left #transcript-scroll { max-height: 46vh; }

  .roadmap-grid { grid-template-columns: 1fr; }

  .mic-button { width: 76px; height: 76px; font-size: 1.3rem; }

  form .field { margin-bottom: 14px; }
  .btn { width: 100%; justify-content: center; }
  .panel-header .btn, .record-row .btn, .coding-chip .btn, .note-section-header .btn { width: auto; }
  .panel-header { flex-wrap: wrap; gap: 8px; }
  .note-section-header { flex-wrap: wrap; gap: 6px; }
  .note-section-header > div { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
}

@media (max-width: 480px) {
  :root { font-size: 15px; }
  h1 { font-size: 1.35rem; }
  .kpi-strip { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 1.4rem; }
  .mic-panel { padding: 24px 10px; }
}

/* ---------- Guest (login) shell ---------- */
.guest-shell {
  max-width: 440px;
  width: 100%;
  margin: 10vh auto 40px;
  padding: 0 20px;
}
@media (max-width: 480px) {
  .guest-shell { margin-top: 6vh; padding: 0 16px; }
}

