:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #172033;
  --muted: #667085;
  --line: #d7dde8;
  --accent: #0b7fab;
  --accent-2: #0f9f7a;
  --danger: #c93c4a;
  --warn: #b7791f;
  --shadow: 0 10px 30px rgba(18, 31, 53, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; }
p { color: var(--muted); line-height: 1.5; }
h1, h2, h3 { margin: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input, textarea, select {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
}
textarea { min-height: 98px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11,127,171,.12); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.logo { width: 48px; height: 48px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; display: grid; place-items: center; font-weight: 900; }
.brand-logo {
  width: 112px;
  height: 70px;
  object-fit: contain;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}
.sidebar-logo {
  width: 124px;
  height: 78px;
}
.brand h1 { font-size: 24px; }

.app-shell { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar { background: #172033; color: #fff; padding: 22px; position: sticky; top: 0; height: 100vh; }
.sidebar p, .sidebar .muted { color: #aeb8ca; }
.user-box { margin: 22px 0; padding: 14px; border-radius: 8px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1); }
.user-box strong { display: block; }
.user-box span { color: #c4ccda; font-size: 13px; }
.nav { display: grid; gap: 8px; }
.nav button { text-align: left; background: transparent; color: #c4ccda; padding: 11px 12px; border-radius: 8px; }
.nav button.active, .nav button:hover { color: #fff; background: rgba(255,255,255,.12); }
.sidebar-credit { margin-top: 22px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.1); color: #8b95a7; font-size: 12px; }

.content { padding: 28px; max-width: 1440px; width: 100%; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.topbar h2 { font-size: 28px; }
.topbar p { margin: 6px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  background: var(--accent);
  color: #fff;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 700;
  border: 1px solid transparent;
}
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.danger { background: #fff3f4; color: var(--danger); border-color: #f0b9bf; }
.btn.ok { background: #eefbf6; color: #08765a; border-color: #b9e8d9; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: var(--shadow); }
.stat strong { display: block; font-size: 32px; }
.stat span, .muted { color: var(--muted); }

.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:hover td { background: #fbfcfe; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; border: 1px solid var(--line); background: #f5f7fb; color: var(--text); margin-right: 6px; }
.badge.red { background: #fff0f1; color: #9f2a35; border-color: #f1b8bf; }
.badge.orange { background: #fff4ec; color: #9a4a11; border-color: #f3c4a4; }
.badge.yellow { background: #fff8df; color: #846000; border-color: #ebd483; }
.badge.green { background: #ecfdf4; color: #087246; border-color: #a8dfc2; }
.badge.blue { background: #edf7ff; color: #0b5f8c; border-color: #a6d5f2; }
.badge.black { background: #202536; color: #fff; border-color: #202536; }

.error, .success { margin-bottom: 14px; padding: 10px 12px; border-radius: 8px; }
.error { color: #9f2a35; background: #fff0f1; border: 1px solid #f1b8bf; }
.success { color: #087246; background: #ecfdf4; border: 1px solid #a8dfc2; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(13, 21, 36, .55); display: grid; place-items: center; padding: 24px; z-index: 20; }
.modal { width: min(820px, 100%); max-height: 92vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 22px; box-shadow: 0 24px 70px rgba(10,20,35,.25); }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.profile-head { display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; }
.record-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: var(--surface-2); margin-bottom: 12px; }
.record-card p { margin: 8px 0; }
.record-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px; margin: 8px 0; }
.kv.mini { grid-template-columns: 1fr; gap: 2px; padding: 8px 0; }
.kv span:first-child { color: var(--muted); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.document-a4 { position: relative; background: white; color: #111; width: min(840px, 100%); margin: 0 auto; padding: 46px; border-radius: 8px; box-shadow: var(--shadow); }
.document-a4 h1 { text-align: center; margin-bottom: 28px; font-size: 24px; }
.document-a4 p, .document-a4 .muted { color: #333; }
.doc-brand { display: flex; align-items: center; gap: 14px; border-bottom: 2px solid #111; padding-bottom: 12px; margin-bottom: 20px; }
.doc-brand img { width: 90px; height: 56px; object-fit: contain; }
.doc-brand strong { display: block; }
.doc-brand span { color: #555; font-size: 13px; }
.doc-watermark { position: absolute; top: 44%; left: 50%; transform: translate(-50%, -50%) rotate(-24deg); font-size: 84px; font-weight: 900; color: rgba(201, 60, 74, .16); letter-spacing: 6px; pointer-events: none; white-space: nowrap; }
.doc-line { display: grid; grid-template-columns: 190px 1fr; gap: 8px; padding: 7px 0; border-bottom: 1px solid #ddd; }
.doc-content { white-space: pre-wrap; line-height: 1.6; color: #111; padding: 6px 0; }
.doc-sign { margin-top: 70px; display: flex; justify-content: flex-end; }
.doc-sign div { width: 260px; text-align: center; border-top: 1px solid #111; padding-top: 8px; }
.doc-stamp { display: block; max-width: 220px; max-height: 110px; margin: 0 auto 6px; }
.stamp-preview { display: block; max-width: 260px; max-height: 150px; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px; }

.sor-section-header {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 4px;
  margin-bottom: 10px;
}

.btn.sor-paramedic { background: #0b5f8c; color: #fff; }
.btn.sor-nurse { background: #0f9f7a; color: #fff; }

.activation-code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 30px; font-weight: 800; letter-spacing: 6px; text-align: center; padding: 16px; margin: 12px 0; background: var(--surface-2); border: 2px dashed var(--accent); border-radius: 10px; color: var(--accent); user-select: all; }
.info-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 14px 0 0; }
.reset-pass { display: flex; align-items: center; gap: 8px; margin-top: 16px; }

.form-divider { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 13px; margin: 18px 0 6px; }
.form-divider::before, .form-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); margin: 0 10px; }
.clinic-search-results { margin-top: 8px; display: grid; gap: 6px; }
.clinic-search-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }

.sample-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.sample-field label { display: flex; align-items: center; gap: 8px; margin-top: 0; }
.sample-letter { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 5px; background: var(--accent); color: #fff; font-weight: 800; font-size: 12px; flex: none; }

.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.board-card { background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--line); border-radius: 8px; padding: 16px; box-shadow: var(--shadow); }
.board-card h3 { margin: 10px 0 2px; }
.board-card p { margin: 6px 0; }
.board-card-top { display: flex; align-items: center; justify-content: space-between; }
.board-wait { font-size: 13px; color: var(--muted); font-weight: 700; }
.board-status { font-weight: 700; color: var(--text); }
.board-card.triage-red { border-left-color: #c93c4a; }
.board-card.triage-orange { border-left-color: #d3791f; }
.board-card.triage-yellow { border-left-color: #c9a400; }
.board-card.triage-green { border-left-color: #0f9f7a; }
.board-card.triage-blue { border-left-color: #0b7fab; }
.board-card.triage-black { border-left-color: #202536; }
.board-card.overdue { box-shadow: 0 0 0 2px #c93c4a inset, var(--shadow); }
.board-wait.over { color: #c93c4a; }
.board-overdue { color: #c93c4a; font-weight: 800; font-size: 12px; margin-top: 6px; }

.triage-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.legend-item { font-size: 12px; padding: 6px 10px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); border-left-width: 5px; }
.legend-item.triage-red { border-left-color: #c93c4a; }
.legend-item.triage-orange { border-left-color: #d3791f; }
.legend-item.triage-yellow { border-left-color: #c9a400; }
.legend-item.triage-green { border-left-color: #0f9f7a; }
.legend-item.triage-blue { border-left-color: #0b7fab; }
.legend-item.triage-black { border-left-color: #202536; }

.board-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.board-filters label { margin-top: 0; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .topbar { display: block; }
  .actions { justify-content: flex-start; margin-top: 12px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .profile-head { grid-template-columns: 1fr; }
  .form-row, .form-row.three, .form-row.four { grid-template-columns: 1fr; }
  .board-filters, .sample-grid { grid-template-columns: 1fr; }
  .content { padding: 18px; }
}

@page { margin: 14mm; }

@media print {
  body { background: white; }
  .sidebar, .topbar, .no-print { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; max-width: none; }
  .document-a4 { box-shadow: none; width: 100%; border-radius: 0; padding: 0; }
  .doc-watermark { color: rgba(201, 60, 74, .22); }
}
