:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --sky: #0284c7;
  --sky-600: #0284c7;
  --sky-700: #0369a1;
  --emerald: #059669;
  --rose: #e11d48;
  --amber: #d97706;
  --slate-900: #0f172a;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 8px 24px rgb(15 23 42 / 6%);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.mono { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; }

.page { min-height: 100vh; display: flex; flex-direction: column; }
.wrap { width: min(1280px, calc(100% - 32px)); margin: 0 auto; }

/* Header */
.header {
  position: sticky; top: 0; z-index: 40;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgb(15 23 42 / 4%);
}
.header-inner {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: #0f172a; color: #38bdf8;
  display: grid; place-items: center; font-weight: 800;
}
.brand h1 { margin: 0; font-size: 18px; }
.brand h1 span { color: var(--sky); }
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--muted); font-weight: 500; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  border: 0; background: #f1f5f9; color: #475569;
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; position: relative;
}
.icon-btn:hover { background: #e2e8f0; }
.badge-dot {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--rose); color: #fff; border-radius: 999px;
  font-size: 10px; font-weight: 800; display: grid; place-items: center;
  border: 2px solid #fff;
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); background: #f8fafc;
  border-radius: 10px; padding: 6px 10px 6px 6px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 8px;
  background: #0f172a; color: #38bdf8;
  display: grid; place-items: center; font-weight: 800; font-size: 11px;
}
.user-chip small { display: block; color: var(--muted); font-size: 10px; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 360px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; display: none;
}
.dropdown.open { display: block; }
.dropdown-head, .dropdown-foot {
  padding: 10px 14px; background: #f8fafc; border-bottom: 1px solid #f1f5f9;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; font-weight: 700;
}
.dropdown-foot { border-top: 1px solid #f1f5f9; border-bottom: 0; }
.notif-item {
  padding: 12px 14px; border-bottom: 1px solid #f1f5f9;
  cursor: pointer; display: flex; gap: 10px;
}
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #f0f9ff; }
.notif-item p { margin: 0; font-size: 12px; }
.notif-item .muted { color: var(--muted); margin-top: 4px; }

.main { flex: 1; padding: 24px 0 48px; }
.footer {
  border-top: 1px solid var(--line); background: #fff;
  padding: 20px 0; color: var(--muted); font-size: 12px;
}
.footer-inner { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.nav-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.nav-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 14px; font-weight: 700; font-size: 12px;
  background: #fff; color: #334155; border-color: var(--line);
}
.btn:hover { background: #f1f5f9; }
.btn-dark { background: #0f172a; color: #fff; border-color: #0f172a; }
.btn-primary { background: var(--sky); color: #fff; border-color: var(--sky); }
.btn-primary:hover { background: var(--sky-700); }
.btn-success { background: var(--emerald); color: #fff; border-color: var(--emerald); }
.btn-danger { background: var(--rose); color: #fff; border-color: var(--rose); }
.btn-ghost { background: #f1f5f9; }

.hero {
  background: #0f172a; color: #fff; border-radius: 12px;
  padding: 22px 24px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.hero .tag {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; background: #1e293b; color: #38bdf8;
  border: 1px solid #334155; padding: 3px 8px; border-radius: 6px;
}
.hero h2 { margin: 8px 0 6px; font-size: 22px; }
.hero p { margin: 0; color: #94a3b8; font-size: 12px; max-width: 640px; }
.kpi { display: flex; gap: 10px; }
.kpi div {
  min-width: 110px; text-align: center; background: #1e293b;
  border: 1px solid #334155; border-radius: 10px; padding: 8px 12px;
}
.kpi span { display: block; font-size: 10px; font-weight: 800; text-transform: uppercase; color: #38bdf8; }
.kpi strong { font-size: 22px; }

.grid-2 { display: grid; grid-template-columns: 5fr 7fr; gap: 20px; }
.grid-doctor { display: grid; grid-template-columns: 4fr 8fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
@media (max-width: 980px) {
  .grid-2, .grid-doctor, .grid-3, .grid-5 { grid-template-columns: 1fr; }
}

.card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 1px 2px rgb(15 23 42 / 4%);
}
.card.pad { padding: 16px; }
.card.selected { border-color: var(--sky); box-shadow: 0 0 0 3px rgb(14 165 233 / 18%); }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: #cbd5e1; }

.search {
  width: 100%; padding: 9px 12px 9px 34px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.search-wrap { position: relative; margin: 12px 0; }
.search-wrap svg, .search-wrap .search-ico {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: #94a3b8; font-size: 12px;
}

.seg { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg a, .seg button {
  flex: 1; border: 0; background: transparent; border-radius: 8px;
  padding: 10px 8px; font-weight: 800; font-size: 12px; color: #475569;
}
.seg .on { background: var(--sky); color: #fff; }
.seg .on-green { background: var(--emerald); color: #fff; }

.status {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid; border-radius: 6px; padding: 2px 8px; font-size: 10px; font-weight: 800;
}
.status-pending { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.status-work { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.status-done { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }
.status-rej { background: #ffe4e6; color: #9f1239; border-color: #fda4af; }
.badge-staff { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.badge-doctor { background: #f0f9ff; color: #0369a1; border: 1px solid #bae6fd; }
.badge-admin { background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: 10px; font-weight: 700; }

.list { display: flex; flex-direction: column; gap: 10px; max-height: 680px; overflow: auto; }
.list-card { padding: 14px; }
.list-card h4 { margin: 0 0 4px; font-size: 13px; }
.muted { color: var(--muted); font-size: 12px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }

.detail-head {
  background: #0f172a; color: #fff; padding: 16px 18px;
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.timeline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.tl { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; font-size: 12px; font-weight: 800; }
.tl.on { outline: 2px solid #38bdf8; background: #f0f9ff; }
.tl.done { outline: 2px solid #34d399; background: #ecfdf5; }

form.stack, .stack { display: flex; flex-direction: column; gap: 12px; }
label { font-size: 12px; font-weight: 800; color: #334155; display: block; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #f8fafc;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #7dd3fc; border-color: var(--sky); background: #fff; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .row-2 { grid-template-columns: 1fr; } }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 12px; font-weight: 700; margin-bottom: 12px; }
.alert-error { background: #fff1f2; color: #9f1239; border: 1px solid #fecdd3; }
.alert-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-info { background: #f0f9ff; color: #075985; border: 1px solid #bae6fd; }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; background: #f8fafc; color: #64748b; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; padding: 12px; border-bottom: 1px solid var(--line); }
td { padding: 12px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #f1f5f9; }
.login-card { width: min(440px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-brand { text-align: center; margin-bottom: 18px; }
.login-brand .logo { margin: 0 auto 10px; width: 48px; height: 48px; }

.modal {
  position: fixed; inset: 0; background: rgb(2 6 23 / 65%);
  display: none; place-items: center; padding: 16px; z-index: 80;
}
.modal.open { display: grid; }
.modal-card { background: #fff; width: min(720px, 100%); border-radius: 14px; overflow: hidden; max-height: 92vh; display: flex; flex-direction: column; }
.modal-head { background: #0f172a; color: #fff; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px; overflow: auto; }
.modal-actions { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #f8fafc; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: #f1f5f9; border-radius: 8px; padding: 7px 10px; font-size: 12px; font-weight: 800; }
.chip.on { background: var(--sky); color: #fff; border-color: var(--sky); }

.ecg-viewer { background: #020617; border-radius: 12px; overflow: hidden; border: 1px solid #1e293b; min-height: 420px; display: flex; flex-direction: column; }
.ecg-toolbar { display: flex; justify-content: space-between; gap: 8px; padding: 8px; background: #0f172a; color: #cbd5e1; }
.ecg-stage { flex: 1; overflow: hidden; display: grid; place-items: center; background: #020617; cursor: grab; min-height: 340px; position: relative; }
.ecg-stage img { max-height: 360px; transform-origin: center center; }
.ecg-foot { padding: 8px 10px; color: #94a3b8; font-size: 11px; border-top: 1px solid #1e293b; }

.protocol { padding: 24px; }
.urgency-critical { background: #ffe4e6; color: #9f1239; border: 1px solid #fda4af; }
.urgency-warn { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.urgency-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }
.urgency-ok { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }

.templates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 800px) { .templates { grid-template-columns: 1fr 1fr; } }
.tmpl { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.tmpl:hover { border-color: #7dd3fc; background: #f0f9ff; }
.tmpl strong { display: block; font-size: 12px; }
.tmpl span { font-size: 10px; color: var(--muted); }

.hidden { display: none !important; }
.rel { position: relative; }
.flash { margin-bottom: 16px; }

@media print {
  .header, .footer, .nav-row, .btn, .no-print, .modal-head, .modal-actions { display: none !important; }
  .modal { position: static; background: #fff; display: block; }
  .modal-card { box-shadow: none; max-height: none; width: 100%; }
}

.video-box { background: #000; min-height: 340px; display: grid; place-items: center; position: relative; }
.video-box video, .video-box img { width: 100%; max-height: 420px; object-fit: contain; }
.cam-overlay {
  position: absolute; inset: 32px; border: 2px dashed rgb(56 189 248 / 70%);
  border-radius: 12px; pointer-events: none; color: #7dd3fc; padding: 12px; font-size: 12px;
}
.role-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.role-pick button { padding: 12px 8px; }
.role-pick .on { background: #f0f9ff; border-color: var(--sky); color: #0c4a6e; }
