/* ============================================================
   AfterVisit :: Styles
   Mobile-first (~393px). Calm clinical / warm editorial.
   ============================================================ */

:root {
  /* paper */
  --bg:           #faf8f3;
  --bg-elev:      #ffffff;
  --bg-warm:      #f3eee2;

  /* ink */
  --ink:          #1a1a1a;
  --ink-soft:     #3a3a3a;
  --muted:        #7a7166;
  --muted-soft:   #a89e8f;

  /* accents */
  --accent:       #c14d2e;     /* terracotta */
  --accent-soft:  #e9b5a3;
  --accent-bg:    #f4ddd2;
  --alarm:        #a02828;
  --alarm-bg:     #f4d8d8;
  --gentle:       #5e7a4c;     /* moss green for "good" / completed */
  --gentle-bg:    #e2ead8;

  /* lines */
  --border:       #e8e2d4;
  --border-strong:#d6cdb8;

  --radius:       14px;
  --radius-sm:    8px;

  --serif:        'Fraunces', Georgia, 'Times New Roman', serif;
  --sans:         'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;

  --shadow-sm:    0 1px 2px rgba(26,26,26,0.04), 0 0 0 1px rgba(26,26,26,0.04);
  --shadow-md:    0 4px 16px rgba(26,26,26,0.06), 0 0 0 1px rgba(26,26,26,0.04);
}

/* ============ RESET ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
html {
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
}
body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(193,77,46,0.06), transparent),
    radial-gradient(ellipse 60% 40% at 100% 90%, rgba(94,122,76,0.04), transparent);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ============ APP SHELL ============ */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}

.view {
  display: none;
  padding: 18px 20px 40px;
  animation: viewIn 0.3s ease both;
}
.view.active { display: block; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ HEADER ============ */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--serif);
  font-weight: 500;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.02em;
}
.brand-name {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}

.icon-btn {
  background: transparent;
  border: none;
  padding: 8px;
  border-radius: 50%;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover, .icon-btn:focus-visible {
  color: var(--ink);
  background: var(--bg-warm);
  outline: none;
}

/* ============ HERO ============ */
.hero {
  padding: 12px 0 26px;
}
.hero-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 10px;
}
.hero-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 38px;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
  color: var(--ink);
}
.hero-title em {
  font-style: italic;
  color: var(--accent);
  font-weight: 400;
}
.hero-sub {
  font-size: 15px;
  color: var(--muted);
  margin: 0;
  max-width: 32ch;
  line-height: 1.5;
}

/* ============ PATIENT BAR ============ */
.patient-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.patient-label {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
}
.patient-select {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 6px 0;
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  outline: none;
  appearance: none;
  cursor: pointer;
}
.patient-edit {
  background: transparent;
  border: 0;
  font-size: 13px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border-strong);
  padding: 4px 6px;
}
.patient-edit:hover { color: var(--accent); }

/* ============ RECORD BUTTON ============ */
.record-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 30px;
}
.record-btn {
  background: transparent;
  border: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  cursor: pointer;
}
.record-btn-inner {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: linear-gradient(180deg, #d05738 0%, #b14328 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 0 6px var(--bg-elev),
    0 0 0 7px var(--accent-soft),
    0 12px 32px rgba(193,77,46,0.28);
  transition: transform 0.15s, box-shadow 0.2s;
}
.record-btn:hover .record-btn-inner,
.record-btn:focus-visible .record-btn-inner {
  transform: scale(1.03);
  box-shadow:
    0 0 0 6px var(--bg-elev),
    0 0 0 8px var(--accent),
    0 16px 40px rgba(193,77,46,0.36);
}
.record-btn:active .record-btn-inner {
  transform: scale(0.97);
}
.record-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg);
}
.record-btn-label {
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-top: 4px;
}
.record-hint {
  margin: 14px auto 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  max-width: 32ch;
  line-height: 1.5;
}

/* ============ PAST VISITS ============ */
.visits-section {
  border-top: 1px solid var(--border);
  padding-top: 22px;
  margin-top: 6px;
}
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 14px;
}
.section-count {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted-soft);
}

.visit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.visit-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: block;
  text-align: left;
  width: 100%;
  font-family: inherit;
}
.visit-card:hover {
  border-color: var(--accent-soft);
  transform: translateY(-1px);
}
.visit-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}
.visit-card-date {
  font-family: var(--serif);
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
}
.visit-card-status {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 100px;
}
.visit-card-status.done    { background: var(--gentle-bg); color: var(--gentle); }
.visit-card-status.pending { background: var(--bg-warm); color: var(--muted); }
.visit-card-status.error   { background: var(--alarm-bg); color: var(--alarm); }
.visit-card-headline {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.3;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.visit-card-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 4px;
}

.empty-state {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  padding: 30px 20px;
  margin: 0;
}

/* ============ SUB HEADER (for inner views) ============ */
.sub-header {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  padding: 4px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}
.sub-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 18px;
  letter-spacing: -0.01em;
  margin: 0;
  text-align: center;
  color: var(--ink);
}

/* ============ RECORDING VIEW ============ */
.recording-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 20px;
  text-align: center;
  min-height: calc(100vh - 100px);
  min-height: calc(100dvh - 100px);
  justify-content: center;
}
.recording-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.recording-eyebrow::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.1); }
}
.recording-time {
  font-family: var(--serif);
  font-size: 78px;
  font-weight: 300;
  letter-spacing: -0.04em;
  color: var(--ink);
  margin: 0;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.recording-meter {
  display: flex;
  gap: 6px;
  margin: 24px 0;
  height: 48px;
  align-items: end;
}
.recording-meter span {
  width: 6px;
  background: var(--accent);
  border-radius: 3px;
  transition: height 0.1s ease-out;
  height: 8px;
}
.recording-note {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
  max-width: 30ch;
  margin: 0 0 36px;
  line-height: 1.5;
}
.recording-controls {
  display: flex;
  gap: 16px;
  align-items: center;
}
.btn-text {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 12px 20px;
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: var(--border-strong);
}
.btn-text:hover { color: var(--ink); }
.btn-text.danger { color: var(--alarm); }
.btn-stop {
  background: var(--ink);
  color: var(--bg);
  border: 0;
  border-radius: 100px;
  padding: 14px 28px;
  font-size: 15px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
}
.btn-stop:hover { background: var(--accent); }
.btn-stop-square {
  width: 11px;
  height: 11px;
  background: var(--bg);
  border-radius: 2px;
}

/* ============ FORMS ============ */
.context-form, .patient-form { padding: 0 4px; }
.form-eyebrow {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  margin: 0 0 18px;
  font-size: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field-row .field { margin-bottom: 18px; }
.field-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.field-optional {
  text-transform: none;
  font-weight: 400;
  font-style: italic;
  color: var(--muted-soft);
  letter-spacing: 0;
}
.field input,
.field select,
.field textarea {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 15px;
  color: var(--ink);
  font-family: var(--sans);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.field textarea {
  resize: vertical;
  min-height: 70px;
  line-height: 1.5;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.field-hint {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* ============ TOGGLE ============ */
.audio-toggle {
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 6px 0 24px;
}
.toggle {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-slider {
  flex-shrink: 0;
  width: 44px;
  height: 26px;
  background: var(--border-strong);
  border-radius: 100px;
  position: relative;
  transition: background 0.2s;
  margin-top: 2px;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px;
  height: 20px;
  background: var(--bg);
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::after { transform: translateX(18px); }
.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 14px;
  line-height: 1.4;
}
.toggle-text strong { font-weight: 600; color: var(--ink); }
.toggle-text small { font-size: 12.5px; color: var(--muted); }

/* ============ PRIMARY BUTTON ============ */
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: 100px;
  padding: 15px 24px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 4px 12px rgba(193,77,46,0.18);
}
.btn-primary:hover { background: #b14328; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============ PROCESSING ============ */
.processing-stage {
  text-align: center;
  padding: 80px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.processing-spinner {
  color: var(--accent);
  width: 60px;
  height: 60px;
  margin-bottom: 22px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}
.processing-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 28px;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}
.processing-sub {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 30px;
  max-width: 32ch;
}
.processing-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 22px;
}
.proc-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}
.proc-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
}
.proc-step.active     .proc-step-dot { background: var(--accent); animation: pulse 1.4s infinite; }
.proc-step.done       .proc-step-dot { background: var(--gentle); }
.proc-step.active     { color: var(--ink); font-weight: 500; }
.proc-step.done       { color: var(--gentle); }

/* ============ DETAIL VIEW ============ */
.detail-body { padding: 0; }
.detail-headline {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 8px;
}
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 26px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.detail-meta span { display: inline-flex; align-items: center; gap: 4px; }

.detail-section { margin-bottom: 26px; }
.detail-section-title {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.detail-section-title.alarm { color: var(--alarm); }
.detail-section-title-count {
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 100px;
  letter-spacing: 0;
}
.detail-section-title.alarm .detail-section-title-count {
  background: var(--alarm-bg);
  color: var(--alarm);
}

.detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.detail-list li {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 14.5px;
  line-height: 1.5;
}
.detail-list.flags li {
  background: var(--alarm-bg);
  border-color: rgba(160,40,40,0.2);
  color: var(--alarm);
}
.detail-list.questions li {
  background: var(--bg-warm);
  border-color: var(--border-strong);
}

.med-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 8px;
}
.med-name {
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.med-name .change-tag {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-left: 6px;
  padding: 2px 7px;
  background: var(--accent-bg);
  border-radius: 100px;
  vertical-align: 1px;
}
.med-name .change-tag.stopped { color: var(--alarm); background: var(--alarm-bg); }
.med-name .change-tag.continued { color: var(--muted); background: var(--bg-warm); }
.med-dose {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--sans);
  font-feature-settings: 'tnum';
  margin-bottom: 6px;
}
.med-purpose {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.detail-instruction {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.detail-instruction-deadline {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.transcript-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  width: 100%;
  text-align: left;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}
.transcript-toggle:hover { border-color: var(--accent-soft); color: var(--ink); }
.transcript-body {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: var(--serif);
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--ink-soft);
  margin-top: 8px;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
}

/* ============ PATIENT TABS ============ */
.patient-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: transparent;
  border: 0;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.patient-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
}
.patient-actions .btn-primary { flex: 1; }

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(26,26,26,0.2);
  max-width: calc(100% - 40px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { background: var(--alarm); }
.toast.success { background: var(--gentle); }

/* ============ TABLET / DESKTOP ============ */
@media (min-width: 720px) {
  #app { max-width: 540px; }
  .hero-title { font-size: 46px; }
  .recording-time { font-size: 96px; }
}
@media (min-width: 1024px) {
  #app { max-width: 600px; }
  .view { padding: 28px 30px 50px; }
}
