/* ============================================================
   Hatzalah Live — Protocols
   Mobile-first, dark, glove-friendly touch targets (min 48px)
   ============================================================ */

:root {
  --bg: #0b1220;
  --bg-raised: #121c30;
  --bg-card: #16223a;
  --border: #24314d;
  --text: #eef2f9;
  --text-dim: #9aa8c2;
  --blue: #2f6bff;
  --blue-soft: rgba(47, 107, 255, 0.16);
  --red: #ff4d5e;
  --red-soft: rgba(255, 77, 94, 0.14);
  --amber: #ffb020;
  --amber-soft: rgba(255, 176, 32, 0.12);
  --green: #2fd27d;
  --radius: 16px;
  --tab-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; }
.hidden { display: none !important; }

.safe-top { padding-top: max(12px, env(safe-area-inset-top)); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
.safe-bottom-pad { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 10px;
  background: linear-gradient(180deg, rgba(11,18,32,0.98), rgba(11,18,32,0.92));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-badge {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--blue); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(47,107,255,0.45);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 800; letter-spacing: 0.14em; font-size: 15px; color: var(--blue); }
.brand-sub { font-size: 10px; letter-spacing: 0.22em; color: var(--text-dim); font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-btn {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--red-soft); color: var(--red);
}
.account-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--blue-soft); color: var(--blue);
  border: 1px solid rgba(47,107,255,0.4);
  font-weight: 800; font-size: 17px; text-transform: uppercase;
}

/* ---------- Screens ---------- */
.screen {
  flex: 1;
  padding: 14px 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom));
  max-width: 720px; width: 100%; margin: 0 auto;
}

/* ---------- Search ---------- */
.search-wrap { display: flex; gap: 10px; align-items: stretch; }
.search-bar {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0 12px; min-height: 52px;
}
.search-bar:focus-within { border-color: var(--blue); }
.search-icon { color: var(--text-dim); flex: none; }
#searchInput {
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 16px; height: 50px;
}
#searchInput::placeholder { color: var(--text-dim); }
#searchInput::-webkit-search-cancel-button { display: none; }
.search-clear { color: var(--text-dim); padding: 8px; }

.mic-btn {
  flex: none; width: 52px; min-height: 52px; border-radius: var(--radius);
  background: var(--blue); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(47,107,255,0.4);
  transition: transform 0.1s ease, background 0.2s ease;
}
.mic-btn:active { transform: scale(0.94); }
.mic-btn.listening {
  background: var(--red);
  box-shadow: 0 0 0 6px var(--red-soft), 0 4px 14px rgba(255,77,94,0.4);
  animation: micPulse 1.2s ease-in-out infinite;
}
.mic-btn.unsupported { background: var(--bg-raised); color: var(--text-dim); box-shadow: none; }
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,77,94,0.45); }
  50% { box-shadow: 0 0 0 12px rgba(255,77,94,0); }
}
.mic-btn-sm { width: 48px; min-height: 48px; border-radius: 14px; }

.voice-hint {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px; padding: 12px 14px;
  background: var(--red-soft); border: 1px solid rgba(255,77,94,0.35);
  border-radius: 12px; font-size: 14px; color: var(--text);
}
.pulse-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--red);
  animation: micPulse 1.2s ease-in-out infinite; flex: none;
}

/* ---------- Category chips ---------- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 4px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 10px 16px; border-radius: 999px;
  background: var(--bg-raised); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 14px; font-weight: 600; white-space: nowrap;
  min-height: 42px;
}
.chip.active { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }

/* ---------- Protocol list ---------- */
.protocol-list { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.section-label {
  margin: 14px 2px 2px; font-size: 12px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim);
}
.protocol-card {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; min-height: 72px;
  transition: transform 0.08s ease;
}
.protocol-card:active { transform: scale(0.985); background: var(--bg-raised); }
.card-stripe { width: 5px; align-self: stretch; border-radius: 4px; background: var(--blue); flex: none; }
.card-stripe.critical { background: var(--red); }
.card-stripe.urgent { background: var(--amber); }
.card-body { flex: 1; min-width: 0; }
.card-title { font-size: 16px; font-weight: 700; }
.card-meta { margin-top: 3px; font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-chevron { color: var(--text-dim); flex: none; }
.empty-note { margin: 28px 8px; text-align: center; color: var(--text-dim); font-size: 15px; }

.disclaimer {
  margin: 26px 6px 8px; font-size: 12px; line-height: 1.5;
  color: var(--text-dim); text-align: center;
}

/* ---------- Protocol detail ---------- */
.detail-top {
  position: sticky; top: 63px; z-index: 15;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0 10px; background: var(--bg);
}
.back-btn {
  display: flex; align-items: center; gap: 2px;
  color: var(--blue); font-weight: 600; font-size: 16px;
  min-height: 44px; padding-right: 10px;
}
.read-btn {
  display: flex; align-items: center; gap: 7px;
  background: var(--blue-soft); color: var(--blue);
  border: 1px solid rgba(47,107,255,0.4); border-radius: 999px;
  padding: 0 16px; min-height: 44px; font-weight: 600; font-size: 14px;
}
.read-btn.reading { background: var(--red-soft); color: var(--red); border-color: rgba(255,77,94,0.4); }

.protocol-detail h1 { font-size: 24px; line-height: 1.2; margin: 6px 0 4px; }
.detail-category {
  display: inline-block; margin: 6px 0 14px; padding: 5px 12px;
  border-radius: 999px; background: var(--blue-soft); color: var(--blue);
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
}
.detail-category.critical { background: var(--red-soft); color: var(--red); }

.step-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 20px; }
.step {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; width: 100%; text-align: left;
}
.step.done { opacity: 0.45; }
.step.done .step-text { text-decoration: line-through; }
.step-num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--blue-soft); color: var(--blue);
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.step.done .step-num { background: var(--green); color: #04210f; }
.step-text { font-size: 16px; line-height: 1.45; padding-top: 3px; }

.callout {
  display: flex; gap: 10px; align-items: flex-start;
  border-radius: 14px; padding: 13px 14px; margin: 10px 0;
  font-size: 15px; line-height: 1.45;
}
.callout.warning { background: var(--red-soft); border: 1px solid rgba(255,77,94,0.35); }
.callout.warning .callout-icon { color: var(--red); }
.callout.pearl { background: var(--amber-soft); border: 1px solid rgba(255,176,32,0.3); }
.callout.pearl .callout-icon { color: var(--amber); }
.callout-icon { flex: none; margin-top: 1px; }

.detail-h2 {
  font-size: 13px; font-weight: 800; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-dim); margin: 22px 0 8px;
}
.med-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.med-table td {
  padding: 11px 8px; border-bottom: 1px solid var(--border); vertical-align: top;
}
.med-table td:first-child { font-weight: 700; white-space: nowrap; padding-left: 0; }
.med-table td:last-child { color: var(--text-dim); }

.source-link {
  display: flex; align-items: center; justify-content: center;
  margin-top: 18px; min-height: 50px; border-radius: 14px;
  background: var(--blue-soft); border: 1px solid rgba(47,107,255,0.4);
  color: var(--blue); font-weight: 700; font-size: 15px; text-decoration: none;
}

.reset-steps {
  margin-top: 8px; width: 100%; min-height: 48px;
  border: 1px dashed var(--border); border-radius: 14px;
  color: var(--text-dim); font-size: 14px; font-weight: 600;
}

/* ---------- Assistant ---------- */
#screen-assistant { display: flex; flex-direction: column; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 8px 0 16px; }
.chat-empty { margin: auto; text-align: center; padding: 30px 18px; color: var(--text-dim); }
.chat-empty-icon {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 22px;
  background: var(--blue-soft); color: var(--blue); display: grid; place-items: center;
}
.chat-empty h2 { color: var(--text); font-size: 20px; margin-bottom: 8px; }
.chat-empty p { font-size: 15px; line-height: 1.5; max-width: 300px; margin: 0 auto; }
.chat-empty-note { margin-top: 12px !important; font-size: 12px !important; opacity: 0.8; }

.msg { max-width: 88%; padding: 12px 15px; border-radius: 18px; font-size: 15.5px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.bot a { color: var(--blue); font-weight: 600; word-break: break-all; }
.msg.error { align-self: flex-start; background: var(--red-soft); border: 1px solid rgba(255,77,94,0.35); }
.msg.thinking { align-self: flex-start; color: var(--text-dim); background: var(--bg-card); border: 1px solid var(--border); }
.msg.thinking .dots::after { content: ""; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.chat-input-row {
  position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  display: flex; gap: 8px; align-items: center;
  padding-top: 10px; background: var(--bg);
}
#chatInput {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 16px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 14px; color: var(--text); font-size: 16px; outline: none;
}
#chatInput:focus { border-color: var(--blue); }
.send-btn {
  flex: none; width: 48px; min-height: 48px; border-radius: 14px;
  background: var(--blue); color: #fff; display: grid; place-items: center;
}
.send-btn:disabled { opacity: 0.5; }

/* ---------- Auth ---------- */
.auth-panel { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px 4px; }
.auth-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 26px 22px; text-align: center;
}
.auth-card .chat-empty-icon { margin-bottom: 4px; }
.auth-card h2 { font-size: 21px; }
.auth-sub { color: var(--text-dim); font-size: 14px; line-height: 1.45; margin-bottom: 6px; }
.auth-field {
  min-height: 50px; padding: 0 15px; border-radius: 13px;
  background: var(--bg-raised); border: 1px solid var(--border);
  color: var(--text); font-size: 16px; outline: none; width: 100%;
}
.auth-field:focus { border-color: var(--blue); }
.auth-submit {
  min-height: 50px; border-radius: 13px; margin-top: 4px;
  background: var(--blue); color: #fff; font-weight: 700; font-size: 16px;
}
.auth-submit:disabled { opacity: 0.55; }
.auth-toggle { min-height: 44px; color: var(--blue); font-size: 14px; font-weight: 600; }
.auth-error {
  padding: 11px 13px; border-radius: 12px; font-size: 14px; text-align: left;
  background: var(--red-soft); border: 1px solid rgba(255,77,94,0.35);
}

/* ---------- Admin ---------- */
.admin-title { font-size: 24px; margin: 4px 0 6px; }
.admin-sub { color: var(--text-dim); font-size: 14px; line-height: 1.5; margin-bottom: 16px; }
.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.admin-avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: var(--blue-soft); color: var(--blue);
  display: grid; place-items: center;
  font-weight: 800; font-size: 17px; text-transform: uppercase;
}
.admin-avatar.is-admin { background: var(--amber-soft); color: var(--amber); }
.admin-info { flex: 1; min-width: 0; }
.admin-name { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.role-badge {
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
  background: var(--amber-soft); color: var(--amber);
}
.admin-meta { margin-top: 3px; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-btn {
  flex: none; min-height: 42px; padding: 0 14px; border-radius: 12px;
  border: 1px solid rgba(47,107,255,0.4);
  background: var(--blue-soft); color: var(--blue);
  font-size: 13px; font-weight: 700;
}
.role-btn.demote { border-color: var(--border); background: var(--bg-raised); color: var(--text-dim); }
.role-btn.approve { border-color: rgba(47,210,125,0.5); background: rgba(47,210,125,0.14); color: var(--green); }
.role-btn:disabled { opacity: 0.5; }
.admin-actions { display: flex; flex-direction: column; gap: 6px; flex: none; }
.admin-card.pending { border-color: rgba(255,176,32,0.4); background: var(--amber-soft); }
.admin-avatar.pending { background: var(--amber-soft); color: var(--amber); }
.role-badge.unit { background: var(--blue-soft); color: var(--blue); }
.role-badge.rejected { background: var(--red-soft); color: var(--red); }

/* ---------- Tab bar ---------- */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  background: rgba(13, 20, 36, 0.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-dim); font-size: 11.5px; font-weight: 600;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab.active { color: var(--blue); }

@media (min-width: 720px) {
  .protocol-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .section-label { grid-column: 1 / -1; }
}
