:root {
  --bg: #0f172a;
  --bg-2: #0b1220;
  --panel: #1e293b;
  --line: #334155;
  --muted: #94a3b8;
  --text: #e2e8f0;
  --accent: #38bdf8;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --shadow: 0 10px 40px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(56,189,248,0.08), transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(168,85,247,0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.view { min-height: 100vh; }
[hidden] { display: none !important; }

/* ---------- LOGIN ---------- */
#loginView {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: rgba(30,41,59,0.6);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px;
  width: 100%; max-width: 360px;
  box-shadow: var(--shadow);
}
.logo { text-align: center; margin-bottom: 24px; }
.logo h1 { margin: 12px 0 4px; font-size: 24px; letter-spacing: 0.04em; }
.logo p { margin: 0; }
.logo-circle {
  width: 64px; height: 64px; margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), #818cf8, var(--accent));
  position: relative;
  animation: spin 6s linear infinite;
}
.logo-circle::after {
  content: ''; position: absolute; inset: 4px; border-radius: 50%;
  background: var(--bg);
}
.logo-circle.small { width: 28px; height: 28px; }
.logo-circle.small::after { inset: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

#loginForm { display: flex; flex-direction: column; gap: 12px; }
#loginForm label { font-size: 13px; color: var(--muted); }
#loginForm input {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line);
  padding: 14px 16px; border-radius: 10px; font-size: 18px; text-align: center;
  letter-spacing: 0.4em; font-family: inherit;
}
#loginForm input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ---------- BUTTONS ---------- */
.btn {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); padding: 12px 18px;
  border-radius: 10px; font-size: 15px; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: transform 0.15s, background 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #0f172a; font-weight: 600; border-color: transparent;
}
.btn.ghost { background: transparent; }
.btn.danger {
  background: linear-gradient(135deg, var(--bad), #b91c1c);
  color: #fff; border: none; font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.35);
}
.btn.danger:hover { filter: brightness(1.1); }
.btn.danger:active { transform: scale(0.97); }
.btn.danger:disabled { opacity: 0.5; cursor: wait; }
.danger-zone { border: 1px solid rgba(239, 68, 68, 0.25); background: rgba(239, 68, 68, 0.03); }
.btn.big-btn {
  /* Receiver-mode action button — fills the card with comfortable side
     insets, perfectly centered text, predictable hit-area on phones. */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 18px auto 0;
  padding: 20px 24px;
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  border-radius: 14px;
  text-align: center;
  letter-spacing: 0.01em;
  /* Lock to the card frame — never larger than its parent */
  max-width: 100%;
  box-sizing: border-box;
}
.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 16px;
}
.icon-btn:active { background: var(--panel); }

/* Stop-alarm escape hatch — APK-only; styled red so it's findable in a panic. */
.icon-btn.stop-alarm {
  background: rgba(239, 68, 68, 0.10);
  border-color: var(--bad);
  color: var(--bad);
  animation: stopAlarmGlow 2s ease-in-out infinite;
}
.icon-btn.stop-alarm:active { background: var(--bad); color: #fff; }
@keyframes stopAlarmGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
  50%      { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.18); }
}

.error { color: var(--bad); margin: 0; font-size: 13px; }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: rgba(15,23,42,0.7);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.topbar-status { display: flex; align-items: center; gap: 10px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
  transition: background 0.3s, box-shadow 0.3s;
}
.dot.online  { background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.offline { background: var(--bad); }
.dot.connecting { background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ---------- DASHBOARD ---------- */
#dashboard { padding: 18px; max-width: 720px; margin: 0 auto; }
.card {
  background: rgba(30,41,59,0.55);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card.glow {
  border-color: rgba(56,189,248,0.3);
  text-align: center;
  padding: 40px 24px;
}
/* ============================================================
   ALERT URGENCY TIERS — escalation drives visual intensity.
   data-level on the card:
     0 = first request → AMBER warning, steady pulse
     1 = 2nd attempt   → RED, faster pulse, shake on entry
     2 = final attempt → RED INTENSE, very fast pulse
   ============================================================ */

/* Base alert card (always applied) */
.card.alert {
  border-width: 2px;
  position: relative;
}

/* ---- LEVEL 0: AMBER WARNING (first request) ---- */
.card.alert[data-level="0"] {
  border-color: var(--warn);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.08), rgba(30, 41, 59, 0.55));
  animation:
    amberPulse 1.4s ease-in-out infinite,
    alertEntryFlash 0.6s ease-out 1;
}
.card.alert[data-level="0"] h2 { color: var(--warn); }
.card.alert[data-level="0"] .alert-body { color: #fff; font-weight: 500; }
.card.alert[data-level="0"] .btn.primary {
  background: linear-gradient(135deg, var(--warn), #b45309);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 20px rgba(245, 158, 11, 0.4);
}
@keyframes amberPulse {
  0%, 100% {
    box-shadow:
      var(--shadow),
      0 0 0 0 rgba(245, 158, 11, 0.55),
      inset 0 0 24px rgba(245, 158, 11, 0.04);
  }
  50% {
    box-shadow:
      var(--shadow),
      0 0 0 12px rgba(245, 158, 11, 0),
      inset 0 0 32px rgba(245, 158, 11, 0.14);
  }
}
@keyframes alertEntryFlash {
  0%   { transform: scale(0.97); opacity: 0; }
  60%  { transform: scale(1.02); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}

/* ---- LEVEL 1: RED — 2nd attempt ---- */
.card.alert[data-level="1"] {
  border-color: var(--bad);
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.10), rgba(30, 41, 59, 0.55));
  animation:
    redPulse 0.9s ease-in-out infinite,
    urgentShake 0.5s ease-in-out 1;
}
.card.alert[data-level="1"] h2 { color: var(--bad); }
.card.alert[data-level="1"] .alert-body { color: #fff; font-weight: 600; }
.card.alert[data-level="1"] .btn.primary {
  background: linear-gradient(135deg, var(--bad), #b91c1c);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 4px 24px rgba(239, 68, 68, 0.45);
}

/* ---- LEVEL 2+: RED INTENSE — final / waiting ---- */
.card.alert[data-level="2"],
.card.alert[data-level="3"] {
  border-color: var(--bad);
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.18), rgba(30, 41, 59, 0.65));
  animation:
    redPulseIntense 0.55s ease-in-out infinite,
    urgentShake 0.5s ease-in-out 2;
}
.card.alert[data-level="2"] h2,
.card.alert[data-level="3"] h2 { color: var(--bad); text-shadow: 0 0 12px rgba(239,68,68,0.5); }
.card.alert[data-level="2"] .alert-body,
.card.alert[data-level="3"] .alert-body { color: #fff; font-weight: 700; }
.card.alert[data-level="2"] .btn.primary,
.card.alert[data-level="3"] .btn.primary {
  background: linear-gradient(135deg, var(--bad), #7f1d1d);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 4px 32px rgba(239, 68, 68, 0.6);
}

@keyframes redPulse {
  0%, 100% {
    box-shadow:
      var(--shadow),
      0 0 0 0 rgba(239, 68, 68, 0.7),
      inset 0 0 24px rgba(239, 68, 68, 0.05);
  }
  50% {
    box-shadow:
      var(--shadow),
      0 0 0 14px rgba(239, 68, 68, 0),
      inset 0 0 36px rgba(239, 68, 68, 0.18);
  }
}
@keyframes redPulseIntense {
  0%, 100% {
    box-shadow:
      var(--shadow),
      0 0 0 0 rgba(239, 68, 68, 0.85),
      inset 0 0 32px rgba(239, 68, 68, 0.12);
  }
  50% {
    box-shadow:
      var(--shadow),
      0 0 0 18px rgba(239, 68, 68, 0),
      inset 0 0 48px rgba(239, 68, 68, 0.30);
  }
}
@keyframes urgentShake {
  0%, 100%        { transform: translateX(0); }
  10%, 30%, 50%, 70% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

/* ============================================================
   CANCEL CARD — boss retracted the order. Same surface as alert
   but visually inverted: red "STOP" treatment, single shake on
   entry, steady (non-pulsing) red glow so it doesn't look like
   another active alert.
   ============================================================ */
.card.cancel {
  border: 2px solid var(--bad);
  background:
    linear-gradient(180deg, rgba(239, 68, 68, 0.18), rgba(30, 41, 59, 0.65));
  position: relative;
  animation:
    cancelEntryFlash 0.5s ease-out 1,
    urgentShake 0.45s ease-in-out 1;
  box-shadow:
    var(--shadow),
    0 0 0 4px rgba(239, 68, 68, 0.18),
    inset 0 0 32px rgba(239, 68, 68, 0.10);
}
.card.cancel h2 {
  color: var(--bad);
  font-size: 20px;
  letter-spacing: 0.02em;
  font-weight: 700;
}
.card.cancel .alert-body {
  color: #fff;
  font-weight: 500;
}
.card.cancel .btn.primary {
  background: linear-gradient(135deg, var(--bad), #991b1b);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
}
@keyframes cancelEntryFlash {
  0%   { transform: scale(0.95); opacity: 0; }
  50%  { transform: scale(1.03); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}

.card.warning {
  border-color: var(--warn);
  background: rgba(245,158,11,0.06);
}
.card.warning h3 { margin: 0 0 8px; font-size: 15px; color: var(--warn); }
.card.warning p  { margin: 0 0 12px; color: var(--muted); font-size: 14px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.big   { font-size: 20px; margin: 8px 0; }

/* Receiver layout — alert + cancel cards are the focal point of the screen,
   not just a list item. Centered, generous spacing, header reads as a phone-
   call banner ("Boss Alert · 10:45"), body is the dominant typography. */
.alert-head {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  text-align: center;
}
.alert-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.24em;
  text-transform: uppercase;
}
.alert-head .muted { font-size: 13px; opacity: 0.7; font-variant-numeric: tabular-nums; }

.alert-body {
  font-size: 26px;
  font-weight: 500;
  line-height: 1.3;
  margin: 18px 0 24px;
  word-wrap: break-word;
  text-align: center;
}

/* Inside the cards we want everything to read centered + breathe. */
.card.alert,
.card.cancel {
  padding: 28px 22px 24px;
  text-align: center;
}
.card.alert .btn.big-btn,
.card.cancel .btn.big-btn { margin-top: 8px; }

/* Ack status line (Sending… / Acknowledged in 4s) sits below the button */
#ackStatus { margin-top: 10px; text-align: center; }

/* ---------- PANELS ---------- */
.panel {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex; flex-direction: column;
  animation: fade 0.2s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.panel-head h3 { margin: 0; font-size: 16px; }
.panel-body { padding: 18px; overflow-y: auto; flex: 1; background: var(--bg); }
.panel-body h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted);
                 text-transform: uppercase; letter-spacing: 0.04em; }
.panel-body h4:first-child { margin-top: 0; }

.history-row {
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.history-row:last-child { border-bottom: none; }
.history-row .cmd { font-weight: 500; }
.history-row .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }

.device-row {
  padding: 10px 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: 8px; font-size: 13px;
}
.device-row .id { font-family: monospace; font-size: 12px; color: var(--muted); }
.device-row .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

.diag-row {
  display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
.diag-row:last-child { border-bottom: none; }

/* ---------- INLINE SECTIONS (recent orders + devices) ---------- */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.section-head h3 {
  margin: 0; font-size: 14px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--text);
}
.xs { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }

/* Tabs above the list — Responded / Missed / Cancelled */
.hist-tabs {
  display: flex; gap: 4px;
  padding: 4px;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
}
.hist-tab {
  flex: 1; background: transparent; border: none;
  color: var(--muted);
  padding: 8px 6px; border-radius: 7px; cursor: pointer;
  font-family: inherit; font-size: 12px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.hist-tab:hover { color: var(--text); }
.hist-tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.hist-tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 6px;
  border-radius: 9px; font-size: 10px; font-weight: 700;
  background: rgba(56, 189, 248, 0.18); color: var(--accent);
}
.hist-tab-badge.missed { background: rgba(239, 68, 68, 0.2); color: var(--bad); }

/* When there are unseen-since-last-check missed orders, the badge glows
   red and pulses gently — keeps drawing the eye until Tina taps the tab. */
.hist-tab-badge.has-unseen {
  background: var(--bad);
  color: #fff;
  animation: missedPulse 1.6s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
}
@keyframes missedPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.history-inline {
  display: flex; flex-direction: column; gap: 0;
  max-height: 320px; overflow-y: auto;
}
.history-inline::-webkit-scrollbar { width: 4px; }
.history-inline::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

/* History rows — friendly view for Tina: avatar + boss-asked-for-X +
   outcome pill + relative time. Mirrors the boss panel's drawer rendering
   so both surfaces feel like the same product. */
.hist-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.hist-row:last-child { border-bottom: none; }

.hist-avatar {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-2);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 16px; font-weight: 600;
}
.hist-avatar img { width: 100%; height: 100%; object-fit: cover; object-position: center 25%; }
.hist-avatar-blank { background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); }

.hist-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hist-line-1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hist-line-2 {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--muted);
}
.hist-person { font-weight: 600; font-size: 14px; color: var(--text); }
.hist-ago {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 10.5px; letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

.hist-pill {
  display: inline-flex; align-items: center;
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 10px; font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.hist-pill.ack {
  background: rgba(34, 197, 94, 0.12);
  color: var(--good);
  border: 1px solid rgba(34, 197, 94, 0.30);
}
.hist-pill.missed {
  background: rgba(239, 68, 68, 0.12);
  color: var(--bad);
  border: 1px solid rgba(239, 68, 68, 0.30);
}
.hist-pill.cancelled {
  background: rgba(245, 158, 11, 0.10);
  color: var(--warn);
  border: 1px solid rgba(245, 158, 11, 0.28);
}

/* Subtle row tint by outcome — failed orders pop without shouting */
.hist-row-missed       .hist-avatar { box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.30); }
.hist-row-cancelled    .hist-avatar { box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.28); }
.hist-row-acknowledged .hist-avatar { box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.20); }

.device-inline {
  display: flex; flex-direction: column; gap: 8px;
}
.dev-row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(15,23,42,0.5);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.dev-row.is-this { border-color: var(--accent); background: rgba(56,189,248,0.08); }
.dev-row .dev-info { flex: 1; min-width: 0; }
.dev-row .dev-title {
  font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 6px;
}
.dev-row .dev-meta {
  font-size: 11px; color: var(--muted); margin-top: 2px;
  font-family: -apple-system, monospace; word-break: break-all;
}
.dev-row .dev-pill {
  display: inline-block; padding: 1px 6px; border-radius: 6px;
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.dev-row .dev-pill.online  { background: rgba(34,197,94,0.18); color: var(--good); }
.dev-row .dev-pill.offline { background: rgba(239,68,68,0.15); color: var(--bad); }
.dev-row .dev-pill.this    { background: rgba(56,189,248,0.18); color: var(--accent); }

.dev-actions { display: flex; gap: 6px; flex-shrink: 0; }
.dev-btn {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.dev-btn:hover { background: var(--panel); border-color: var(--accent); }
.dev-btn.danger { color: var(--bad); }
.dev-btn.danger:hover { background: rgba(239,68,68,0.12); border-color: var(--bad); }
.dev-btn:disabled { opacity: 0.5; cursor: wait; }

/* ---------- COLLAPSIBLE DIAGNOSTICS ---------- */
.collapsible summary {
  cursor: pointer;
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
  padding: 4px 0;
  list-style: none;
}
.collapsible summary::before {
  content: '▸ '; display: inline-block; transition: transform 0.2s;
}
.collapsible[open] summary::before { transform: rotate(90deg); }
.collapsible[open] summary { color: var(--text); margin-bottom: 12px; }

.diag-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  margin-bottom: 12px;
}
.diag-grid .diag-row {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  font-size: 12px;
  display: flex; justify-content: space-between; align-items: center;
}

/* ---------- SETTINGS VIEW ---------- */
#settingsBody {
  padding: 18px; max-width: 720px; margin: 0 auto;
}
#settingsView .brand { gap: 14px; }
#settingsView #settingsBackBtn {
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 18px; font-weight: 500;
}

/* ---------- UPDATE BANNER ---------- */
.update-banner {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, calc(100% + 60px));
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 18px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(56,189,248,0.18), 0 4px 12px rgba(0,0,0,0.5);
  z-index: 200;
  font-size: 13px;
  color: var(--text);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.update-banner.show { transform: translate(-50%, 0); }
.update-banner .update-text { color: var(--accent); font-weight: 500; }
.update-banner .update-btn {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #0f172a; border: none;
  padding: 8px 16px; border-radius: 8px;
  font-family: inherit; font-size: 12px;
  font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  cursor: pointer;
}
.update-banner .update-btn:active { transform: scale(0.96); }
.update-banner .update-dismiss {
  background: transparent; color: var(--muted); border: none;
  width: 26px; height: 26px; border-radius: 50%;
  font-size: 18px; line-height: 1; cursor: pointer; font-family: inherit;
  display: flex; align-items: center; justify-content: center;
}
.update-banner .update-dismiss:hover { background: rgba(255,255,255,0.06); color: var(--text); }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 100px);
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); padding: 12px 22px; border-radius: 24px;
  font-size: 14px; box-shadow: var(--shadow);
  transition: transform 0.3s; z-index: 200;
}
.toast.show { transform: translate(-50%, 0); }
.toast.bad  { border-color: var(--bad); color: var(--bad); }
.toast.good { border-color: var(--good); }

/* ============================================================
   RESPONSIVE — small phones + safe areas (Android WebView, iOS notch)
   ============================================================ */

/* Respect notches / system bars — push the topbar below the status bar,
   add bottom padding so the FAB / system-nav doesn't overlap content. */
body {
  padding-top:    env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.topbar { padding-top: calc(14px + env(safe-area-inset-top, 0)); }

/* Phone-class viewports — tighten paddings, scale text, kill horizontal bleed */
@media (max-width: 480px) {
  .topbar { padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top, 0)); }
  .brand strong { font-size: 14px; }
  #dashboard { padding: 14px 12px 80px; }
  .card { padding: 18px 16px; border-radius: 14px; margin-bottom: 12px; }
  .card.glow { padding: 28px 18px; }
  .card.glow .big { font-size: 22px; }
  /* Receiver-mode body — stays large on phones because this IS the message */
  .alert-body  { font-size: 22px; margin: 14px 0 20px; }
  .big-btn     { font-size: 19px; padding: 18px; }
  /* Eyebrow keeps its uppercase but slightly tighter */
  .alert-head h2 { font-size: 13px; letter-spacing: 0.22em; }
  .card.alert, .card.cancel { padding: 24px 18px 22px; }
  .hist-tabs { gap: 4px; }
  .hist-tab { font-size: 12px; padding: 8px 10px; }
  .icon-btn { padding: 6px 8px; }
  /* Login card occupies the screen comfortably */
  #loginView { padding: 18px; }
  .login-card { padding: 24px 20px; max-width: 100%; }
}

/* ============================================================
   LANDSCAPE TAKEOVER — when the phone is rotated landscape and the
   secretary is idle (no alert in flight), present a giant
   "Standing by · awaiting Boss command" full-screen surface.
   The whole screen lights up the moment a real alert arrives because
   data-level swaps the card from idleCard → alertCard.
   Only triggers on small viewports (phone-class) — tablets keep their
   normal layout in landscape.
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) and (max-width: 950px) {
  /* Hide everything except the active card to stop visual noise */
  .topbar,
  #dashboard > section.card,        /* permission, orders, etc. */
  #dashboard > .card.alert[hidden],
  #updateBanner,
  #toast { /* untouched — toasts still visible */ }

  /* Anything inside the dashboard except the (visible) idleCard / alertCard
     gets hidden so the landscape view is one giant surface. */
  body.landscape-focus #dashboard > *:not(#idleCard):not(#alertCard):not(#cancelCard) { display: none !important; }
  body.landscape-focus .topbar { display: none !important; }
  body.landscape-focus #dashboard { padding: 0; max-width: none; }

  /* Idle takeover — fills the whole landscape view, dramatic typography */
  body.landscape-focus #idleCard:not([hidden]) {
    position: fixed;
    inset: 0;
    margin: 0;
    border-radius: 0;
    border: none;
    padding: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    background:
      radial-gradient(ellipse at center, rgba(56, 189, 248, 0.10), transparent 60%),
      var(--bg);
    box-shadow: none;
  }
  body.landscape-focus #idleCard h2 {
    font-size: 18px; letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--accent);
    margin: 0 0 16px;
    opacity: 0.7;
    animation: standbyBlink 2.4s ease-in-out infinite;
  }
  body.landscape-focus #idleCard .big {
    font-size: clamp(28px, 6vh, 56px);
    font-weight: 300;
    letter-spacing: 0.02em;
    margin: 0;
    color: var(--text);
  }
  body.landscape-focus #idleCard #lastAckLine { margin-top: 32px; opacity: 0.6; }

  /* Alert takeover — same fullscreen, but the urgency-tier visuals stay */
  body.landscape-focus #alertCard:not([hidden]) {
    position: fixed;
    inset: 0;
    margin: 0;
    border-radius: 0;
    padding: 32px 40px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
  }
  body.landscape-focus #alertCard .alert-head {
    flex-direction: column; gap: 8px;
    margin-bottom: 18px;
  }
  body.landscape-focus #alertCard h2 {
    font-size: 14px; letter-spacing: 0.4em; text-transform: uppercase;
    margin: 0;
  }
  body.landscape-focus #alertCard .alert-body {
    font-size: clamp(28px, 6vh, 52px);
    font-weight: 400; line-height: 1.2;
    margin: 0 0 28px;
    max-width: 90vw;
  }
  body.landscape-focus #alertCard .big-btn {
    width: auto;                    /* override the 100% from the base rule */
    font-size: 22px; padding: 18px 56px; border-radius: 999px;
    min-width: 240px;
    max-width: 480px;
  }

  /* Cancel takeover — same fullscreen treatment as alert, red palette */
  body.landscape-focus #cancelCard:not([hidden]) {
    position: fixed;
    inset: 0;
    margin: 0;
    border-radius: 0;
    padding: 32px 40px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
  }
  body.landscape-focus #cancelCard .alert-head {
    flex-direction: column; gap: 8px;
    margin-bottom: 18px;
  }
  body.landscape-focus #cancelCard h2 {
    font-size: clamp(20px, 3.5vh, 32px);
    letter-spacing: 0.06em;
    margin: 0;
  }
  body.landscape-focus #cancelCard .alert-body {
    font-size: clamp(26px, 5.5vh, 48px);
    font-weight: 400; line-height: 1.2;
    margin: 0 0 28px;
    max-width: 90vw;
  }
  body.landscape-focus #cancelCard .big-btn {
    width: auto;
    font-size: 22px; padding: 18px 56px; border-radius: 999px;
    min-width: 240px;
    max-width: 480px;
  }
}
@keyframes standbyBlink {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.85; }
}

/* ============================================================
   PREMIUM LOGIN — animated ambient gradient, real app logo with
   pulsing rings, 4-cell PIN entry. Same dark palette as the rest
   of the PWA so the transition into the dashboard feels seamless.
   ============================================================ */
#loginView {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

/* Two slow-drifting gradient layers for the ambient breathe effect */
.login-bg {
  position: fixed; inset: -20%;
  pointer-events: none;
  background:
    radial-gradient(40% 30% at 25% 35%, rgba(56, 189, 248, 0.18), transparent 70%),
    radial-gradient(38% 30% at 75% 65%, rgba(168, 85, 247, 0.12), transparent 70%),
    radial-gradient(45% 35% at 50% 55%, rgba(99, 102, 241, 0.10), transparent 70%);
  animation: loginAmbient 24s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes loginAmbient {
  0%   { transform: translate3d(-3%, -2%, 0) rotate(0deg); }
  100% { transform: translate3d( 3%,  2%, 0) rotate(6deg); }
}

/* Subtle starfield */
.login-stars {
  position: fixed; inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 14% 22%, rgba(255,255,255,0.55), transparent),
    radial-gradient(1px 1px at 78% 18%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.4px 1.4px at 32% 72%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 64% 84%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 88% 56%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 22% 88%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1px 1px at 50% 10%, rgba(255,255,255,0.35), transparent);
  animation: loginTwinkle 6s ease-in-out infinite alternate;
}
@keyframes loginTwinkle {
  0%   { opacity: 0.55; }
  100% { opacity: 1; }
}

/* The card itself — overrides the older .login-card styling */
#loginView .login-card {
  position: relative;
  z-index: 2;
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.85), rgba(15, 23, 42, 0.92));
  backdrop-filter: blur(28px) saturate(1.3);
  -webkit-backdrop-filter: blur(28px) saturate(1.3);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 24px;
  padding: 44px 32px 32px;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.05) inset,
    0 50px 120px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(56, 189, 248, 0.04) inset;
  animation: loginCardIn 0.65s cubic-bezier(0.34, 1.4, 0.64, 1);
  text-align: center;
}
@keyframes loginCardIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* App icon — actual logo PNG, ringed by a slow pulse */
.login-logo {
  width: 96px; height: 96px;
  margin: 0 auto 22px;
  position: relative;
}
.login-logo .login-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(56, 189, 248, 0.30);
  animation: loginRing 2.6s ease-in-out infinite;
  pointer-events: none;
}
.login-logo .login-ring.r1 { inset: -10px; }
.login-logo .login-ring.r2 { inset: -22px; border-color: rgba(56, 189, 248, 0.18); animation-delay: 0.4s; animation-duration: 3.2s; }
.login-logo .login-ring.r3 { inset: -34px; border-color: rgba(168, 85, 247, 0.14); animation-delay: 0.8s; animation-duration: 3.8s; }
@keyframes loginRing {
  0%, 100% { opacity: 0.4; transform: scale(0.96); }
  50%      { opacity: 1;   transform: scale(1.04); }
}
.login-logo img {
  width: 100%; height: 100%;
  border-radius: 22px;
  display: block;
  box-shadow:
    0 0 30px rgba(56, 189, 248, 0.30),
    0 12px 40px rgba(0, 0, 0, 0.55);
}

/* Typography overrides for the new layout */
.login-title {
  margin: 0 0 4px;
  font-size: 24px; font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}
.login-sub {
  margin: 0 0 26px;
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.30em;
  text-transform: uppercase;
  color: var(--muted);
}

/* 4-cell PIN row */
.pin-row {
  display: flex; gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}
.pin-cell {
  width: 52px; height: 64px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.20);
  border-radius: 14px;
  color: var(--text);
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 28px; font-weight: 600;
  text-align: center;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.2s, background 0.2s, transform 0.1s;
}
.pin-cell:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}
.pin-cell.filled {
  border-color: rgba(56, 189, 248, 0.50);
  background: rgba(56, 189, 248, 0.08);
}
.pin-cell.shake {
  animation: pinShake 0.4s;
  border-color: var(--bad);
}
@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Primary unlock button — slightly bigger + more emphasis than the
   default .btn.primary */
.login-btn {
  width: 100%;
  padding: 16px;
  font-size: 14px; font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  color: #0f172a;
  box-shadow: 0 8px 28px rgba(56, 189, 248, 0.32);
}

.login-err {
  margin-top: 14px;
  text-align: center;
  font-size: 13px;
  min-height: 18px;
  font-weight: 500;
}

.login-foot {
  position: fixed;
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  color: rgba(148, 163, 184, 0.40);
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.30em;
  text-transform: uppercase;
}

@media (max-width: 380px) {
  #loginView .login-card { padding: 36px 24px 28px; }
  .pin-cell { width: 48px; height: 60px; font-size: 26px; }
}

/* ============================================================
   MISSED-WHILE-AWAY BANNER
   Sits inside the idle card when there are missed orders Tina
   hasn't seen yet. Red, attention-grabbing, but contained — not
   a full alert (the actual order is past). One tap = jump to
   Missed tab and clear the counter.
   ============================================================ */
.missed-banner {
  margin-top: 18px;
  padding: 0;
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.14), rgba(239, 68, 68, 0.06));
  border: 1px solid rgba(239, 68, 68, 0.40);
  border-radius: 12px;
  display: flex; align-items: stretch;
  overflow: hidden;
  animation: missedBannerIn 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
  box-shadow: 0 8px 22px rgba(239, 68, 68, 0.12);
}
@keyframes missedBannerIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.missed-banner-body {
  flex: 1;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.missed-banner-body:hover { background: rgba(239, 68, 68, 0.06); }
.missed-banner-body:active { transform: scale(0.98); }
body.rtl .missed-banner-body { text-align: right; }

.missed-banner-icon {
  font-size: 20px;
  flex-shrink: 0;
}
.missed-banner-text {
  flex: 1;
  display: flex; flex-direction: column;
  line-height: 1.3;
}
.missed-banner-text strong {
  color: var(--bad);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.missed-banner-text span:last-child {
  font-size: 13px;
  color: var(--muted);
}
.missed-banner-cta {
  flex-shrink: 0;
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--bad);
  text-transform: uppercase;
}

.missed-banner-dismiss {
  flex-shrink: 0;
  background: transparent;
  border: none;
  border-left: 1px solid rgba(239, 68, 68, 0.20);
  color: var(--muted);
  font-size: 22px; line-height: 1;
  width: 44px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, background 0.15s;
}
.missed-banner-dismiss:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
body.rtl .missed-banner-dismiss { border-left: none; border-right: 1px solid rgba(239, 68, 68, 0.20); }

@media (max-width: 480px) {
  .missed-banner-body { padding: 12px 14px; gap: 10px; }
  .missed-banner-text strong { font-size: 20px; }
  .missed-banner-cta { font-size: 10px; }
}
