:root {
  --navy: #0f172a;
  --teal: #147f78;
  --teal-dark: #0f6d67;
  --teal-soft: #ecfdf9;
  --canvas: #f4f7fb;
  --surface: #ffffff;
  --line: #dbe4ef;
  --line-strong: #c9d5e4;
  --text: #172033;
  --muted: #708199;
  --amber: #b45309;
  --amber-soft: #fff7ed;
  --red: #b42318;
  --red-soft: #fff1f0;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: Inter, Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; color: var(--text); background: var(--canvas); font-size: 14px; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.topbar { height: 58px; display: flex; align-items: center; padding: 0 20px; color: #dce6f4; background: var(--navy); gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 230px; color: white; }
.brand img { width: 32px; height: 32px; }
.brand strong { font-size: 18px; }
.brand span { color: #91a0b7; font-size: 12px; border-left: 1px solid #344157; padding-left: 10px; }
.topbar nav { display: flex; align-self: stretch; gap: 3px; }
.topbar nav button { color: #aebbd0; border: 0; background: transparent; padding: 0 18px; font-weight: 700; }
.topbar nav button.active { color: white; background: rgba(20,127,120,.9); }
.top-meta { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: 12px; color: #9dabc0; }
.top-meta strong { color: #e6edf7; }

.workspace { display: grid; grid-template-columns: 276px minmax(0, 1fr); height: calc(100vh - 58px); }
.queue-panel { background: #182338; color: #eef4ff; border-right: 1px solid #26344a; display: flex; flex-direction: column; min-height: 0; }
.panel-title { padding: 18px 18px 12px; display: flex; align-items: center; justify-content: space-between; }
.panel-title strong { display: block; font-size: 16px; }
.panel-title small { display: block; margin-top: 4px; color: #8fa0b8; }
.icon-btn { border: 1px solid #3a4961; background: #243149; color: #dbe7f7; border-radius: 8px; width: 34px; height: 34px; font-size: 18px; }
.search { margin: 0 14px; border: 1px solid #3b4961; background: #202c42; border-radius: 9px; display: flex; align-items: center; padding: 0 10px; }
.search span { color: #8494aa; font-size: 18px; }
.search input { width: 100%; padding: 10px 8px; border: 0; outline: 0; color: white; background: transparent; }
.search input::placeholder { color: #8291a7; }
.queue-filters { display: grid; grid-template-columns: repeat(3,1fr); padding: 12px 14px 8px; gap: 5px; }
.queue-filters button { border: 0; border-radius: 7px; background: transparent; color: #8fa0b8; padding: 7px 4px; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 5px; }
.queue-filters button.active { background: #2a3850; color: #fff; }
.queue-filter-count { min-width: 18px; padding: 1px 5px; border-radius: 99px; color: #aebbd0; background: #2a3850; font-size: 9px; line-height: 16px; }
.queue-filters button.active .queue-filter-count { color: #182338; background: #dce6f4; }
.queue-list { flex: 1; overflow: auto; padding: 4px 10px 12px; }
.queue-item { width: 100%; text-align: left; border: 1px solid transparent; color: #dce6f4; background: transparent; border-radius: 9px; padding: 12px 10px; margin-bottom: 5px; display: grid; grid-template-columns: 8px minmax(0,1fr); gap: 10px; align-items: start; }
.queue-item:hover, .queue-item.active { border-color: #3b5d69; background: #24344b; }
.queue-item.patient-selected:not(.active) { border-color: #315160; background: #202f45; }
.status-dot { width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: #8391a6; }
.status-dot.WAITING { background: #f59e0b; }
.status-dot.IN_PROGRESS { background: #2dd4bf; }
.status-dot.COMPLETED { background: #64748b; }
.queue-main { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.queue-name-row { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.queue-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; color: #f4f7fb; }
.queue-status { flex: 0 0 auto; border-radius: 99px; padding: 2px 6px; color: #a9b8cb; background: #2b3850; font-size: 9px; font-weight: 800; }
.queue-status.WAITING { color: #fbbf24; }
.queue-status.IN_PROGRESS { color: #5eead4; }
.queue-complaint { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #aab8ca; font-size: 11px; line-height: 1.4; }
.queue-time { display: block; color: #8494aa; font-size: 10px; line-height: 1.3; }
.queue-more { width: calc(100% - 8px); margin: 5px 4px 10px; border: 1px solid #3a4961; border-radius: 8px; padding: 9px; color: #b9c6d8; background: #202c42; font-size: 11px; font-weight: 800; }
.queue-more:hover { border-color: #5a6c85; background: #27354d; color: #fff; }
.patient-register { border-top: 1px solid #2d3b52; padding: 14px; background: #151f32; }
.patient-register h3 { font-size: 12px; color: #aab8cb; margin: 0 0 9px; }
.patient-register select, .patient-register input { width: 100%; color: #e6edf7; background: #202c42; border: 1px solid #3b4961; border-radius: 7px; padding: 9px; margin-bottom: 7px; outline: 0; }

.clinical-panel { min-width: 0; overflow: auto; }
.empty-state { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.empty-state img { width: 66px; height: 66px; box-shadow: var(--shadow); border-radius: 16px; }
.empty-state h1 { color: var(--text); font-size: 21px; margin: 22px 0 7px; }
.empty-state p { margin: 0; }
.hidden { display: none !important; }
.encounter { min-height: 100%; padding-bottom: 76px; }
.patient-banner { min-height: 84px; background: white; border-bottom: 1px solid var(--line); padding: 13px 24px; display: flex; align-items: center; gap: 13px; position: sticky; top: 0; z-index: 8; }
.patient-avatar { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--teal-soft); color: var(--teal); font-size: 17px; font-weight: 900; }
.patient-name { display: flex; align-items: center; gap: 9px; }
.patient-name h1 { font-size: 19px; margin: 0; }
.patient-name span { color: var(--muted); font-size: 11px; }
.patient-banner p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.patient-flags { display: flex; gap: 6px; margin-left: 16px; flex-wrap: wrap; }
.encounter-state { margin-left: auto; text-align: right; }
.encounter-state span { display: inline-block; color: var(--teal); background: var(--teal-soft); border-radius: 99px; padding: 5px 9px; font-size: 11px; font-weight: 800; }
.encounter-state small { display: block; color: var(--muted); margin-top: 5px; }
.badge { display: inline-flex; align-items: center; border-radius: 99px; padding: 4px 8px; font-size: 11px; font-weight: 800; }
.badge.neutral { background: #eef2f7; color: #5f6f85; }
.badge.ok { background: var(--teal-soft); color: var(--teal-dark); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.danger { background: var(--red-soft); color: var(--red); }

.clinical-grid { padding: 16px; display: grid; grid-template-columns: minmax(610px, 1fr) 340px; gap: 14px; max-width: 1580px; margin: 0 auto; }
.main-column, .context-column { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(15,23,42,.02); padding: 16px; }
.card.compact { padding: 14px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-heading h2 { font-size: 15px; margin: 2px 0 0; }
.eyebrow { color: var(--teal); font-size: 10px; font-weight: 900; letter-spacing: .04em; }
.secondary, .primary { border-radius: 8px; padding: 9px 13px; font-weight: 800; border: 1px solid transparent; }
.primary { color: white; background: var(--teal); }
.primary:hover { background: var(--teal-dark); }
.primary:disabled { cursor: not-allowed; background: #b4c2cf; }
.secondary { color: #475569; background: white; border-color: var(--line-strong); }
.secondary:hover { border-color: var(--teal); color: var(--teal); }
.full { width: 100%; }
textarea, .autocomplete-row input, .inline-form input { border: 1px solid var(--line-strong); border-radius: 8px; color: var(--text); outline: 0; }
textarea:focus, input:focus, select:focus { border-color: var(--teal) !important; box-shadow: 0 0 0 3px rgba(20,127,120,.08); }
textarea { width: 100%; min-height: 120px; resize: vertical; padding: 12px; line-height: 1.65; }
.autocomplete-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.autocomplete-row input { padding: 9px 10px; }
.search-results { margin-top: 7px; display: flex; flex-direction: column; gap: 4px; }
.result-option { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #f9fbfd; text-align: left; color: var(--text); }
.result-option:hover { background: var(--teal-soft); border-color: #8ddbd0; }
.result-option strong { display: block; font-size: 12px; }
.result-option small { color: var(--muted); }
.diagnosis-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.diagnosis-chip { border: 1px solid #a7e4da; background: var(--teal-soft); border-radius: 8px; padding: 7px 9px; display: flex; gap: 7px; align-items: center; font-size: 12px; }
.diagnosis-chip button { border: 0; background: transparent; color: #6a7b90; }
.diagnosis-warnings { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.diagnosis-warning { display: flex; gap: 8px; align-items: flex-start; border: 1px solid #fed7aa; border-radius: 8px; background: var(--amber-soft); color: #92400e; padding: 8px 10px; font-size: 11px; line-height: 1.45; }
.diagnosis-warning.info { border-color: #bae6fd; background: #f0f9ff; color: #075985; }
.diagnosis-warning strong { flex: 0 0 auto; }
.revision { text-align: right; }
.revision span { display: block; color: var(--teal); font-size: 11px; font-weight: 800; }
.revision small { color: var(--muted); }
.table-wrap { margin-top: 10px; overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
table { border-collapse: collapse; width: 100%; min-width: 720px; }
th { background: #f4f7fb; color: #68778c; text-align: left; padding: 9px 8px; font-size: 10px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid #edf1f6; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td strong { display: block; font-size: 12px; }
td small { color: var(--muted); font-size: 10px; }
td input, td select { width: 76px; padding: 7px; border: 1px solid var(--line); border-radius: 6px; outline: 0; background: white; }
td .freq-input { width: 88px; }
.delete-btn { color: #94a3b8; border: 0; background: transparent; font-size: 16px; }
.delete-btn:hover { color: var(--red); }

.history-count { color: var(--muted); background: #f4f7fb; border: 1px solid var(--line); border-radius: 99px; padding: 4px 9px; font-size: 11px; font-weight: 800; }
.visit-history-layout { min-height: 210px; display: grid; grid-template-columns: 220px minmax(0, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.visit-history-list { max-height: 360px; overflow-y: auto; background: #f7f9fc; border-right: 1px solid var(--line); padding: 7px; }
.visit-history-item { width: 100%; display: block; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--text); padding: 10px; text-align: left; }
.visit-history-item + .visit-history-item { margin-top: 4px; }
.visit-history-item:hover { background: white; border-color: var(--line); }
.visit-history-item.active { background: white; border-color: #8ddbd0; box-shadow: 0 1px 3px rgba(15,23,42,.05); }
.visit-history-item strong { display: block; font-size: 12px; }
.visit-history-item span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visit-history-item small { display: inline-block; margin-top: 7px; color: var(--teal); font-size: 10px; font-weight: 800; }
.visit-history-detail { min-width: 0; max-height: 360px; overflow-y: auto; padding: 15px; background: white; }
.history-placeholder { margin: 0; min-height: 176px; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; line-height: 1.6; }
.history-detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.history-detail-head h3 { margin: 0; font-size: 14px; }
.history-detail-head p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.history-section { padding-top: 12px; }
.history-section h4 { margin: 0 0 7px; color: #526277; font-size: 11px; }
.history-note { margin: 0; padding: 10px; border-radius: 8px; background: #f7f9fc; color: #334155; line-height: 1.6; font-size: 12px; white-space: pre-wrap; }
.history-chip-list { display: flex; gap: 6px; flex-wrap: wrap; }
.history-chip { border: 1px solid #b7e6df; border-radius: 7px; background: var(--teal-soft); color: var(--teal-dark); padding: 5px 7px; font-size: 11px; }
.history-rx-list { display: flex; flex-direction: column; gap: 5px; }
.history-rx-row { display: grid; grid-template-columns: minmax(150px, 1fr) auto; gap: 12px; border-bottom: 1px solid #edf1f6; padding: 7px 0; font-size: 11px; }
.history-rx-row:last-child { border-bottom: 0; }
.history-rx-row strong { display: block; font-size: 12px; }
.history-rx-row small { display: block; margin-top: 3px; color: var(--muted); }
.history-rx-row span { color: #475569; white-space: nowrap; }
.history-lab-list { display: flex; gap: 6px; flex-wrap: wrap; }
.history-lab { border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; font-size: 11px; }
.history-lab strong { margin-left: 5px; }

.mydata-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.mydata-batch { border: 1px solid var(--line); border-radius: 9px; background: #f9fbfd; padding: 10px; }
.mydata-batch-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.mydata-batch-head strong { font-size: 12px; }
.mydata-batch-head small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.mydata-item { margin-top: 8px; padding-top: 8px; border-top: 1px solid #e8eef5; }
.mydata-item strong { display: block; font-size: 11px; }
.mydata-item span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.mydata-item .mapping-ok { color: var(--teal); }
.mydata-item .mapping-warn { color: var(--amber); }
.mydata-subtitle { display: block; margin-top: 10px; padding-top: 9px; border-top: 1px solid #e8eef5; color: #526277; font-size: 11px; }
.mydata-allergy { margin-top: 6px; border: 1px solid #fed7aa; border-radius: 7px; padding: 8px; background: var(--amber-soft); }
.mydata-allergy strong { display: block; color: #92400e; font-size: 11px; }
.mydata-allergy span { display: block; margin-top: 3px; color: #9a5b22; font-size: 10px; line-height: 1.45; }
.mydata-actions { display: flex; gap: 6px; margin-top: 9px; }
.mydata-actions button { flex: 1; padding: 7px 8px; font-size: 11px; }
.mydata-review { margin-top: 8px; border-radius: 7px; padding: 8px; background: var(--teal-soft); color: var(--teal-dark); font-size: 11px; line-height: 1.5; }
.mydata-review.alert { background: var(--amber-soft); color: var(--amber); }

.record-list { display: flex; flex-direction: column; gap: 6px; }
.record-item { border-bottom: 1px solid #edf1f6; padding: 7px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.record-item:last-child { border-bottom: 0; }
.record-item strong { font-size: 12px; }
.record-item small { display: block; color: var(--muted); margin-top: 2px; }
.record-value { font-weight: 800; color: #334155; white-space: nowrap; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 10px; }
.inline-form input { min-width: 0; padding: 8px; }
.lab-form { grid-template-columns: .8fr .7fr .7fr auto; }
.safety-help { color: var(--muted); line-height: 1.55; font-size: 12px; }
.review-result { margin-top: 10px; }
.review-summary { border-radius: 9px; padding: 10px; background: var(--teal-soft); color: var(--teal-dark); font-weight: 800; }
.alert-card { margin-top: 7px; border: 1px solid #fed7aa; border-left: 4px solid #f59e0b; background: #fffaf2; border-radius: 8px; padding: 10px; }
.alert-card.danger { border-color: #fecaca; border-left-color: #dc2626; background: #fff7f7; }
.alert-card strong { font-size: 12px; }
.alert-card p { margin: 6px 0; line-height: 1.45; font-size: 11px; }
.alert-card small { color: var(--muted); }
.review-history { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.review-context { display: block; margin-bottom: 7px; color: var(--teal-dark); font-size: 11px; }
.previous-review { margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.previous-review > summary { cursor: pointer; padding: 9px 10px; color: var(--muted); font-size: 11px; font-weight: 800; }
.previous-review[open] > summary { border-bottom: 1px solid var(--line); }
.previous-review > div { margin: 0; border: 0; border-radius: 0 0 8px 8px; }
.mydata-alert-line { margin-top: 4px; }
.history-row { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: 11px; color: var(--muted); }
.history-row button { border: 0; background: transparent; color: var(--teal); font-weight: 800; }

.actionbar { position: fixed; bottom: 0; left: 276px; right: 0; z-index: 9; min-height: 66px; background: rgba(255,255,255,.97); border-top: 1px solid var(--line); box-shadow: 0 -8px 22px rgba(15,23,42,.05); display: flex; align-items: center; justify-content: flex-end; gap: 18px; padding: 10px 24px; }
.actionbar div { text-align: right; }
.actionbar strong { display: block; }
.actionbar span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.toast { position: fixed; right: 22px; bottom: 86px; z-index: 20; color: white; background: #263449; border-radius: 9px; padding: 11px 14px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #9f2d25; }

.apply-confirm-dialog { width: min(460px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 14px; color: var(--text); box-shadow: 0 22px 70px rgba(15,23,42,.28); }
.apply-confirm-dialog::backdrop { background: rgba(15,23,42,.46); backdrop-filter: blur(2px); }
.apply-confirm-head { padding: 22px 22px 16px; border-bottom: 1px solid var(--line); }
.apply-confirm-head h2 { margin: 5px 0 0; font-size: 18px; }
.apply-confirm-head p { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.apply-confirm-summary { margin: 0; padding: 14px 22px; display: grid; gap: 8px; }
.apply-confirm-summary div { display: grid; grid-template-columns: 64px minmax(0,1fr); gap: 10px; }
.apply-confirm-summary dt { color: var(--muted); font-size: 11px; }
.apply-confirm-summary dd { margin: 0; font-size: 12px; font-weight: 800; }
.apply-confirm-alert { margin: 0 22px; border: 1px solid #a7e4da; border-radius: 9px; padding: 10px 12px; color: var(--teal-dark); background: var(--teal-soft); font-size: 12px; font-weight: 800; }
.apply-confirm-alert.warn { border-color: #fed7aa; color: #92400e; background: var(--amber-soft); }
.apply-confirm-severity { min-height: 16px; margin: 8px 22px 0; color: var(--muted); font-size: 11px; }
.apply-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 22px 22px; }
.mydata-consent-options { display: grid; gap: 8px; padding: 16px 22px 6px; }
.mydata-consent-options label { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--line); border-radius: 9px; padding: 11px; cursor: pointer; }
.mydata-consent-options label:has(input:checked) { border-color: #8ddbd0; background: var(--teal-soft); }
.mydata-consent-options input { margin-top: 2px; }
.mydata-consent-options strong, .mydata-consent-options small { display: block; }
.mydata-consent-options strong { font-size: 12px; }
.mydata-consent-options small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.mydata-consent-note { margin: 8px 22px 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

@media (max-width: 1100px) {
  .clinical-grid { grid-template-columns: 1fr; }
  .context-column { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
  .safety-card { grid-column: 1 / -1; }
  .mydata-card { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .visit-history-layout { grid-template-columns: 1fr; }
  .visit-history-list { max-height: 170px; border-right: 0; border-bottom: 1px solid var(--line); }
}
