/* Emergency Line — one stylesheet, no external fonts or assets (the CSP allows only this origin). */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #14171c;
  --text-2: #5b6370;
  --text-3: #8b93a1;
  --accent: #e5484d;
  --accent-ink: #ffffff;
  --accent-soft: #fdecec;
  --focus: #3b82f6;
  --user-bubble: #1f2937;
  --user-ink: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;

  --st-investigating: #2563eb; --st-investigating-bg: #e8f0fe;
  --st-fixed: #15803d;         --st-fixed-bg: #e7f6ec;
  --st-diagnosed: #b45309;     --st-diagnosed-bg: #fdf3e2;
  --st-escalated: #c2410c;     --st-escalated-bg: #fdede3;
  --st-declined: #4b5563;      --st-declined-bg: #eef0f3;
  --st-waiting: #7c3aed;       --st-waiting-bg: #f1eafe;
  --st-error: #b91c1c;         --st-error-bg: #fde8e8;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --border: #2a303b;
    --text: #e8eaee;
    --text-2: #a3abb8;
    --text-3: #6f7886;
    --accent-soft: #3a1b1d;
    --user-bubble: #2b3442;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --st-investigating: #7aa7ff; --st-investigating-bg: #1a2640;
    --st-fixed: #5bd28a;         --st-fixed-bg: #15291e;
    --st-diagnosed: #f2b84b;     --st-diagnosed-bg: #2e2412;
    --st-escalated: #ff9a62;     --st-escalated-bg: #321d12;
    --st-declined: #a3abb8;      --st-declined-bg: #22272f;
    --st-waiting: #b79cff;       --st-waiting-bg: #261d3a;
    --st-error: #ff7b7b;         --st-error-bg: #361819;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- boot ---- */
.boot { display: grid; place-items: center; height: 100%; }
.boot-mark, .logo {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent) url("/icon.svg") center/cover;
}
.boot-mark { animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.92); opacity: .7; } }

/* ---- auth screens ---- */
.auth {
  min-height: 100%; display: grid; place-items: center; padding: 32px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(229, 72, 77, .14), transparent 60%),
    var(--bg);
}
.card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow); padding: 32px 28px;
}
.card.wide { max-width: 520px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field small { display: block; color: var(--text-3); font-size: 12px; margin-top: 6px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none; transition: border-color .15s, background .15s;
}
.input:focus { border-color: var(--focus); background: var(--surface); }
.input.code { font-size: 22px; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink); transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn.small { padding: 7px 12px; font-size: 13px; }

.alert {
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 16px;
  background: var(--st-error-bg); color: var(--st-error);
}
.alert:empty { display: none; }
.foot { margin-top: 20px; text-align: center; color: var(--text-3); font-size: 12px; }
.backup { margin-top: 6px; }
.backup a { color: var(--text-2); }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0 0 8px; }
.steps > li { position: relative; padding-left: 40px; margin-bottom: 22px; }
.steps > li::before {
  counter-increment: s; content: counter(s); position: absolute; left: 0; top: 0;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px;
}
.steps h3 { margin: 2px 0 6px; font-size: 15px; }
.steps p { margin: 0 0 10px; color: var(--text-2); font-size: 14px; }
.qr { width: 200px; height: 200px; padding: 10px; background: #fff; border-radius: 12px; border: 1px solid var(--border); }
.qr svg { width: 100%; height: 100%; display: block; }
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all;
  background: var(--surface-2); padding: 8px 10px; border-radius: 8px; margin-top: 10px;
}

/* ---- app shell ---- */
.app { display: grid; grid-template-rows: auto 1fr; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar .logo { width: 32px; height: 32px; border-radius: 9px; }
.topbar .title { font-weight: 700; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip.ok { color: var(--st-fixed); background: var(--st-fixed-bg); }
.chip.bad { color: var(--st-error); background: var(--st-error-bg); }
.menu-btn { display: none; background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--text); }
.menu-btn svg { display: block; }
.who { font-size: 13px; color: var(--text-2); }

.body { display: grid; grid-template-columns: 300px 1fr; min-height: 0; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: 14px; }
.list { overflow-y: auto; padding: 0 8px 16px; flex: 1; }
.list-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 8px 8px 6px; }
.item {
  display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 10px;
  padding: 10px; margin-bottom: 2px; color: var(--text);
}
.item:hover { background: var(--surface-2); }
.item.active { background: var(--accent-soft); }
.item .t { font-weight: 600; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .m { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--text-3); }
.empty-list { color: var(--text-3); font-size: 13px; padding: 12px 10px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; text-transform: capitalize; white-space: nowrap;
}
.pill[data-s="queued"], .pill[data-s="investigating"] { color: var(--st-investigating); background: var(--st-investigating-bg); }
.pill[data-s="fixed"], .pill[data-s="checked"] { color: var(--st-fixed); background: var(--st-fixed-bg); }
.pill[data-s="diagnosed"] { color: var(--st-diagnosed); background: var(--st-diagnosed-bg); }
.pill[data-s="escalated"] { color: var(--st-escalated); background: var(--st-escalated-bg); }
.pill[data-s="declined"], .pill[data-s="blocked"], .pill[data-s="duplicate"] { color: var(--st-declined); background: var(--st-declined-bg); }
.pill[data-s="waiting"], .pill[data-s="unclear"] { color: var(--st-waiting); background: var(--st-waiting-bg); }
.pill[data-s="error"], .pill[data-s="interrupted"] { color: var(--st-error); background: var(--st-error-bg); }
.pill[data-s="investigating"] .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.banner.warn { background: var(--st-escalated-bg); color: var(--st-escalated); }
.choices { margin-left: 40px; display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 8px 14px; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow);
}
.choice:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.choice:disabled { opacity: .5; cursor: default; }
@media (max-width: 820px) { .choices { margin-left: 0; } }
.banner {
  margin: 12px 16px 0; padding: 10px 14px; border-radius: 10px; font-size: 13px;
  background: var(--st-investigating-bg); color: var(--st-investigating);
}

/* ---- new emergency ---- */
.hero { flex: 1; overflow-y: auto; display: grid; place-items: center; padding: 32px 16px; }
.hero-inner { width: 100%; max-width: 640px; }
.hero h2 { font-size: 26px; letter-spacing: -.02em; margin: 0 0 6px; }
.hero .lead { color: var(--text-2); margin: 0 0 20px; }
.composer-big {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  padding: 12px; transition: border-color .15s;
}
.composer-big:focus-within { border-color: var(--focus); }
.composer-big textarea { width: 100%; min-height: 130px; border: 0; outline: 0; resize: vertical; background: transparent; padding: 6px; }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 4px 0; }
.hint { color: var(--text-3); font-size: 12px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.example {
  border: 1px dashed var(--border); background: none; border-radius: 999px; padding: 6px 12px;
  font-size: 13px; color: var(--text-2);
}
.example:hover { border-style: solid; color: var(--text); }
.rules { margin-top: 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rule { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; font-size: 13px; color: var(--text-2); }
.rule b { display: block; color: var(--text); margin-bottom: 4px; font-size: 14px; }

/* ---- incident ---- */
.inc-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.inc-head h2 { font-size: 16px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread { flex: 1; overflow-y: auto; padding: 20px 16px 8px; scroll-behavior: smooth; }
.thread-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

.msg { display: flex; gap: 10px; max-width: 100%; }
.msg.user { justify-content: flex-end; }
.bubble { padding: 10px 14px; border-radius: 16px; max-width: min(560px, 85%); overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bubble); color: var(--user-ink); border-bottom-right-radius: 6px; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.meta { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }
.msg.user .meta { text-align: right; color: rgba(255, 255, 255, .6); }
.avatar { width: 30px; height: 30px; border-radius: 9px; flex: none; background: var(--accent) url("/icon.svg") center/cover; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin: 0; }
.bubble ul { margin: 4px 0 8px; padding-left: 20px; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.steps-box { margin-left: 40px; max-width: min(560px, 85%); }
.steps-box summary {
  list-style: none; cursor: pointer; font-size: 12.5px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
}
.steps-box summary::-webkit-details-marker { display: none; }
.steps-box summary::before { content: "▸"; font-size: 10px; transition: transform .15s; }
.steps-box[open] summary::before { transform: rotate(90deg); }
.steps-box ol { margin: 8px 0 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); list-style: none; }
.steps-box li { font-size: 12.5px; color: var(--text-2); padding: 3px 0 3px 10px; overflow-wrap: anywhere; }
.steps-box li.blocked { color: var(--st-escalated); }
.steps-box li.err { color: var(--st-error); }

.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
.live { font-size: 12.5px; color: var(--text-2); margin-left: 40px; }

.report {
  margin-left: 40px; max-width: min(600px, 88%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
}
.report-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.report-head b { flex: 1; }
.report dl { margin: 0; padding: 4px 16px 12px; }
.report dt { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-top: 12px; }
.report dd { margin: 3px 0 0; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note { margin-left: 40px; font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.note.ok { color: var(--st-fixed); } .note.bad { color: var(--st-error); }

.composer {
  border-top: 1px solid var(--border); background: var(--surface); padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.composer form { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 160px; min-height: 46px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); outline: none;
}
.composer textarea:focus { border-color: var(--focus); background: var(--surface); }

/* ---- small screens: the sidebar becomes a drawer ---- */
@media (max-width: 820px) {
  .body { grid-template-columns: 1fr; }
  .menu-btn { display: inline-flex; }
  .who { display: none; }
  .sidebar {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(320px, 86vw);
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
    padding-top: env(safe-area-inset-top);
  }
  .app.drawer .sidebar { transform: none; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 10; }
  .app.drawer .scrim { display: block; }
  .rules { grid-template-columns: 1fr; }
  .hero h2 { font-size: 22px; }
  .steps-box, .report, .live, .note { margin-left: 0; max-width: 100%; }
  .bubble { max-width: 88%; }
  .card { padding: 26px 20px; }
}

/* phone header: keep everything on one line */
.chip, .btn, .topbar .title { white-space: nowrap; }
@media (max-width: 480px) {
  .topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .topbar .title { display: none; }
  .topbar .chip { padding: 4px 8px; font-size: 11px; }
}
.app, .main, .body { max-width: 100vw; overflow-x: hidden; }
