/* ===== Design tokens ===== */
:root {
  --bg: #f4f7f8;
  --bg-panel: #ffffff;
  --bg-sidebar: #0d3b3a;
  --bg-sidebar-active: #12504e;
  --border: #e2e8ec;
  --text: #16232b;
  --text-muted: #5b6b74;
  --text-inverse: #eef7f6;

  --primary: #0f766e;
  --primary-dark: #0b5f58;
  --primary-soft: #e3f4f1;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 40, 40, 0.06);
  --shadow-md: 0 6px 20px rgba(16, 40, 40, 0.10);

  /* Stage colors — mục 6 spec */
  --stage-cho_tiep_nhan: #64748b;      /* xám */
  --stage-cho_tiep_nhan-bg: #f1f5f9;
  --stage-cho_mo: #b45309;             /* hổ phách */
  --stage-cho_mo-bg: #fef3c7;
  --stage-dang_mo: #1d4ed8;            /* xanh dương */
  --stage-dang_mo-bg: #dbeafe;
  --stage-hoi_tinh: #7e22ce;           /* tím */
  --stage-hoi_tinh-bg: #f3e8ff;
  --stage-chuyen_trai: #15803d;        /* xanh lá */
  --stage-chuyen_trai-bg: #dcfce7;
  --stage-hoan_mo: #b91c1c;            /* đỏ nhạt */
  --stage-hoan_mo-bg: #fee2e2;

}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
button { font-family: inherit; cursor: pointer; }

/* ===== Login screen ===== */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0d3b3a, #0b2530);
  padding: 20px;
}
.login-card {
  background: var(--bg-panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  padding: 32px 28px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px;
}
.login-brand-mark { align-self: center; margin-bottom: 4px; }
.login-title { margin: 0; font-size: 19px; text-align: center; color: var(--text); }
.login-sub { margin: 0 0 10px; font-size: 12px; text-align: center; color: var(--text-muted); }
.login-field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.login-field input {
  padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  font-size: 13.5px; color: var(--text); font-family: inherit;
}
.login-field input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.login-submit {
  margin-top: 6px; padding: 10px; border-radius: var(--radius-sm); border: none;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 13.5px;
}
.login-submit:hover { background: var(--primary-dark); }
.login-error { font-size: 12px; color: var(--stage-hoan_mo); text-align: center; }

/* ===== App shell ===== */
.app-shell {
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 12px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #0f766e, #0891b2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
}
.brand-title { font-weight: 700; font-size: 14px; }
.brand-sub { font-size: 11.5px; color: #9fc3bf; }

.nav { display: flex; flex-direction: column; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: transparent; border: none; color: #cfe7e3;
  font-size: 13.2px; font-weight: 500; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--bg-sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #34d1c0; }
.nav-item[hidden] { display: none; }
.nav-ico { width: 16px; height: 16px; flex: 0 0 auto; display: inline-block; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.12); padding-top: 12px; }
.stage-legend { display: flex; flex-direction: column; gap: 6px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: #b9d6d1; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.dot-cho_tiep_nhan { background: var(--stage-cho_tiep_nhan); }
.dot-cho_mo { background: var(--stage-cho_mo); }
.dot-dang_mo { background: var(--stage-dang_mo); }
.dot-hoi_tinh { background: var(--stage-hoi_tinh); }
.dot-chuyen_trai { background: var(--stage-chuyen_trai); }
.dot-hoan_mo { background: var(--stage-hoan_mo); }

/* ===== Main column ===== */
.main-col { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 60px; flex: 0 0 auto;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
}
.topbar-left { display: flex; align-items: baseline; gap: 14px; }
.surgery-date { font-weight: 700; font-size: 15px; color: var(--text); }
.live-clock { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 13px; }

.topbar-right { display: flex; align-items: center; gap: 16px; }
.quick-counts { display: flex; gap: 6px; }
.qc {
  min-width: 26px; height: 24px; padding: 0 7px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11.5px; font-weight: 700; color: #fff;
}
.qc[data-stage="cho_tiep_nhan"] { background: var(--stage-cho_tiep_nhan); }
.qc[data-stage="cho_mo"] { background: var(--stage-cho_mo); }
.qc[data-stage="dang_mo"] { background: var(--stage-dang_mo); }
.qc[data-stage="hoi_tinh"] { background: var(--stage-hoi_tinh); }
.qc[data-stage="chuyen_trai"] { background: var(--stage-chuyen_trai); }
.qc[data-stage="hoan_mo"] { background: var(--stage-hoan_mo); }

.user-chip { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-size: 12.5px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-muted); }
.logout-btn {
  border: none; background: transparent; color: var(--text-muted); font-size: 15px;
  padding: 2px 4px; border-radius: var(--radius-sm); line-height: 1;
}
.logout-btn:hover { color: var(--stage-hoan_mo); background: var(--stage-hoan_mo-bg); }

.view-area { flex: 1; overflow: auto; padding: 20px; }

.view-placeholder {
  background: var(--bg-panel); border: 1px dashed var(--border); border-radius: var(--radius-lg);
  padding: 48px 24px; text-align: center; color: var(--text-muted);
}
.view-placeholder h2 { color: var(--text); margin: 0 0 6px; font-size: 18px; }
.view-placeholder p { margin: 0; font-size: 13px; }
.phase-tag {
  display: inline-block; margin-top: 14px; padding: 4px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark); font-size: 11.5px; font-weight: 600;
}

/* ===== Reusable: filter pills (tham khảo OR dashboard) ===== */
.pill-group { display: flex; gap: 8px; flex-wrap: wrap; }
.pill-btn {
  padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-panel); color: var(--text-muted);
  font-size: 12.5px; font-weight: 600;
}
.pill-btn:hover { border-color: var(--primary); color: var(--primary-dark); }
.pill-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== Reusable: stat card (số lớn + subtitle mờ) ===== */
.stat-card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
}
.stat-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.stat-card-label { font-size: 12px; font-weight: 700; color: var(--text); }
.stat-card-value { font-size: 20px; font-weight: 800; }
.stat-card-value.positive { color: #15803d; }
.stat-card-value.warn { color: var(--stage-hoan_mo); }
.stat-card-sub { font-size: 11.5px; color: var(--text-muted); }
.stat-card-link { font-size: 11px; font-weight: 700; color: var(--primary); background: var(--primary-soft); padding: 2px 8px; border-radius: 999px; }

/* ===== Module 1 — form + list ===== */
.lm-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; align-items: start; }
.lm-form-card, .lm-list-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-field { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); }
.form-field-wide { grid-column: 1 / -1; }
.form-field input {
  padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  font-size: 13px; color: var(--text); font-family: inherit;
}
.form-field input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-field input[readonly] { background: var(--bg); color: var(--text-muted); }
.case-submit { width: 100%; margin-top: 14px; }

.lm-list-head { font-size: 12.5px; font-weight: 700; color: var(--text); margin-bottom: 10px; }
.lm-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.lm-table th { text-align: left; font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.lm-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); color: var(--text); }
.lm-empty { text-align: center; color: var(--text-muted); padding: 16px 0; }

.room-assign {
  margin-top: 8px; width: 100%; padding: 5px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); font-size: 11px; color: var(--text); font-family: inherit; background: var(--bg-panel);
}

@media (max-width: 900px) {
  .lm-grid { grid-template-columns: 1fr; }
}

/* ===== Module 2 — header, segmented toggle, filter bar ===== */
.pm-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.pm-title { margin: 0 0 2px; font-size: 18px; color: var(--text); }
.pm-desc { margin: 0; font-size: 12.5px; color: var(--text-muted); }

.segmented { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 3px; flex: 0 0 auto; }
.segmented-btn { padding: 6px 16px; border-radius: 999px; border: none; background: transparent; color: var(--text-muted); font-size: 12.5px; font-weight: 700; }
.segmented-btn.active { background: var(--primary); color: #fff; }

.stat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }

.pm-filterbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.value-chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.value-chip {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-panel); color: var(--text-muted); font-size: 11.5px; font-weight: 600;
}
.value-chip:hover { border-color: var(--primary); color: var(--primary-dark); }
.value-chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }

/* ===== Module 2 — Kanban board (theo phòng) ===== */
.kanban-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.kanban-col { flex: 0 0 260px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); display: flex; flex-direction: column; max-height: 70vh; }
.kanban-col-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.kanban-col-title { font-size: 12.5px; font-weight: 800; color: var(--text); }
.kanban-col-count { font-size: 10.5px; color: var(--text-muted); white-space: nowrap; }
.kanban-col-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.kanban-empty { text-align: center; padding: 18px 0; color: var(--text-muted); font-size: 11.5px; border: 1px dashed var(--border); border-radius: var(--radius-sm); }

.kanban-col.stage-col { border-top: 3px solid transparent; }
.kanban-col.stage-col.stage-cho_tiep_nhan { border-top-color: var(--stage-cho_tiep_nhan); }
.kanban-col.stage-col.stage-cho_mo { border-top-color: var(--stage-cho_mo); }
.kanban-col.stage-col.stage-dang_mo { border-top-color: var(--stage-dang_mo); }
.kanban-col.stage-col.stage-hoi_tinh { border-top-color: var(--stage-hoi_tinh); }
.kanban-col.stage-col.stage-chuyen_trai { border-top-color: var(--stage-chuyen_trai); }
.kanban-col.stage-col.stage-hoan_mo { border-top-color: var(--stage-hoan_mo); }

.case-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; box-shadow: var(--shadow-sm); }
.case-card-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 4px; }
.case-stage { display: inline-flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; }
.case-warn { font-size: 12px; }
.case-patient { font-size: 13px; font-weight: 700; color: var(--text); }
.case-age { font-weight: 500; color: var(--text-muted); }
.case-diag { font-size: 11.5px; color: var(--text-muted); margin: 3px 0 6px; line-height: 1.35; }
.case-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.case-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.case-tag { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark); }
.case-tag-note { background: #fef3c7; color: #92400e; font-weight: 600; }

/* ===== Module 2 — Timeline board (Gantt theo phòng, trục giờ 7h-19h) ===== */
.timeline-board { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; overflow-x: auto; }
.tlb-ruler { display: grid; grid-template-columns: 90px 1fr; padding-bottom: 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; min-width: 720px; }
.tlb-ruler-hours { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); font-weight: 700; }
.tlb-row { display: grid; grid-template-columns: 90px 1fr; align-items: center; min-height: 34px; min-width: 720px; }
.tlb-row-label { font-size: 11.5px; font-weight: 700; color: var(--text); }
.tlb-row-track {
  position: relative; height: 24px; border-radius: 6px;
  background: repeating-linear-gradient(to right, var(--border) 0 1px, transparent 1px calc(100% / 12));
}
.tlb-row-empty { position: absolute; left: 6px; top: 3px; font-size: 11px; color: var(--text-muted); }
.tlb-block {
  position: absolute; top: 2px; height: 20px; border-radius: 5px; overflow: hidden;
  display: flex; align-items: center; padding: 0 6px; color: #fff;
}
.tlb-block-label { font-size: 10px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tlb-block.stage-cho_tiep_nhan { background: var(--stage-cho_tiep_nhan); }
.tlb-block.stage-cho_mo { background: var(--stage-cho_mo); }
.tlb-block.stage-dang_mo { background: var(--stage-dang_mo); }
.tlb-block.stage-hoi_tinh { background: var(--stage-hoi_tinh); }
.tlb-block.stage-chuyen_trai { background: var(--stage-chuyen_trai); }
.tlb-block.stage-hoan_mo { background: var(--stage-hoan_mo); }

/* ===== Modal (Module 3 — panel hanh trinh OTM) ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 25, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.modal-card {
  background: var(--bg-panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; padding: 22px;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.modal-title { margin: 0; font-size: 16px; color: var(--text); }
.modal-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.modal-close { border: none; background: var(--bg); color: var(--text-muted); border-radius: 50%; width: 28px; height: 28px; font-size: 15px; flex: 0 0 auto; }
.modal-close:hover { background: var(--stage-hoan_mo-bg); color: var(--stage-hoan_mo); }

.journey-status-row { display: flex; align-items: center; gap: 8px; margin: 12px 0 16px; }
.journey-status-row select {
  padding: 6px 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: 12.5px; font-family: inherit;
}

.cp-list { display: flex; flex-direction: column; gap: 0; border-top: 1px solid var(--border); }
.cp-row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--border); }
.cp-row.done .cp-label { color: var(--text); font-weight: 600; }
.cp-row.pending .cp-label { color: var(--text-muted); }
.cp-icon { width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.cp-row.done .cp-icon { background: var(--stage-chuyen_trai-bg); color: var(--stage-chuyen_trai); }
.cp-row.next .cp-icon { background: var(--stage-cho_mo-bg); color: var(--stage-cho_mo); }
.cp-row.pending .cp-icon { background: var(--bg); color: var(--text-muted); }
.cp-main { flex: 1; min-width: 0; }
.cp-label { font-size: 12.5px; }
.cp-meta { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; }
.cp-action-btn {
  padding: 6px 12px; border-radius: 999px; border: none; background: var(--primary); color: #fff;
  font-size: 11.5px; font-weight: 700; flex: 0 0 auto;
}
.cp-action-btn:hover { background: var(--primary-dark); }

.issues-field { margin-top: 16px; }
.issues-field textarea {
  width: 100%; min-height: 56px; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  font-size: 12.5px; font-family: inherit; resize: vertical;
}
.issues-save-btn { margin-top: 6px; padding: 6px 14px; border-radius: var(--radius-sm); border: none; background: var(--bg); color: var(--text); font-size: 11.5px; font-weight: 700; }
.issues-save-btn:hover { background: var(--primary-soft); color: var(--primary-dark); }

.checklist-items { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.checklist-item { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--text); }
.checklist-item input { margin-top: 2px; }
.checklist-confirm-btn {
  width: 100%; padding: 10px; border-radius: var(--radius-sm); border: none;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 13px;
}
.checklist-confirm-btn:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }

.jm-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; box-shadow: var(--shadow-sm); cursor: pointer; }
.jm-card:hover { border-color: var(--primary); }

/* ===== Toasts ===== */
.toast-host { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--text); color: #fff; padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 12.5px; box-shadow: var(--shadow-md); max-width: 320px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 236px; z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .topbar-left { gap: 8px; }
  .quick-counts { display: none; }
}
