:root { --red: #c62828; --red-d: #8e0000; --ok: #2e7d32; --ink: #1d2733; --muted: #66727f; --line: #d9dee4; --bg: #f3f5f8; --card: #fff; color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid #c3cad3; border-radius: 8px; background: #fff; }
label { display: block; font-size: 14px; color: var(--muted); }
label > input, label > select { margin-top: 4px; color: var(--ink); font-size: 16px; }
h3 { margin: 18px 0 8px; }
.muted { color: var(--muted); }
.err { color: var(--red); margin-top: 8px; min-height: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.btn { padding: 10px 14px; border: 1px solid #b9c2cc; border-radius: 8px; background: #fff; cursor: pointer; font-weight: 600; }
.btn.sm { padding: 5px 9px; font-size: 13px; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; margin-top: 10px; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.nowrap { white-space: nowrap; }
.help { font-size: 14px; margin-top: 12px; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #b71c1c, #4a0000); }
.login form { width: min(380px, 100%); display: grid; gap: 12px; text-align: center; }
.login h1 { margin: 0; color: var(--red); }
.login .logo { font-size: 48px; }
.login label { text-align: left; }

#bar { position: sticky; top: 0; z-index: 5; }
#bar header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 14px 8px; background: var(--red-d); color: #fff; }
#bar header small { display: block; opacity: .85; font-size: 13px; }
#bar header .conn { font-size: 12.5px; color: #b9f6ca; text-align: right; }
#bar header.off .conn { color: #ffd54f; }
.banner { display: block; width: 100%; padding: 12px; border: 0; background: #e3f2fd; color: #0d47a1; font-weight: 600; cursor: pointer; }
.banner.warn { background: #fff3cd; color: #7a4f00; }
main { max-width: 900px; margin: 0 auto; padding: 12px 14px; }

nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav a { flex: 1; text-align: center; padding: 14px 4px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14.5px; }
nav a.on { color: var(--red); box-shadow: inset 0 3px 0 var(--red); }

.call { display: grid; gap: 10px; margin: 6px 0 16px; }
.call .from { font-size: 16px; color: var(--ink); }
.sos { display: grid; place-items: center; gap: 4px; width: min(78vw, 300px); aspect-ratio: 1; margin: 10px auto; border: 0; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ff5252, #b71c1c 60%, #7f0000); color: #fff; font-size: 64px; cursor: pointer; box-shadow: 0 0 0 10px #ffcdd2, 0 10px 30px rgb(183 28 28 / .45); touch-action: manipulation; }
.sos span { font-size: 20px; font-weight: 800; letter-spacing: .03em; }
.sos:active { transform: scale(.97); }
.call.small .sos { width: 150px; font-size: 34px; }
.call.small .sos span { font-size: 13px; }
.modal .sos { width: 200px; font-size: 44px; }

.alert { background: #fff; border: 1px solid var(--line); border-left: 8px solid #999; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.alert.lv1 { border-left-color: var(--red); }
.alert.lv2 { border-left-color: #ef6c00; }
.alert.lv3 { border-left-color: #f9a825; }
.alert.open { box-shadow: 0 0 0 2px rgb(198 40 40 / .25); }
.alert-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; }
.alert .lvl { color: var(--red); font-weight: 800; }
.alert h2 { margin: 4px 0; font-size: 26px; }
.alert .loc { font-size: 17px; }
.alert .reason { font-weight: 600; color: #6d1b1b; }
.alert .by { color: var(--muted); font-size: 14px; margin: 4px 0; }
.acks ul { margin: 6px 0; padding-left: 0; list-style: none; }
.acks li { padding: 2px 0; }
.k { display: inline-block; min-width: 82px; padding: 1px 6px; border-radius: 4px; font-size: 12.5px; font-weight: 700; background: #e8f5e9; color: var(--ok); }
.k.coming { background: #fff3e0; color: #e65100; }
.k.arrived { background: #e3f2fd; color: #1565c0; }
.wait { color: #e65100; }
.closed { margin-top: 6px; color: var(--muted); font-size: 14px; }
.alert .row { margin-top: 8px; }
.alert .btn.big { width: auto; flex: 1 1 100%; margin: 0; }
.hot { color: var(--red); }
.calm { text-align: center; padding: 30px 10px; color: var(--ok); font-size: 22px; font-weight: 700; }
.calm small { color: var(--muted); font-size: 14px; font-weight: 400; }
.big-ok { font-size: 60px; }
.clock { margin-top: 10px; font-size: 44px; color: var(--ink); font-variant-numeric: tabular-nums; }

#alarm { position: fixed; inset: 0; z-index: 50; overflow: auto; background: var(--red); color: #fff; animation: flash 1s steps(2, start) infinite; }
@keyframes flash { 50% { background: #5d0000; } }
.alarm-in { min-height: 100%; display: grid; align-content: center; gap: 18px; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); text-align: center; }
.alarm-item { display: grid; gap: 10px; justify-items: center; padding: 18px; border: 3px solid #fff; border-radius: 16px; background: rgb(0 0 0 / .18); }
.alarm-item .lvl { font-size: clamp(26px, 6vw, 56px); font-weight: 900; letter-spacing: .05em; }
.alarm-item .dept { font-size: clamp(34px, 9vw, 96px); font-weight: 900; line-height: 1.05; }
.alarm-item .loc { font-size: clamp(18px, 3.5vw, 34px); font-weight: 700; }
.alarm-item .who { font-size: clamp(15px, 2.5vw, 22px); }
.btn.huge { width: min(100%, 520px); padding: 22px; font-size: clamp(24px, 5vw, 40px); border: 3px solid #fff; border-radius: 14px; }
.alarm-item .btn.ghost { color: #fff; border-color: rgb(255 255 255 / .6); }
.nosound { font-weight: 700; background: #fff3cd; color: #7a4f00; padding: 10px; border-radius: 8px; }
@media (prefers-reduced-motion: reduce) { #alarm { animation: none; } }

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgb(0 0 0 / .5); }
.modal .card { width: min(460px, 100%); max-height: 100%; overflow: auto; text-align: center; }
.modal h2 { margin: 0 0 6px; color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 10px 0; }
.chip { padding: 8px 10px; border: 1px solid #c3cad3; border-radius: 999px; background: #fff; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }
.modal input { margin: 8px 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; align-items: end; }
.grid1 { display: grid; gap: 8px; margin: 10px 0; }
.table { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f7f8fa; }
tr.off td { opacity: .5; }
.filters label { display: flex; align-items: center; gap: 6px; }
.filters input { width: auto; }
textarea { margin-bottom: 8px; }
#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; max-width: 90vw; padding: 12px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 6px 20px rgb(0 0 0 / .3); }
#toast.bad { background: var(--red); }
@media (min-width: 900px) { .alert h2 { font-size: 32px; } }
.modal .card.wide { width: min(720px, 100%); text-align: left; }
.btn.sm.primary { background: var(--ink); color: #fff; }
td select { padding: 5px 8px; font-size: 14px; }
.center { text-align: center; margin: 0; }
.plain { list-style: none; padding: 0; text-align: left; font-size: 17px; }
.called h2 { color: var(--ink); }
.matrix th, .matrix td { text-align: center; white-space: nowrap; }
.matrix td:nth-child(2) { text-align: left; }
.matrix th { font-size: 12.5px; white-space: normal; min-width: 70px; }
.matrix td.yes { color: var(--ok); font-weight: 800; font-size: 17px; }
.matrix td.yes small { display: block; font-size: 10.5px; font-weight: 400; color: var(--muted); }
.matrix td.no { color: #fff; background: var(--red); font-weight: 800; font-size: 17px; }
.matrix td.self { color: var(--muted); font-size: 12px; background: #f1f3f5; }
.matrix td.na { color: #b0b8c1; }
.ok-t { color: var(--ok); }
.print-only { display: none; }
@media print {
  #bar, nav, .no-print, #toast { display: none !important; }
  .print-only { display: block; }
  body { padding: 0; background: #fff; }
  main { max-width: none; }
  .matrix td.no { background: none; color: #c62828; }
}
.note { font-weight: 600; }
.alarm-item .dept .note { display: inline; font-size: .55em; font-weight: 700; }
.recv { font-size: 16px; }
.recv ul { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.recv li { padding: 4px 10px; border-radius: 999px; background: #e8f5e9; color: var(--ok); font-weight: 700; }
.recv li small { font-weight: 400; color: var(--muted); }
.recv.none { color: #e65100; font-weight: 700; }
.alarm-item .recv { font-size: clamp(16px, 2.4vw, 24px); }
.alarm-item .recv ul { justify-content: center; }
.alarm-item .recv li { background: #fff; }
.alarm-item .recv.none { color: #ffe0b2; }
.called .row input { margin: 0; }
.tap-hint { font-size: clamp(14px, 2vw, 18px); opacity: .85; }
#alarm { cursor: pointer; }
.mycall { display: grid; gap: 10px; margin: 0 0 16px; padding: 14px; background: #fff; border: 2px solid var(--red); border-radius: 12px; }
.mycall-head { font-size: 19px; font-weight: 800; }
.mycall-head small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
.note-form input { flex: 1; margin: 0; }
.card.pick { margin-bottom: 14px; border: 2px solid #f9a825; }
.shared-box { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
/* Nút gọi luôn nằm giữa phần màn hình còn lại (điện thoại: không bị đẩy xuống dưới) */
.banner { padding: 7px 10px; font-size: 14px; }
.banner-row { display: flex; }
.banner-row .banner:first-child { flex: 1; }
.banner.x { width: auto; padding: 7px 14px; }
.call:not(.small) { min-height: calc(100dvh - 190px - env(safe-area-inset-bottom)); align-content: center; margin: 0; }
.call:not(.small) .sos { width: min(72vw, 46dvh, 300px); }
.call .from { text-align: center; }
