/* =========================================================
   GuGu Medical Center EMR — Blue Design System (v4)
   - 하나의 토큰 체계로 정리 (이전의 겹겹이 쌓인 override 제거)
   - 기능용 클래스(.hidden, .editing, .plan-edit, .open 등)는 그대로 유지
   ========================================================= */

/* ---------- 1. Tokens ---------- */
:root {
  /* Blue scale */
  --blue-950: #0a1f3d;
  --blue-900: #0f2c55;
  --blue-800: #163d73;
  --blue-700: #1d4f94;
  --blue-600: #2563c4;   /* primary */
  --blue-500: #3b7be0;
  --blue-400: #6a9cec;
  --blue-200: #c9daf6;
  --blue-100: #e3ecfb;
  --blue-50:  #f1f6fd;

  /* Neutrals (blue-tinted slate) */
  --bg:        #f3f6fa;
  --surface:   #ffffff;
  --surface-2: #f7f9fc;
  --border:    #e1e7ef;
  --border-strong: #cbd5e1;
  --text:      #0f1e33;
  --text-2:    #334155;
  --muted:     #64748b;
  --faint:     #94a3b8;

  /* Semantic */
  --primary: var(--blue-600);
  --primary-hover: var(--blue-700);
  --danger: #d14343;
  --danger-bg: #fdecec;
  --success: #12805c;
  --success-bg: #e6f5ef;
  --warning: #b7791f;
  --warning-bg: #fdf4e3;

  /* Shape */
  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-xs: 0 1px 2px rgba(15, 30, 51, .05);
  --shadow-sm: 0 1px 3px rgba(15, 30, 51, .06), 0 1px 2px rgba(15, 30, 51, .04);
  --shadow-md: 0 8px 24px rgba(15, 30, 51, .08);
  --shadow-lg: 0 20px 48px rgba(15, 30, 51, .18);
  --ring: 0 0 0 3px rgba(37, 99, 196, .22);

  /* Sizing */
  --control-h: 40px;
  --control-h-sm: 32px;
  --appbar-h: 60px;

  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
          "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3 { margin: 0; color: var(--text); letter-spacing: -0.02em; }
strong { font-weight: 700; }
::selection { background: var(--blue-100); }

.hidden { display: none !important; }

.container {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

/* ---------- 3. App bar ---------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--appbar-h);
  background: var(--blue-900);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 2px 10px rgba(10,31,61,.18);
}
.app-bar-inner {
  max-width: 1680px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.02rem;
  color: #fff;
  white-space: nowrap;
}
.app-brand img {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #fff;
  object-fit: cover;
  box-shadow: 0 0 0 2px rgba(255,255,255,.25);
}
.app-brand .brand-sub {
  font-weight: 500;
  color: var(--blue-200);
  font-size: .82rem;
  padding: 2px 8px;
  border: 1px solid rgba(201,218,246,.35);
  border-radius: 999px;
  margin-left: 2px;
}
.app-nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.app-nav a {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border-radius: 8px;
  color: var(--blue-100);
  font-size: .9rem; font-weight: 600;
  transition: background .15s, color .15s;
}
.app-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.app-nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.app-date { color: var(--blue-200); font-size: .85rem; font-variant-numeric: tabular-nums; padding-left: 12px; border-left: 1px solid rgba(255,255,255,.15); }

.footer {
  position: fixed;
  right: 14px; bottom: 10px;
  font-size: 11px;
  color: var(--faint);
  pointer-events: none;
}

/* ---------- 4. Buttons ---------- */
button,
.button,
.btn,
input[type="button"],
input[type="submit"] {
  font-family: inherit;
}

button,
.button,
.btn,
.btn-submit,
.btn-complete,
.btn-chart,
.back-button,
.confirm-button,
.new-button,
.export-button,
.reset-button,
#confirm-name-search,
#save-vitals-btn,
#load-prev-plan-btn,
#toggle-past-btn,
#edit-past-btn,
#save-past-btn,
#save-new-patient,
#cancel-new-patient,
#confirm-complete,
#cancel-complete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--control-h);
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font-size: .9rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
button:hover,
.button:hover,
.btn:hover,
.btn-chart:hover,
.back-button:hover,
.new-button:hover,
#toggle-past-btn:hover,
#edit-past-btn:hover,
#load-prev-plan-btn:hover,
#cancel-new-patient:hover,
#cancel-complete:hover {
  background: var(--blue-50);
  border-color: var(--blue-200);
  color: var(--blue-700);
}
button:focus-visible,
.button:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
button:disabled,
.button:disabled {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: none;
}
button:disabled:hover { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); }

button i, .button i, a i { font-size: .92em; }

/* Primary */
.btn-primary,
.btn-submit,
.confirm-button,
.form-panel .button-group .button[type="submit"],
#confirm-name-search,
#save-vitals-btn,
#save-past-btn,
#save-new-patient,
#confirm-complete,
#go-med {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover,
.btn-submit:hover,
.confirm-button:hover,
.form-panel .button-group .button[type="submit"]:hover,
#confirm-name-search:hover,
#save-vitals-btn:hover,
#save-past-btn:hover,
#save-new-patient:hover,
#confirm-complete:hover,
#go-med:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}

/* Strong (navy) — 진료 완료 등 확정 동작 */
.btn-complete,
#nur-complete-btn {
  background: var(--blue-900);
  border-color: var(--blue-900);
  color: #fff;
}
.btn-complete:hover,
#nur-complete-btn:hover:not(:disabled) { background: var(--blue-950); border-color: var(--blue-950); color: #fff; }

/* Soft blue — 보조 */
.export-button,
.btn-chart {
  background: var(--blue-50);
  border-color: var(--blue-200);
  color: var(--blue-700);
}
.export-button:hover,
.btn-chart:hover { background: var(--blue-100); border-color: var(--blue-400); color: var(--blue-800); }

/* Danger (outline) */
.reset-button,
.delete-button {
  background: var(--surface);
  border-color: #f0c4c4;
  color: var(--danger);
}
.reset-button:hover,
.delete-button:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

/* Small */
.btn-sm,
#toggle-past-btn,
#edit-past-btn,
#save-past-btn,
#load-prev-plan-btn,
.btn-plan-edit {
  height: var(--control-h-sm);
  padding: 0 12px;
  font-size: .82rem;
}

/* Icon-only buttons in tables */
.icon-btn,
.patient-table .enter-button,
.patient-table .delete-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
}
.patient-table .enter-button {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.patient-table .enter-button:hover { background: var(--primary-hover); color: #fff; }
.patient-table .enter-button:disabled {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--faint);
  opacity: 1;
}
.patient-table .delete-button { border-color: transparent; box-shadow: none; color: var(--faint); background: transparent; }
.patient-table .delete-button:hover { color: var(--danger); background: var(--danger-bg); border-color: transparent; }

.button-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- 5. Form controls ---------- */
input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
input:not([type]),
select,
textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .92rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
textarea { min-height: 0; line-height: 1.55; resize: vertical; }
select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover:not([readonly]):not(:disabled),
select:hover:not(:disabled),
textarea:hover:not([readonly]) { border-color: var(--blue-400); }
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--ring);
}
input[readonly],
textarea[readonly],
select:disabled,
input:disabled {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--border);
}
input[type="radio"],
input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; vertical-align: middle; cursor: pointer; }

label { color: var(--text-2); }

/* ---------- 6. Cards ---------- */
.card,
.emr-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 700;
}
.card-title .title-icon {
  width: 30px; height: 30px;
  display: inline-grid; place-items: center;
  border-radius: 8px;
  background: var(--blue-50);
  color: var(--primary);
  font-size: .85rem;
}
.count-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 22px; padding: 0 8px;
  border-radius: 999px;
  background: var(--blue-50);
  color: var(--blue-700);
  font-size: .78rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- 7. Tables (공통) ---------- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .9rem;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}
th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }

.table-bordered,
.plan-table,
.ne-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-bordered td + td,
.table-bordered th + th { border-left: 1px solid var(--border); }
.table-bordered td[rowspan] { background: var(--surface-2); font-weight: 600; color: var(--text-2); border-right: 1px solid var(--border); }
.table-active td { background: var(--blue-50); }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }

/* ---------- 8. Login ---------- */
.login-wrapper {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(59,123,224,.22), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(29,79,148,.20), transparent 60%),
    var(--bg);
}
body:has(.login-wrapper) .container { padding: 0; max-width: none; }
.login-box {
  width: 100%;
  max-width: 380px;
  padding: 36px 32px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 6px var(--blue-50); }
.login-box h2 { margin: 18px 0 24px; font-size: 1.35rem; font-weight: 800; }
.login-sub { margin: 0 0 24px; color: var(--muted); font-size: .88rem; }
.input-group { position: relative; margin-bottom: 12px; }
.input-group label {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--faint); font-size: .9rem; pointer-events: none;
}
.input-group input { height: 46px; padding-left: 40px; font-size: .95rem; }
.login-button {
  width: 100%;
  height: 46px;
  margin-top: 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: .98rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color .15s;
}
.login-button:hover { background: var(--primary-hover); }
.login-box .error-message {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: .85rem;
}

/* ---------- 9. Dashboard ---------- */
.dashboard-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 0 18px;
}
.dashboard-header .clinic-name { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.03em; }
.dashboard-header .page-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }

.dashboard-container {
  display: grid;
  grid-template-columns: minmax(420px, 5fr) 7fr;
  gap: 20px;
  align-items: start;
}

/* 오늘의 환자 */
.patient-list-section { display: flex; flex-direction: column; }
.patient-table-scroll {
  max-height: calc(100vh - 360px);
  min-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.patient-table th {
  position: sticky; top: 0; z-index: 1;
  border-bottom: 1px solid var(--border);
}
.patient-table th:nth-child(1), .patient-table td:nth-child(1) { width: 56px; color: var(--muted); font-variant-numeric: tabular-nums; }
.patient-table th:nth-child(2), .patient-table td:nth-child(2) { text-align: left; }
.patient-table th:nth-child(3) { width: 108px; }
.patient-table th:nth-child(4), .patient-table th:nth-child(5) { width: 60px; }
.patient-table td { padding: 8px 12px; height: 52px; }
.patient-table td:nth-child(2) { font-weight: 600; color: var(--text); }
.patient-table tbody tr { transition: background-color .12s; }
.patient-table tbody tr:hover td { background: var(--blue-50); }
.patient-table .delete-col { display: none; }
.patient-table.management-mode .delete-col { display: table-cell; }
.patient-table:has(#patient-list:empty) tbody::after {
  content: "등록된 환자가 없습니다";
  display: block;
  padding: 40px 0;
  color: var(--faint);
  text-align: center;
}

.small-birthdate {
  margin-left: 4px;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* 상태 배지 */
.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: 999px;
  font-size: .78rem; font-weight: 700;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-badge[data-tone="wait"]     { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.status-badge[data-tone="treat"]    { background: var(--blue-50); color: var(--blue-700); border-color: var(--blue-200); }
.status-badge[data-tone="iv-wait"]  { background: #ecf7fb; color: #0e6a8a; border-color: #bfe3ef; }
.status-badge[data-tone="iv"]       { background: #e7f3fb; color: #0b5f9c; border-color: #b6d8f0; }
.status-badge[data-tone="med"]      { background: #eef0fd; color: #3f48b8; border-color: #cdd2f7; }
.status-badge[data-tone="done"]     { background: var(--success-bg); color: var(--success); border-color: #bfe5d5; }

/* 환자 등록 입력 */
.patient-controls { position: relative; margin-top: 16px; }
.search-field { position: relative; }
.search-field > i {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--faint); font-size: .85rem; pointer-events: none;
}
.search-field > input { padding-left: 36px; }
#new-patient-search { position: relative; }
.suggestion-list {
  position: absolute;
  left: 0; right: 0; top: 6px;
  z-index: 20;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 4px;
}
.suggestion-list li {
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .9rem;
}
.suggestion-list li:hover { background: var(--blue-50); color: var(--blue-700); }
.no-result { margin-top: 8px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--muted); font-size: .85rem; }

.patient-actions-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.patient-actions-bar .secondary-actions { display: flex; gap: 8px; grid-column: 1 / -1; }
.patient-actions-bar .secondary-actions > * { flex: 1; }
.patient-actions-bar button { width: 100%; }

/* 부서 현황 */
.status-section { display: flex; flex-direction: column; gap: 20px; }
.status-container {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.status-box {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: calc(100vh - 360px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.status-box h3 {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  font-size: .9rem;
  font-weight: 700;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--tone, var(--primary));
}
.status-box h3 i { color: var(--tone, var(--primary)); font-size: .85rem; }
.status-box h3 .dept-sub { color: var(--muted); font-weight: 600; }
.status-box h3 .count-pill { margin-left: auto; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
#in-treatment      { --tone: var(--blue-600); }
#in-infusion-wait  { --tone: #2a93b8; }
#in-infusion       { --tone: #1673b8; }
#in-medication     { --tone: #4f58c9; }

.status-box ul {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.status-box ul:empty::after {
  content: "대기 환자 없음";
  margin: auto;
  padding: 24px 0;
  color: var(--faint);
  font-size: .82rem;
}
.status-box ul li { margin: 0; padding: 0; }
.status-box ul li a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--tone, var(--primary));
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text) !important;
  box-shadow: var(--shadow-xs);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.status-box ul li a::after {
  content: "\f054";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: .7rem;
  color: var(--faint);
}
.status-box ul li a:hover {
  border-color: var(--blue-200);
  border-left-color: var(--tone, var(--primary));
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* 환자 검색 */
.search-patient-section { display: flex; flex-direction: column; gap: 10px; }
.search-row { display: flex; gap: 8px; }
.search-row .search-field { flex: 1; }
.search-row button { flex: 0 0 auto; min-width: 96px; }
#search-results { display: flex; flex-wrap: wrap; gap: 8px; }
#search-results:not(:empty) { padding-top: 4px; }
#search-results > div { display: contents; }
#search-results .open-chart-picker {
  display: inline-flex; align-items: center; gap: 4px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  font-size: .88rem;
  transition: background .15s, border-color .15s;
}
#search-results .open-chart-picker:hover { background: var(--blue-50); border-color: var(--blue-200); color: var(--blue-700); }

/* ---------- 10. Modal / Popup ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(10, 31, 61, .45);
  backdrop-filter: blur(2px);
}
.modal-content {
  position: relative;
  width: calc(100% - 32px);
  max-width: 480px;
  margin: 10vh auto 0;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.modal-content h3 { font-size: 1.1rem; font-weight: 700; margin: 0 0 16px; padding-right: 32px; }
.modal-content p { margin: 0 0 8px; color: var(--text-2); font-size: .92rem; }
.modal-content p strong { color: var(--text); }
.modal-content .note { color: var(--danger); font-size: .82rem; }
.close-button {
  position: absolute; top: 16px; right: 16px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--muted);
  font-size: 1.3rem; line-height: 1;
  cursor: pointer;
}
.close-button:hover { background: var(--surface-2); color: var(--text); }
.modal-section { margin-bottom: 16px; }
.modal-section label { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: .9rem; }
.modal-section label input { flex: 1; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; border-top: 1px solid var(--border); }

#chart-picker-modal .modal-content { max-width: 420px !important; }
#chart-picker-modal .modal-content > p { color: var(--muted) !important; }
#chart-picker-modal .button-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#chart-picker-modal .button {
  height: 88px;
  flex-direction: column;
  gap: 8px;
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
  font-size: .92rem;
}
#chart-picker-modal .button::before {
  font-family: "Font Awesome 6 Free"; font-weight: 900; font-size: 1.25rem;
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px;
  background: var(--blue-50); color: var(--primary);
}
#chart-picker-modal #go-med::before { content: "\f0f0"; }
#chart-picker-modal #go-pha::before { content: "\f484"; color: #4f58c9; background: #eef0fd; }
#chart-picker-modal #go-nur::before { content: "\f48e"; color: #1673b8; background: #e7f3fb; }
#chart-picker-modal .button:hover { border-color: var(--blue-400) !important; background: var(--blue-50) !important; }

.popup-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  background: rgba(10, 31, 61, .45);
  backdrop-filter: blur(2px);
}
.popup-form {
  width: calc(100% - 32px);
  max-width: 380px;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.popup-form h3 { margin: 0 0 18px; font-size: 1.1rem; font-weight: 700; }
.popup-form label { display: block; margin-bottom: 14px; font-size: .85rem; font-weight: 600; }
.popup-form label input { margin-top: 6px; }
.popup-form .button-group { justify-content: flex-end; margin-top: 20px; }

/* ---------- 11. Toast ---------- */
.toast {
  position: fixed;
  right: 24px; bottom: 24px;
  z-index: 10000;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--blue-950);
  color: #fff;
  font-size: .9rem; font-weight: 600;
  box-shadow: var(--shadow-lg);
}
.toast.success { background: var(--blue-900); }
.toast.success::before { content: "\f058"; font-family: "Font Awesome 6 Free"; font-weight: 900; color: #7fd1ae; }
.toast.error { background: #8f2626; }
.toast.error::before { content: "\f06a"; font-family: "Font Awesome 6 Free"; font-weight: 900; color: #ffc9c9; }

/* ---------- 12. Patient pages ---------- */
.patient-header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 22px 0 18px;
}
.patient-header .avatar {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--blue-600);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
}
.patient-header .patient-title { font-size: 1.45rem; font-weight: 800; }
.patient-header .patient-title span { margin-left: 6px; color: var(--muted); font-size: 1rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.patient-header p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.patient-header .dept-tag {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: 999px;
  background: var(--blue-50);
  color: var(--blue-700);
  font-size: .78rem; font-weight: 700;
}
.patient-header .back-button { margin-left: auto; }

.emr-layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.emr-layout.two-col { grid-template-columns: 200px minmax(0, 1120px); justify-content: center; }
.emr-layout:has(#past-panel-body.hidden) { grid-template-columns: 200px minmax(0, 1.4fr) minmax(0, .6fr); }

.emr-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  font-size: 1.05rem;
  font-weight: 700;
}
.emr-card h2 > i { color: var(--primary); font-size: .95rem; }
.emr-card h2 .h-actions { margin-left: auto; display: flex; gap: 6px; }

/* 방문 기록 */
.visits-panel { position: sticky; top: calc(var(--appbar-h) + 16px); padding: 16px; }
.visits-panel h2 { margin-bottom: 10px; padding-bottom: 12px; font-size: .95rem; }
.visits-panel ul { display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 220px); overflow-y: auto; }
.visits-panel ul li { margin: 0; color: var(--muted); font-size: .85rem; }
.visits-panel ul li a,
.visits-panel .record-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  transition: background .12s, color .12s;
}
.visits-panel ul li a::before {
  content: "\f133"; font-family: "Font Awesome 6 Free"; font-weight: 400;
  font-size: .8rem; color: var(--faint);
}
.visits-panel ul li a:hover { background: var(--blue-50); color: var(--blue-700); }
.visits-panel ul li a:hover::before { color: var(--blue-500); }
.visits-panel ul li a:has(strong) { background: var(--blue-50); color: var(--blue-700); font-weight: 700; }
.visits-panel ul li a strong { margin-left: auto; color: var(--primary); }

/* 폼 패널 */
.form-panel { font-size: .92rem; min-width: 0; }
.form-group { margin-bottom: 14px; }
.form-group > label,
.form-group label:not(.checkbox-sign-label) {
  display: block;
  margin-bottom: 6px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
}
.form-group label strong {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px; margin-right: 4px;
  border-radius: 5px;
  background: var(--blue-600);
  color: #fff;
  font-size: .72rem;
}

.form-panel .date-inline { display: flex; align-items: center; gap: 10px; }
.form-panel .date-inline label { margin: 0; white-space: nowrap; }
.form-panel .date-inline input[type="date"] { width: 170px; }

.form-panel .header-group {
  display: grid;
  grid-template-columns: auto minmax(0, 1.4fr) auto minmax(0, .8fr) auto minmax(0, .8fr);
  align-items: center;
  gap: 8px 10px;
}
.form-panel .header-group label { margin: 0; white-space: nowrap; }

.form-panel fieldset,
.form-panel fieldset.section-fieldset,
.form-section,
.section-fieldset {
  margin: 0 0 16px;
  padding: 14px 16px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 0;
}
.form-panel legend,
fieldset legend {
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px;
  margin-left: -4px;
  font-size: .82rem;
  font-weight: 700;
  color: var(--blue-700);
  letter-spacing: .01em;
}

.form-panel .vitals-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 12px;
}
.form-panel .vital-item label { display: block; margin-bottom: 4px; font-size: .78rem; font-weight: 600; color: var(--muted); }
.form-panel .vital-item input { font-variant-numeric: tabular-nums; }
#save-vitals-btn { margin: -4px 0 18px auto; display: flex; }

.form-panel .no-wrap { display: flex; gap: 10px; margin-bottom: 12px; }
.form-panel .no-wrap:last-child { margin-bottom: 0; }
.form-panel .no-wrap .inline-item { flex: 1; min-width: 0; }
.form-panel .no-wrap .inline-item.grow-2 { flex: 2; }
.form-panel .no-wrap .inline-item label { display: block; margin-bottom: 4px; font-size: .78rem; font-weight: 600; color: var(--muted); }

.readonly-value {
  min-height: var(--control-h);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  white-space: pre-wrap;
  word-break: break-word;
}
fieldset > .readonly-value { font-weight: 500; }

.btn-chart-container { display: flex; justify-content: flex-end; margin: -6px 0 12px; }

/* Plan 표 */
.plan-table { table-layout: fixed; margin-top: 4px; font-size: .88rem; }
.plan-table th { padding: 9px 8px; }
.plan-table td { padding: 6px 8px; border-left: 1px solid var(--border); }
.plan-table td:first-child { border-left: none; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; background: var(--surface-2); }
.plan-table td:nth-child(2) { text-align: left; font-weight: 600; color: var(--text-2); }
.plan-table td input[type="text"] { min-height: 34px; padding: 6px 10px; font-size: .88rem; }
.plan-table col.col-num { width: 44px; }
.plan-table col.col-desc { width: 46%; }
.plan-table col.col-method,
.plan-table col.col-period { width: auto; }
.plan-table:not(:has(colgroup)) th:first-child { width: 44px; }

.site-row { white-space: nowrap; }
.site-row input[type="text"] { display: inline-block; width: 110px !important; min-height: 30px !important; margin: 0 2px; vertical-align: middle; }

/* O/X 분할 버튼 */
.plan-table td:has(.radio-btn-group) { padding: 6px 8px; }
.radio-btn-group {
  display: flex;
  width: 100%;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.plan-radio-label {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  min-width: 0;
  height: 28px;
  border-radius: 6px;
  font-size: .84rem; font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: background .12s, color .12s, box-shadow .12s;
}
.plan-radio-label input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.plan-radio-label:hover { background: var(--surface); color: var(--blue-700); }
.plan-radio-label:has(input:checked) { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }
.plan-radio-label:has(input:disabled) { cursor: default; }
.plan-radio-label:has(input:disabled):hover { background: transparent; color: var(--muted); }
.plan-radio-label:has(input:disabled:checked),
.plan-radio-label:has(input:disabled:checked):hover { background: var(--blue-400); color: #fff; }
.radio-cell-label { margin-bottom: 4px; font-size: .74rem; font-weight: 600; color: var(--muted); text-align: center; }

.btn-plan-edit {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--blue-200);
  border-radius: var(--radius-sm);
  background: var(--blue-50);
  color: var(--blue-700);
  font-weight: 600;
  cursor: pointer;
}
.btn-plan-edit:hover,
.btn-plan-edit-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.plan-toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }

/* 약국 Plan 뷰/편집 모드 */
#pha-plan-table .plan-edit { display: none; }
#pha-plan-table .plan-view { font-weight: 600; color: var(--text); }
#pha-plan-table.editing .plan-view { display: none; }
#pha-plan-table.editing input.plan-edit[type="text"] { display: block; width: 100%; }
#pha-plan-table.editing td.site-row input.plan-edit[type="text"] { display: inline-block; width: 110px; }
#pha-plan-table.editing span.radio-btn-group.plan-edit { display: flex; }
#pha-plan-table.editing .radio-cell-label.plan-edit { display: block; }

/* Medication / IV / 서명 */
.med-counsel { margin-top: 2px; }
.iv-order {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 4px 2px;
}
.iv-desc { flex: 1; font-size: .88rem; color: var(--text-2); }
.iv-choice { display: inline-flex; padding: 3px; gap: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.iv-choice label {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 28px; margin: 0;
  border-radius: 6px;
  font-weight: 700; font-size: .84rem; color: var(--muted);
  cursor: pointer;
}
.iv-choice label input { position: absolute; opacity: 0; pointer-events: none; }
.iv-choice label:has(input:checked) { background: var(--primary); color: #fff; }
.iv-choice label:has(input:disabled:checked) { background: var(--blue-400); }

.signature-block {
  display: flex; justify-content: flex-end;
  margin: 8px 0 4px;
}
.signature-block label { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text-2); }
.signature-block input {
  width: 200px !important;
  border: none !important;
  border-bottom: 2px solid var(--border-strong) !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  font-weight: 600;
}
.signature-block input:focus { border-bottom-color: var(--primary) !important; }

.form-panel .button-group,
.emr-card .button-group {
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.form-panel .button-group button,
.emr-card .button-group .button { min-width: 112px; height: 44px; font-size: .95rem; }

.error-message { display: block; margin-top: 6px; color: var(--danger); font-size: .82rem; }

.checkbox-sign-label {
  display: inline-flex; align-items: center; gap: 8px;
  height: var(--control-h); padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.checkbox-sign-label:has(input:checked) { background: var(--blue-50); border-color: var(--primary); color: var(--blue-700); }

/* 신환 차트 */
.ne-table td { padding: 10px 12px; text-align: left; border-left: 1px solid var(--border); }
.ne-table td:first-child { border-left: none; width: 30%; }
.ne-table label { display: inline-flex !important; align-items: center; gap: 8px; margin: 0 !important; font-size: .9rem !important; }
.ne-table input[type="text"] { display: inline-block; width: 72px !important; min-height: 32px; margin: 0 4px; text-align: center; }
.page-narrow { max-width: 920px; margin: 0 auto; }

/* 간호 기록 표 */
.recent-panel { min-width: 0; }
.recent-panel .table-wrap { max-height: calc(100vh - 220px); overflow: auto; border-radius: var(--radius); }
.recent-panel table { font-size: .84rem; }
.recent-panel td { padding: 7px 10px; }
.recent-panel td:last-child { text-align: left; }

/* ---------- 13. Slide sidebars ---------- */
#today-sidebar {
  position: fixed;
  top: 50%;
  left: -260px;
  transform: translateY(-50%);
  z-index: 900;
  display: flex;
  align-items: flex-start;
  transition: left .3s cubic-bezier(.4, 0, .2, 1);
}
#today-sidebar.open { left: 0; }
#today-sidebar-content {
  width: 260px;
  max-height: 72vh;
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 0 var(--radius) 0;
  box-shadow: var(--shadow-lg);
}
#today-sidebar-content h3 { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); font-size: .95rem; font-weight: 700; }
#sidebar-patient-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
}
#sidebar-patient-list li:last-child { border-bottom: none; }
.sidebar-seq { min-width: 22px; color: var(--faint); font-weight: 700; font-variant-numeric: tabular-nums; }
.sidebar-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-status { padding: 2px 8px; border-radius: 999px; background: var(--blue-50); color: var(--blue-700); font-size: .74rem; font-weight: 700; white-space: nowrap; }

#today-sidebar-tab,
#drug-sidebar-tab {
  flex-shrink: 0;
  width: 40px;
  height: auto;
  padding: 14px 0;
  border: none;
  background: var(--blue-800);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: pre-line;
  text-align: center;
  box-shadow: var(--shadow-md);
  writing-mode: horizontal-tb;
  display: block;
}
#today-sidebar-tab { border-radius: 0 10px 10px 0; }
#drug-sidebar-tab { border-radius: 10px 0 0 10px; background: var(--blue-600); width: 44px; }
#today-sidebar-tab:hover { background: var(--blue-900); color: #fff; border: none; }
#drug-sidebar-tab:hover { background: var(--blue-700); color: #fff; border: none; }

#drug-sidebar {
  position: fixed;
  top: 50%;
  right: -85vw;
  transform: translateY(-50%);
  z-index: 900;
  display: flex;
  align-items: flex-start;
  transition: right .3s cubic-bezier(.4, 0, .2, 1);
}
#drug-sidebar.open { right: 0; }
#drug-sidebar-content {
  width: 85vw;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 0 0 0 var(--radius);
  box-shadow: var(--shadow-lg);
}
#drug-sidebar-header {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#drug-sidebar-header h3 { font-size: 1rem; font-weight: 700; white-space: nowrap; }
#drug-search { max-width: 360px; border-radius: 999px; padding-left: 16px; }
#drug-table-wrap { flex: 1; overflow: auto; }
#drug-table { min-width: 960px; font-size: .8rem; border-collapse: separate; }
#drug-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--blue-50);
  color: var(--blue-800);
  text-align: left;
  border-bottom: 1px solid var(--blue-200);
}
#drug-table td { padding: 8px 10px; text-align: left; vertical-align: top; line-height: 1.5; }
#drug-table tbody tr:nth-child(even) td { background: var(--surface-2); }
#drug-table tbody tr:hover td { background: var(--blue-50); }
#drug-table td:nth-child(1), #drug-table td:nth-child(2) { white-space: nowrap; font-weight: 600; color: var(--blue-700); min-width: 60px; }
#drug-table td:nth-child(3) { white-space: nowrap; font-weight: 700; color: var(--text); min-width: 80px; }
#drug-table td:nth-child(4) { min-width: 120px; max-width: 160px; }
#drug-table td:nth-child(5) { min-width: 140px; max-width: 180px; }
#drug-table td:nth-child(6) { min-width: 100px; max-width: 140px; color: var(--blue-800); font-weight: 600; }
#drug-table td:nth-child(7), #drug-table td:nth-child(8), #drug-table td:nth-child(9) { min-width: 130px; max-width: 200px; }
#drug-table td:nth-child(8) { color: var(--danger); font-weight: 600; }
#drug-table tr.category-start td { border-top: 2px solid var(--blue-200); }
#drug-table tr.drug-hidden { display: none; }

/* ---------- 14. Responsive ---------- */
@media (max-width: 1280px) {
  .status-container { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-box { min-height: 220px; }
  .emr-layout { grid-template-columns: 180px minmax(0, 1fr); }
  .emr-layout > #past-panel,
  .emr-layout > .recent-panel { grid-column: 2; }
}
@media (max-width: 1024px) {
  .dashboard-container { grid-template-columns: 1fr; }
  .patient-table-scroll, .status-box { max-height: none; }
}
@media (max-width: 768px) {
  .container { padding: 0 14px 40px; }
  .app-bar-inner { padding: 0 14px; }
  .app-brand .brand-sub, .app-date { display: none; }
  .emr-layout, .emr-layout.two-col { grid-template-columns: 1fr; }
  .emr-layout > #past-panel, .emr-layout > .recent-panel { grid-column: auto; }
  .visits-panel { position: static; }
  .status-container { grid-template-columns: 1fr; }
  .form-panel .vitals-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-panel .header-group { grid-template-columns: auto 1fr; }
  .form-panel .no-wrap { flex-wrap: wrap; }
  .form-panel .no-wrap .inline-item { flex: 1 1 140px; }
  .patient-header .back-button { margin-left: 0; }
}
