/* RadSpeed Web — dark clinical theme */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #050a12;
  --surface:  #0c1623;
  --card:     #101e30;
  --border:   #1c2a3e;
  --accent:   #00c2ff;
  --accent2:  #0080e8;
  --mint:     #00e5a0;
  --text:     #e8edf5;
  --muted:    #8a9ab5;
  --red:      #ef5b5b;
  --green:    #00e5a0;
  --radius:   8px;
  --shadow:   0 2px 12px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
body { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
header h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
  background: linear-gradient(90deg, var(--accent), var(--mint));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
header .subtitle { font-size: 12px; color: var(--muted); }

main { flex: 1; padding: 16px 20px; max-width: 900px; margin: 0 auto; width: 100%; }

footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 20px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── Inputs ── */
select, input[type=text], textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
select:focus, input[type=text]:focus, textarea:focus {
  border-color: var(--accent);
}
select { cursor: pointer; }
textarea { resize: vertical; font-family: "Menlo", "Consolas", monospace; font-size: 12px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary   { background: linear-gradient(135deg, var(--accent2), var(--accent)); color: #fff; }
.btn-primary:hover { box-shadow: 0 4px 16px rgba(0,194,255,0.25); }
.btn-danger    { background: var(--red);     color: #fff; }
.btn-success   { background: var(--green);   color: #022017; font-weight: 600; }
.btn-success:hover { box-shadow: 0 4px 16px rgba(0,229,160,0.25); }
.btn-ghost     { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-secondary { background: var(--surface); border: 1px solid var(--accent); color: var(--accent); }
.btn-secondary:hover { background: rgba(0,194,255,0.08); }
.btn-sm        { padding: 5px 10px; font-size: 12px; }

/* ── Vocabulary-correction suggestion banner ── */
.vocab-suggest {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 8px 12px;
  background: rgba(0, 194, 255, 0.08);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
}
.vocab-suggest-text { flex: 1; }
.vocab-suggest-text b { color: var(--accent); }

.worklist-chip { padding: 3px 9px; font-size: 11px; }
.worklist-chip.active { background: var(--accent); color: #050a12; border-color: var(--accent); }

/* ── Recording section ── */
.record-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#timer {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  min-width: 52px;
}

#waveform {
  flex: 1;
  height: 48px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
  min-width: 120px;
}

/* ── Status bar ── */
#status {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  min-height: 36px;
  display: flex;
  align-items: center;
  transition: border-color 0.2s;
}
#status.error   { border-color: var(--red);   color: var(--red); }
#status.success { border-color: var(--green);  color: var(--green); }
#status.active  { border-color: var(--accent); }

/* ── Grid for patient context fields ── */
.fhir-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}
@media (max-width: 600px) { .fhir-grid { grid-template-columns: 1fr; } }

.fhir-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
  display: block;
}

/* ── Collapsible ── */
details > summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
  padding: 4px 0;
  list-style: none;
}
details > summary::before { content: "▶ "; font-size: 10px; }
details[open] > summary::before { content: "▼ "; }
details > summary::-webkit-details-marker { display: none; }

/* ── Report card header ── */
.report-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

/* ── Rendered markdown report ── */
.report-rendered {
  min-height: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  color: var(--text);
  line-height: 1.7;
  font-size: 13px;
}
.report-rendered:empty::before {
  content: "Formatted report will appear here…";
  color: var(--muted);
}
.report-rendered h1,
.report-rendered h2,
.report-rendered h3 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  margin: 14px 0 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 3px;
}
.report-rendered h1:first-child,
.report-rendered h2:first-child,
.report-rendered h3:first-child { margin-top: 0; }
.report-rendered strong { color: var(--text); font-weight: 600; }
.report-rendered p { margin: 4px 0; }
.report-rendered ul, .report-rendered ol {
  margin: 4px 0 4px 18px;
  padding: 0;
}
.report-rendered li { margin: 2px 0; }
.report-rendered li + li { margin-top: 1px; }

/* ── Raw edit textarea ── */
#report-raw {
  width: 100%;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  color: var(--text);
  line-height: 1.6;
  box-sizing: border-box;
}

/* ── Row utils ── */
.row { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.ml-auto { margin-left: auto; }
.mt-8 { margin-top: 8px; }
.w-full { width: 100%; }

/* ── Recording indicator ── */
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.3; } }
.rec-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: pulse 1s infinite; }
.voice-edit-hint { font-size: 11px; color: var(--muted); margin: 4px 0 0; }

/* ── Feedback recording bar ── */
.feedback-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 10px;
  background: rgba(224, 82, 82, 0.08);
  border: 1px solid rgba(224, 82, 82, 0.25);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--muted);
}

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }

/* ── Streaming live dot (green, shown when streaming STT active) ── */
.streaming-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--green); animation: pulse 1s infinite; margin-right: 2px; }

/* ── API key status badges ── */
.key-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 8px; border-radius: 12px; font-weight: 600; }
.key-badge.configured { background: rgba(82,192,101,0.15); color: var(--green); }
.key-badge.missing { background: rgba(224,82,82,0.12); color: var(--red); }

/* ── Provider radio options ── */
.provider-option { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; cursor: pointer; transition: border-color 0.15s; }
.provider-option:hover { border-color: var(--accent2); }
.provider-option.selected { border-color: var(--accent); background: rgba(0,194,255,0.05); }
.provider-option input[type=radio] { accent-color: var(--accent); }
.provider-label { flex: 1; }
.provider-name { font-size: 13px; font-weight: 600; }
.provider-desc { font-size: 11px; color: var(--muted); }

/* ── Settings page sections ── */
.settings-section { margin-bottom: 22px; }
.settings-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.settings-field { margin-bottom: 10px; }
.settings-field label { font-size: 11px; color: var(--muted); display: block; margin-bottom: 3px; }
.settings-info { font-size: 11px; color: var(--muted); margin-top: 6px; }
.settings-warning { font-size: 11px; color: var(--red); margin-top: 4px; display: none; }

/* ── Settings save bar ── */
.save-bar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 10px 0; margin-top: 16px; display: flex; gap: 8px; align-items: center; }

/* ── Keys status grid ── */
.keys-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 500px) { .keys-grid { grid-template-columns: 1fr; } }

/* ── Reporting style grid ── */
.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
@media (max-width: 600px) { .style-grid { grid-template-columns: 1fr; } }
.style-grid .settings-field { margin-bottom: 0; }
.key-row { display: flex; align-items: center; justify-content: space-between; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; font-size: 12px; }

/* ── Template editor modal ── */
.tmpl-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.tmpl-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0,0,0,0.7);
  display: flex;
  width: 100%;
  max-width: 940px;
  height: min(82vh, 720px);
  overflow: hidden;
}

/* Left sidebar — template list */
.tmpl-sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.tmpl-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 6px;
}
.tmpl-sidebar-header .btn { white-space: nowrap; padding: 4px 8px; font-size: 11px; }
.tmpl-search {
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 12px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  width: 100%;
  outline: none;
  flex-shrink: 0;
}
.tmpl-search:focus { border-bottom-color: var(--accent); }
.tmpl-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 4px 0;
  margin: 0;
}
.tmpl-list li {
  padding: 7px 10px 7px 12px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  border-left: 2px solid transparent;
  color: var(--text);
  user-select: none;
}
.tmpl-list li:hover { background: rgba(0,194,255,0.05); }
.tmpl-list li.tmpl-active { border-left-color: var(--accent); background: rgba(0,194,255,0.07); }
.tmpl-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  background: rgba(0,194,255,0.14);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Right editor pane */
.tmpl-editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.tmpl-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
/* Two-section editor tabs (Report structure / AI instructions) */
.tmpl-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tmpl-tab {
  appearance: none;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
}
.tmpl-tab:hover { color: var(--text); }
.tmpl-tab-active {
  color: var(--text);
  background: var(--bg);
  border-color: var(--border);
  margin-bottom: -1px;
}
.tmpl-split-note {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  padding-right: 4px;
}
.tmpl-import-hint {
  font-size: 11px;
  color: var(--muted);
  padding: 6px 2px 2px;
  line-height: 1.4;
}
.tmpl-textarea {
  flex: 1;
  resize: none;
  border: none;
  border-radius: 0;
  background: var(--bg);
  font-family: "Menlo", "Consolas", "SF Mono", monospace;
  font-size: 12px;
  line-height: 1.65;
  padding: 14px 16px;
  color: var(--text);
  width: 100%;
  min-height: 0;
  outline: none;
}
.tmpl-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
  gap: 8px;
}

/* Unsaved-change indicator on the title */
.tmpl-dirty::after {
  content: " ●";
  color: var(--accent);
  font-size: 10px;
}

@media (max-width: 600px) {
  .tmpl-sidebar { width: 160px; }
  .tmpl-modal { height: 90vh; }
}

/* ── Template upload options dialog ── */
.tmpl-upload-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.tmpl-upload-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0,0,0,0.7);
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  max-height: 88vh;
}
.tmpl-upload-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tmpl-upload-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.tmpl-upload-option { margin: 0; }
.tmpl-upload-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

/* ── Phase 1: status badge, sign-off, amendments ── */
.status-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  text-transform: uppercase;
}
.status-draft       { background: var(--surface); color: var(--muted); border-color: var(--border); }
.status-preliminary { background: rgba(0,194,255,0.10); color: var(--accent); border-color: rgba(0,194,255,0.35); }
.status-final       { background: rgba(0,229,160,0.12); color: var(--green); border-color: rgba(0,229,160,0.35); }
.status-amended     { background: rgba(255,170,0,0.12); color: #ffaa00; border-color: rgba(255,170,0,0.35); }

/* ── Phase 2: QA panel ── */
.qa-panel {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.qa-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.qa-flag {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  margin: 6px 0 0;
  border-radius: 6px;
  border-left: 3px solid var(--border);
  background: var(--bg);
  font-size: 13px;
  align-items: flex-start;
}
.qa-flag-error    { border-left-color: var(--red); }
.qa-flag-warning  { border-left-color: #ffaa00; }
.qa-flag-info     { border-left-color: var(--accent); }
.qa-flag-icon { flex-shrink: 0; font-weight: 700; min-width: 18px; }
.qa-flag-icon.error   { color: var(--red); }
.qa-flag-icon.warning { color: #ffaa00; }
.qa-flag-icon.info    { color: var(--accent); }
.qa-flag-body { flex: 1; }
.qa-flag-message { color: var(--text); }
.qa-flag-location {
  display: block;
  margin-top: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
}
.qa-flag-dismiss {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}
.qa-flag-dismiss:hover { color: var(--text); }
.qa-empty {
  font-size: 13px;
  color: var(--green);
  padding: 4px 0;
}

/* ── Audit & amendment modal layout ── */
.audit-event {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.audit-event:last-child { border-bottom: none; }
.audit-event-header {
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.audit-event-type {
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}
.audit-event-time { color: var(--muted); font-size: 11px; }
.audit-event-meta {
  margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
}
.audit-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 14px 0 6px;
  font-weight: 700;
}
.audit-section-title:first-child { margin-top: 0; }
.report-version {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  font-size: 12px;
}
.report-version-header {
  display: flex;
  gap: 8px;
  align-items: center;
}
.report-version-reason {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}
