/* RadAlert — dark, high-contrast, built for a bright reading room and for
   gloved fingers on a scanner console tablet. All touch targets >= 56px. */

:root {
  --bg: #0b1017;
  --surface: #151c26;
  --surface-2: #1d2632;
  --line: #2a3644;
  --text: #eaf0f7;
  --muted: #93a2b5;
  --accent: #4da3ff;
  --urgent: #f5a524;
  --urgent-ink: #2a1c00;
  --emergent: #ff4d4f;
  --emergent-ink: #2a0000;
  --ok: #35c26a;
  --radius: 14px;
  --gap: 14px;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(77, 163, 255, 0.16);
}

.brand-name { font-weight: 650; letter-spacing: 0.2px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.conn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted);
}
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); transition: background 0.2s;
}
.conn[data-state="live"] .conn-dot { background: var(--ok); }
.conn[data-state="down"] .conn-dot { background: var(--emergent); }

/* -------------------------------------------------------------- layout */

main {
  flex: 1;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.view { display: block; }
.view[hidden] { display: none; }

.section-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 26px 0 10px;
  font-weight: 600;
}
.section-title:first-child { margin-top: 4px; }
.section-title.critical { color: var(--emergent); }

#study-groups .section-title:first-of-type { margin-top: 4px; }
.study-grid.critical .study-btn { border-color: rgba(255, 77, 79, 0.35); }

.muted { color: var(--muted); }
.empty { padding: 18px 4px; margin: 0; }

/* --------------------------------------------------------------- forms */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}

.login-card { max-width: 440px; margin: 24px auto; }
.card-title { margin: 0 0 6px; font-size: 22px; }
.login-card .muted { margin: 0 0 20px; font-size: 15px; }

.field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.field { display: block; margin-bottom: 18px; }

input[type="password"], input[type="text"] {
  width: 100%;
  min-height: 56px;
  padding: 0 14px;
  font-size: 18px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:focus-visible, button:focus-visible, .role-option:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.role-picker { margin-bottom: 20px; }
.role-options { display: grid; gap: 10px; }

.role-option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.role-option input { accent-color: var(--accent); width: 20px; height: 20px; flex: none; }
.role-option:has(input:checked) { border-color: var(--accent); background: rgba(77, 163, 255, 0.1); }
.role-body { display: flex; flex-direction: column; }
.role-title { font-weight: 600; }
.role-sub { font-size: 13px; color: var(--muted); }

.primary-btn {
  width: 100%;
  min-height: 56px;
  font-size: 17px;
  font-weight: 650;
  color: #05121f;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.primary-btn:active { transform: translateY(1px); }

.ghost-btn {
  min-height: 40px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.ghost-btn.wide { width: 100%; min-height: 52px; margin-top: 10px; }
.ghost-btn[data-on="true"] { border-color: var(--ok); color: var(--ok); }

.error {
  margin: 0 0 14px;
  padding: 10px 12px;
  font-size: 15px;
  color: #ffd7d7;
  background: rgba(255, 77, 79, 0.14);
  border: 1px solid rgba(255, 77, 79, 0.4);
  border-radius: 9px;
}

/* ---------------------------------------------------------- technician */

.scanner-row { margin-bottom: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 44px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  /* scanner names stay in English inside an RTL page */
  direction: ltr;
  unicode-bidi: isolate;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: rgba(77, 163, 255, 0.14); color: #cfe6ff; }

/* Clinical questions are written in the page language with English shorthand
   embedded (AAA, PE, LVO), so they follow the page direction and isolate. */
.indication-chips .chip {
  direction: inherit;
  unicode-bidi: isolate;
  text-align: start;
  font-weight: 500;
}
.indication-chips { margin-bottom: 18px; }
.sheet-urgency-label { margin-top: 4px; }

.study-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--gap);
}

.study-btn {
  min-height: 88px;
  padding: 14px;
  font-size: 17px;
  font-weight: 600;
  text-align: start;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  direction: ltr;
  unicode-bidi: isolate;
}
.study-btn:active { background: var(--surface-2); }

/* --------------------------------------------------------------- feeds */

.feed { display: grid; gap: 10px; }

.alert-card {
  display: grid;
  grid-template-columns: 6px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px 14px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
html[dir="rtl"] .alert-card { padding: 14px 0 14px 16px; }

.alert-stripe { align-self: stretch; background: var(--muted); }
.alert-card[data-urgency="urgent"] .alert-stripe { background: var(--urgent); }
.alert-card[data-urgency="emergent"] .alert-stripe { background: var(--emergent); }
.alert-card[data-acked="true"] .alert-stripe { background: var(--ok); }

.alert-main { min-width: 0; }
.alert-study {
  font-size: 18px;
  font-weight: 650;
  direction: ltr;
  unicode-bidi: isolate;
  display: block;
}
/* The clinical question is the reason this alert matters — give it weight. */
.alert-indication {
  display: block;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 600;
  color: #cfe6ff;
  unicode-bidi: isolate;
}

.alert-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.tag.urgent { background: rgba(245, 165, 36, 0.18); color: var(--urgent); }
.tag.emergent { background: rgba(255, 77, 79, 0.18); color: var(--emergent); }
.tag.acked { background: rgba(53, 194, 106, 0.16); color: var(--ok); }
.tag.waiting { background: rgba(147, 162, 181, 0.16); color: var(--muted); }
.tag.scanner { background: var(--surface-2); color: var(--muted); direction: ltr; unicode-bidi: isolate; }

.ack-btn {
  min-height: 60px;
  min-width: 116px;
  margin-inline-end: 14px;
  font-size: 16px;
  font-weight: 700;
  color: #05121f;
  background: var(--ok);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.ack-btn:active { transform: translateY(1px); }

.alert-card[data-urgency="emergent"][data-acked="false"] {
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); }
  50% { box-shadow: 0 0 0 4px rgba(255, 77, 79, 0.22); }
}
@media (prefers-reduced-motion: reduce) {
  .alert-card[data-urgency="emergent"][data-acked="false"] { animation: none; border-color: var(--emergent); }
}

/* ------------------------------------------------------- urgency sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(4, 8, 13, 0.72);
  padding: 16px;
}
.sheet-backdrop[hidden] { display: none; }

.sheet {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.sheet-title {
  margin: 0 0 4px;
  font-size: 21px;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}
.sheet .muted { margin: 0 0 16px; font-size: 14px; }

.urgency-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: 76px;
  margin-bottom: 12px;
  padding: 12px 18px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  text-align: start;
}
.urgency-btn.urgent { background: var(--urgent); color: var(--urgent-ink); }
.urgency-btn.emergent { background: var(--emergent); color: #fff; }
.urgency-name { font-size: 20px; font-weight: 750; }
.urgency-sub { font-size: 13px; opacity: 0.82; }

/* -------------------------------------------------------- alert banner */

.banner {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 50;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--emergent);
  color: #fff;
}
.banner[hidden] { display: none; }
/* Keep the last card clear of the fixed banner. */
body.has-banner main { padding-bottom: 130px; }
body.has-banner .disclaimer { display: none; }
.banner[data-urgency="urgent"] { background: var(--urgent); color: var(--urgent-ink); }

.banner-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(760px, 100%);
  margin: 0 auto;
}
.banner-urgency { font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.banner-text { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.banner-study {
  font-size: 18px;
  line-height: 1.25;
  font-weight: 700;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}
.banner-indication {
  font-size: 14px;
  font-weight: 600;
  opacity: 0.9;
  unicode-bidi: isolate;
  text-align: start;
}
.banner-indication:empty { display: none; }
.banner-ack {
  min-height: 52px;
  padding: 0 22px;
  font-size: 16px;
  font-weight: 750;
  color: #0b1017;
  background: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

/* ----------------------------------------------------------- duty mode */

.duty-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 6px;
}

.duty-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  min-height: 72px;
  padding: 12px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.duty-btn[data-on="true"] {
  color: #05121f;
  background: var(--ok);
  border-color: var(--ok);
}
.duty-state { font-size: 19px; font-weight: 700; }
.duty-hint { font-size: 13px; opacity: 0.75; }

.duty-options { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.duty-buttons { display: flex; gap: 8px; }
.duty-buttons .ghost-btn { flex: 1; min-height: 46px; }
.duty-note { margin: 12px 0 0; font-size: 12.5px; line-height: 1.5; }

/* --------------------------------------------------------------- misc */

.notify-row { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--muted); }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

.toast {
  position: fixed;
  inset-inline: 0;
  bottom: 20px;
  z-index: 70;
  width: fit-content;
  max-width: 90vw;
  margin: 0 auto;
  padding: 12px 20px;
  font-size: 15px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.toast[hidden] { display: none; }

.disclaimer {
  padding: 0 16px 22px;
  text-align: center;
}
.disclaimer p {
  width: min(760px, 100%);
  margin: 0 auto;
  font-size: 12.5px;
  color: var(--muted);
}

@media (max-width: 420px) {
  .study-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .study-btn { min-height: 78px; font-size: 15px; padding: 12px; }
}
