/* ── Design tokens ──────────────────────────────────────────── */
:root {
  --st-bg:       #f0f2f6;
  --st-panel-bg: #ffffff;
  --st-text:     #0e1116;
  --st-muted:    #6c757d;
  --st-border:   rgba(49, 51, 63, 0.08);
  --st-primary:  #1a73e8;   /* 醫療藍 */
  --st-success:  #198754;
  --st-warning:  #f0a500;
  --st-danger:   #dc3545;
}

/* ── Base ───────────────────────────────────────────────────── */
.st-body {
  background: var(--st-bg);
  color: var(--st-text);
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

/* ── Header / Nav ───────────────────────────────────────────── */
.st-header {
  background: var(--st-panel-bg);
  border-bottom: 1px solid var(--st-border);
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.sc-logo-icon { font-size: 1.4rem; }
.st-brand { font-size: 1.25rem; color: var(--st-primary); }
.st-nav-link {
  color: var(--st-muted);
  text-decoration: none;
  margin-left: 1.5rem;
  font-weight: 600;
  position: relative;
  padding-bottom: 0.25rem;
  font-size: 0.95rem;
}
.st-nav-link::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: transparent;
  border-radius: 999px;
}
.st-nav-link:hover { color: var(--st-text); }
.st-nav-link.active { color: var(--st-primary); }
.st-nav-link.active::after { background: var(--st-primary); }

.st-main { padding: 2rem 0 3.5rem; }

/* ── Panel ──────────────────────────────────────────────────── */
.st-panel {
  background: var(--st-panel-bg);
  border-radius: 1.1rem;
  box-shadow: 0 4px 18px rgba(49, 51, 63, 0.07);
  padding: 1.75rem;
}
.st-panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--st-text);
}

/* ── Flash ──────────────────────────────────────────────────── */
.st-flash {
  background: #fff3cd;
  border: 1px solid rgba(255, 193, 7, 0.35);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  color: #8a6d3b;
  margin-bottom: 1.5rem;
}

/* ── Schedule page ──────────────────────────────────────────── */
.sc-patient-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--st-border);
  background: #fafbfd;
  transition: box-shadow 0.15s, background 0.15s;
  text-decoration: none;
  color: var(--st-text);
}
.sc-patient-row:hover {
  background: #fff;
  box-shadow: 0 3px 12px rgba(26, 115, 232, 0.12);
  color: var(--st-primary);
}
.sc-patient-num {
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: var(--st-primary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sc-badge-card-ready {
  font-size: 0.75rem;
  background: rgba(25, 135, 84, 0.1);
  color: var(--st-success);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-weight: 600;
}
.sc-badge-card-pending {
  font-size: 0.75rem;
  background: rgba(240, 165, 0, 0.1);
  color: var(--st-warning);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-weight: 600;
}

/* ── Knowledge card ─────────────────────────────────────────── */
.sc-kcard-section {
  border-left: 3px solid var(--st-primary);
  padding: 0.75rem 1rem;
  background: #f5f8ff;
  border-radius: 0 0.6rem 0.6rem 0;
  margin-bottom: 1rem;
}
.sc-kcard-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--st-primary);
  margin-bottom: 0.4rem;
}
.sc-kcard-section p { margin: 0; font-size: 0.92rem; }
.sc-suggest-tag {
  display: inline-block;
  background: rgba(26, 115, 232, 0.08);
  color: var(--st-primary);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  margin: 0.2rem 0.2rem 0 0;
}

/* ── Encounter page（問診工作畫面 — 密集式病歷格） ──────────────── */
.sc-emr {
  --emr-cream:      #fdf6d8;
  --emr-cream-dark: #efe6bd;
  --emr-vlabel-bg:  #e8dfae;
  --emr-border:     #c9c1a0;
  --emr-dark:       #262b3d;
  --emr-accent:     #0f7a6c;
  --emr-accent-dark:#0b5c52;
  --emr-text:       #3a3010;
  --emr-muted:      #8a7c40;
  font-size: 0.9rem;
}

.sc-emr-topbar {
  display: flex;
  align-items: center;
  background: var(--emr-dark);
  color: #fff;
  padding: 0.45rem 0.85rem;
  border-radius: 0.6rem 0.6rem 0 0;
  gap: 0.25rem;
  flex-wrap: wrap;
}
.sc-emr-tabs { display: flex; gap: 0.2rem; flex-wrap: wrap; }
.sc-emr-tab {
  color: #cfd3e6;
  padding: 0.28rem 0.65rem;
  border-radius: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}
a.sc-emr-tab:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sc-emr-topactions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sc-emr-save-indicator {
  color: #9fd8c9;
  font-size: 0.72rem;
  min-width: 64px;
  text-align: right;
}

.sc-emr-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #fff;
  color: #333;
  border: 1px solid #b9b9b9;
  border-radius: 0.3rem;
  padding: 0.24rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
}
.sc-emr-btn:hover { background: #f0f0f0; color: #111; }
.sc-emr-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sc-emr-btn-accent { background: var(--emr-accent); border-color: var(--emr-accent); color: #fff; }
.sc-emr-btn-accent:hover { background: var(--emr-accent-dark); color: #fff; }
.sc-emr-btn-danger { background: #fff; border-color: var(--st-danger); color: var(--st-danger); }
.sc-emr-btn-danger:hover { background: #fdecea; }
.sc-emr-btn-primary-lg {
  background: var(--emr-accent);
  border-color: var(--emr-accent);
  color: #fff;
  font-size: 0.85rem;
  padding: 0.45rem 1.5rem;
  border-radius: 0.4rem;
}
.sc-emr-btn-primary-lg:hover { background: var(--emr-accent-dark); }
.sc-emr-btn-primary-lg:disabled { background: #ccc; border-color: #ccc; }
.sc-emr-btn-disabled { background: #e9e9e9; color: #888; border-color: #ccc; }

.sc-emr-idbar {
  background: var(--emr-cream);
  border-left: 1px solid var(--emr-border);
  border-right: 1px solid var(--emr-border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
  color: var(--emr-text);
  flex-wrap: wrap;
}
.sc-emr-id { font-weight: 800; }
.sc-emr-sep { color: #b8ac7a; }
.sc-emr-status {
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  background: #c98a12;
}
.sc-emr-status.active { background: #2e8b57; }
.sc-emr-status.confirmed { background: #3a6ea5; }
.sc-emr-status.pending { background: #c98a12; }
.sc-emr-select {
  margin-left: auto;
  font-size: 0.78rem;
  padding: 0.18rem 0.4rem;
  border-radius: 0.3rem;
  border: 1px solid var(--emr-border);
  background: #fff;
  max-width: 230px;
}

.sc-emr-vitals {
  background: var(--emr-cream);
  border: 1px solid var(--emr-border);
  border-top: none;
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
}
.sc-emr-vital {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.75rem;
  border-right: 1px solid var(--emr-border);
  min-width: 60px;
}
.sc-emr-vital label { font-size: 0.68rem; color: var(--emr-muted); font-weight: 700; margin-bottom: 0.15rem; }
.sc-emr-vitals .sc-emr-btn { margin: 0.35rem 0.6rem 0.35rem auto; align-self: center; }

.sc-emr-input, .sc-emr-textarea {
  background: #fffef4;
  border: 1px solid var(--emr-border);
  border-radius: 0.2rem;
  font-size: 0.82rem;
  padding: 0.15rem 0.4rem;
  color: #2b2400;
  font-family: inherit;
}
.sc-emr-input { width: 48px; text-align: center; }
.sc-emr-textarea { resize: vertical; }
.sc-emr-input:focus, .sc-emr-textarea:focus {
  outline: 2px solid var(--emr-accent);
  outline-offset: -1px;
}

.sc-emr-body {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1rem;
  align-items: start;
  margin-top: 0.85rem;
}
@media (max-width: 992px) {
  .sc-emr-body { grid-template-columns: 1fr; }
}
.sc-emr-main { display: flex; flex-direction: column; gap: 0.85rem; }
.sc-emr-row { display: flex; gap: 0.85rem; align-items: stretch; flex-wrap: wrap; }
.sc-emr-row > .sc-emr-block { flex: 1; min-width: 280px; }
.sc-emr-side { display: flex; flex-direction: column; min-height: 0; }

.sc-emr-block {
  display: flex;
  background: var(--emr-cream);
  border: 1px solid var(--emr-border);
  border-radius: 0.4rem;
  overflow: hidden;
}
.sc-emr-vlabel {
  writing-mode: vertical-rl;
  text-orientation: upright;
  background: var(--emr-vlabel-bg);
  color: #4a3f10;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  padding: 0.6rem 0.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-right: 1px solid var(--emr-border);
}
.sc-emr-block-body { padding: 0.65rem 0.85rem; flex: 1; min-width: 0; }
.sc-emr-block-actions { display: flex; justify-content: flex-end; margin-bottom: 0.4rem; }

.sc-emr-field { margin-top: 0.5rem; }
.sc-emr-field label { display: block; font-size: 0.74rem; font-weight: 700; color: var(--emr-muted); margin-bottom: 0.15rem; }
.sc-emr-field .sc-emr-textarea { width: 100%; }

.sc-emr-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; background: #fffef4; }
.sc-emr-table th {
  background: var(--emr-cream-dark);
  color: #5a4d15;
  font-size: 0.7rem;
  text-transform: uppercase;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--emr-border);
  text-align: left;
}
.sc-emr-table td { padding: 0.2rem 0.35rem; border: 1px solid var(--emr-border); vertical-align: middle; }
.sc-emr-bullet { color: #c0392b; font-size: 0.85rem; }
.sc-emr-remove { background: none; border: none; color: #b23; cursor: pointer; font-size: 0.85rem; }
.sc-emr-remove:hover { color: #7a1a10; }

.sc-case-bg {
  background: #fffef4;
  border: 1px solid var(--emr-border);
  border-radius: 0.3rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.65;
  color: #333;
  margin-bottom: 0.4rem;
  white-space: pre-wrap;
}
.sc-emr-empty { color: #9c9160; font-size: 0.82rem; font-style: italic; padding: 0.4rem 0; }

.sc-emr-actionbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--st-panel-bg);
  border-radius: 0.6rem;
  box-shadow: 0 4px 18px rgba(49, 51, 63, 0.08);
  position: sticky;
  bottom: 1rem;
}

/* 即時記錄浮動白卡（右欄，非病歷格底色） */
.sc-livepanel {
  background: var(--st-panel-bg);
  border-radius: 0.6rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
}
.sc-livepanel-head { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.5rem; }
.sc-livepanel-title { font-weight: 700; font-size: 0.88rem; color: var(--st-text); }
.sc-live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--st-danger);
  animation: sc-blink 1.4s infinite;
}
.sc-live-status { font-size: 0.72rem; color: var(--st-success); font-weight: 700; margin-left: auto; }

/* transcript panel */
.sc-transcript {
  flex: 1;
  min-height: 0;
  max-height: 48vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  background: #f9fafb;
  border-radius: 0.85rem 0.85rem 0 0;
  border: 1px solid var(--st-border);
  border-bottom: none;
}
.sc-seg {
  max-width: 80%;
  padding: 0.55rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
}
.sc-seg-doctor {
  align-self: flex-start;
  background: #e8f0fe;
  color: #1a3c6e;
  border-bottom-left-radius: 0.2rem;
}
.sc-seg-patient {
  align-self: flex-end;
  background: #e6f4ea;
  color: #1b4332;
  border-bottom-right-radius: 0.2rem;
}
.sc-seg-role {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  opacity: 0.65;
  display: block;
  margin-bottom: 0.15rem;
}

/* sidebar hint panel */
.sc-hint-item {
  background: #fffbea;
  border-left: 3px solid var(--st-warning);
  border-radius: 0 0.6rem 0.6rem 0;
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
  color: #4a3800;
}
.sc-hint-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--st-warning);
  margin-bottom: 0.35rem;
}
.sc-hint-text {
  line-height: 1.5;
}
/* 檢驗值表格 */
.sc-hint-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.sc-hint-table td {
  padding: 0.12rem 0.3rem;
  vertical-align: middle;
}
.sc-hint-table td:first-child { color: #6b5700; font-weight: 600; }
.sc-hint-table td:nth-child(2) { font-weight: 700; }
.sc-hint-unit { font-weight: 400; font-size: 0.75rem; color: #8b6f00; }
.sc-hint-ref { color: #9b8200; font-size: 0.75rem; }
.sc-flag-h { color: #c0392b; }
.sc-flag-l { color: #2471a3; }
/* 用藥清單 */
.sc-hint-list {
  margin: 0;
  padding-left: 1.1rem;
  list-style: disc;
}
.sc-hint-list li { margin-bottom: 0.15rem; }
.sc-hint-drug { font-weight: 600; }
.sc-hint-dose { color: #6b5700; font-size: 0.82rem; }
.sc-hint-ind  { color: #9b8200; font-size: 0.8rem; }
/* 過敏 */
.sc-allergy-severe { color: #c0392b; font-weight: 700; }
/* 基本資料 */
.sc-hint-kv {
  font-size: 0.75rem;
  font-weight: 700;
  color: #8b6f00;
  margin-right: 0.4rem;
}
/* fallback raw */
.sc-hint-raw {
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  color: #6b5700;
}

/* ── 醫囑卡片（LLM 建議，encounter.html AI SOAP 區塊） ─────────────── */
.sc-order-card {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  padding: 0.55rem 0.85rem;
  border-radius: 0.5rem;
  font-size: 0.88rem;
  line-height: 1.5;
}
.sc-order-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
  color: #fff;
  flex-shrink: 0;
}
.sc-order-action { font-weight: 700; color: #2c3e50; }
.sc-order-item   { color: #1a252f; }
.sc-order-detail { color: #555; font-size: 0.82rem; }
.sc-order-reason { font-size: 0.8rem; }
/* per-type colours */
.sc-order-medication { background:#fff3e0; border-left:3px solid #e67e22; }
.sc-order-medication .sc-order-badge { background:#e67e22; }
.sc-order-lab        { background:#fde8e8; border-left:3px solid #e74c3c; }
.sc-order-lab        .sc-order-badge { background:#e74c3c; }
.sc-order-imaging    { background:#e8f4fd; border-left:3px solid #2980b9; }
.sc-order-imaging    .sc-order-badge { background:#2980b9; }
.sc-order-followup   { background:#eafaf1; border-left:3px solid #27ae60; }
.sc-order-followup   .sc-order-badge { background:#27ae60; }
.sc-order-education  { background:#f4f4f4; border-left:3px solid #7f8c8d; }
.sc-order-education  .sc-order-badge { background:#7f8c8d; }

/* audio toolbar */
.sc-audio-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: #f8f9fb;
  border: 1px solid var(--st-border);
  border-bottom: none;
  border-radius: 0.85rem 0.85rem 0 0;
}

/* blinking recording dot */
.sc-rec-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--st-danger);
  animation: sc-blink 1s infinite;
  flex-shrink: 0;
}

/* chat input bar — no top radius when audio toolbar is above */
.sc-chat-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border: 1px solid var(--st-border);
  border-top: none;
  border-radius: 0 0 0.85rem 0.85rem;
}
.sc-chat-bar #chat-input {
  flex: 1;
  min-width: 0;
}
.sc-rec-indicator {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ccc;
  flex-shrink: 0;
}
.sc-rec-indicator.recording {
  background: var(--st-danger);
  animation: sc-blink 1s infinite;
}
@keyframes sc-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── SOAP draft ─────────────────────────────────────────────── */
.sc-soap-field { resize: vertical; min-height: 90px; font-size: 0.92rem; }
.sc-soap-label {
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--st-primary);
}

/* ── Shared utils ───────────────────────────────────────────── */
.st-table table { width: 100%; }
.st-table thead { position: sticky; top: 0; background: var(--st-panel-bg); z-index: 1; }
.table-responsive { max-height: 380px; }

.st-expander {
  background: #f8f9fb;
  border-radius: 0.85rem;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(49, 51, 63, 0.06);
}
.st-expander summary { cursor: pointer; font-weight: 600; list-style: none; }
.st-expander summary::-webkit-details-marker { display: none; }
.st-expander[open] { background: #fff; border-color: rgba(26, 115, 232, 0.2); }
.st-expander[open] summary { margin-bottom: 0.75rem; }

.st-code {
  font-family: "Fira Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.88rem;
  border-radius: 0.9rem;
  background: #f8f9fb;
}
