:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #141a2b;
  --muted: #5d667d;
  --line: #dde2ee;
  --brand: #e2475f;
  --brand-2: #ff7a59;
  --brand-ink: #ffffff;
  --bot: #ffffff;
  --me: #1f2a44;
  --me-ink: #ffffff;
  --t0: #15803d; --t0-bg: #dcfce7;
  --t1: #1d4ed8; --t1-bg: #dbeafe;
  --t2: #b45309; --t2-bg: #fef3c7;
  --t3: #b91c1c; --t3-bg: #fee2e2;
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d111b; --surface: #161c2b; --surface-2: #1d2436; --text: #e9edf6; --muted: #9aa4bb;
    --line: #2a3349; --bot: #1d2436; --me: #e2475f; --me-ink: #fff;
    --t0-bg: #0f2e1d; --t1-bg: #13254a; --t2-bg: #3a2a0c; --t3-bg: #3d1414;
    --t0: #4ade80; --t1: #93c5fd; --t2: #fbbf24; --t3: #fca5a5;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Inter", "Segoe UI", Roboto, system-ui, sans-serif; font-size: 16px; line-height: 1.5;
}
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%;
}
textarea { resize: none; }
label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 12px 0 5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.btn {
  border: none; border-radius: 14px; padding: 12px 16px; font-weight: 700;
  background: var(--surface-2); color: var(--text); width: 100%; margin-top: 12px;
}
.btn-brand { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--brand-ink); }
.btn-danger { background: var(--t3-bg); color: var(--t3); }
.btn:disabled { opacity: .5; }

/* ---------- layout ---------- */
.shell { max-width: 720px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; }
header.top {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.logo { font-weight: 900; font-size: 18px; display: flex; align-items: center; gap: 6px; }
.logo .dot { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: grid; place-items: center; color: #fff; font-size: 14px; }
.top .spacer { flex: 1; }
.top .pill { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.iconbtn { white-space: nowrap; background: none; border: none; color: var(--muted); padding: 6px 8px; border-radius: 10px; font-size: 14px; }
.iconbtn:hover { background: var(--surface-2); }

nav.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--line); }
nav.tabs button {
  flex: 1; background: none; border: none; padding: 10px; color: var(--muted); font-weight: 700; font-size: 14px;
  border-bottom: 3px solid transparent;
}
nav.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

main { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.view { flex: 1; overflow-y: auto; padding: 16px; min-height: 0; }

/* ---------- chat ---------- */
#viewChat { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
#msgs { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.bubble { max-width: 86%; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.bubble.bot { background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 6px; align-self: flex-start; }
.bubble.me { background: var(--me); color: var(--me-ink); border-bottom-right-radius: 6px; align-self: flex-end; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bubble.me .meta { color: rgba(255,255,255,.7); }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding: 4px 10px; }
.typing span { animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2 } 40% { opacity: 1 } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  align-self: stretch;
}
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card ul { margin: 6px 0 0; padding-left: 20px; font-size: 14px; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.card .actions a { text-decoration: none; padding: 9px 14px; border-radius: 12px; font-weight: 800; font-size: 14px; background: var(--t3); color: #fff; }
.card.emergency { border: 2px solid var(--t3); background: var(--t3-bg); }
.card.crisis { border: 2px solid var(--t1); background: var(--t1-bg); }
.card.crisis .actions a { background: var(--t1); }

.tri { border-left-width: 6px; }
.tri.mandiri { border-left-color: var(--t0); } .tri.konsultasi { border-left-color: var(--t1); }
.tri.segera { border-left-color: var(--t2); }  .tri.darurat { border-left-color: var(--t3); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.pill.mandiri { background: var(--t0-bg); color: var(--t0); } .pill.konsultasi { background: var(--t1-bg); color: var(--t1); }
.pill.segera { background: var(--t2-bg); color: var(--t2); } .pill.darurat { background: var(--t3-bg); color: var(--t3); }
.pill.netral { background: var(--surface-2); color: var(--muted); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.metric { background: var(--surface-2); border-radius: 12px; padding: 8px; text-align: center; }
.metric b { display: block; font-size: 20px; }
.metric small { color: var(--muted); font-size: 11px; }

#chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 14px 8px; scrollbar-width: none; }
#chips button {
  white-space: nowrap; border: 1.5px solid var(--brand); color: var(--brand); background: var(--surface);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600;
}
#measureBar { padding: 0 14px 8px; }
#measureBar button { margin: 0; }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--line); }
.composer textarea { max-height: 120px; border-radius: 20px; padding: 10px 14px; }
.roundbtn { flex: none; width: 44px; height: 44px; border-radius: 50%; border: none; display: grid; place-items: center; font-size: 18px; background: var(--surface-2); color: var(--text); }
.roundbtn.send { background: var(--brand); color: #fff; }
.roundbtn.rec { background: var(--t3); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.ended-bar { padding: 12px; text-align: center; background: var(--surface); border-top: 1px solid var(--line); }

/* ---------- overlay ukur & modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8,10,18,.6); display: grid; place-items: center; padding: 16px; z-index: 50; }
.sheet { background: var(--surface); border-radius: 22px; padding: 20px; width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto; }
.sheet h2 { margin: 0 0 6px; font-size: 19px; }
.ring { width: 170px; height: 170px; border-radius: 50%; margin: 14px auto; display: grid; place-items: center;
  border: 7px solid var(--line); font-size: 46px; font-weight: 900; transition: border-color .3s; }
.ring.on { border-color: var(--t0); } .ring.off { border-color: var(--t2); }
.progress { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .25s; }
.wave { width: 100%; height: 60px; display: block; margin-top: 10px; }
.pre { white-space: pre-wrap; background: var(--surface-2); border-radius: 12px; padding: 12px; font-size: 14px; }

/* ---------- riwayat ---------- */
.sess { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; margin-bottom: 10px; }
.sess-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.sess details summary { cursor: pointer; color: var(--brand); font-size: 13px; margin-top: 6px; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.box h2 { font-size: 16px; margin: 0 0 6px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.code { font-family: ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 10px; border-radius: 10px; word-break: break-all; font-size: 13px; }
.alert { padding: 10px 12px; border-radius: 12px; font-size: 14px; margin-top: 10px; }
.alert.err { background: var(--t3-bg); color: var(--t3); }
.alert.ok { background: var(--t0-bg); color: var(--t0); }
.alert.info { background: var(--t1-bg); color: var(--t1); }

/* ---------- onboarding ---------- */
.onboard { max-width: 480px; margin: 0 auto; padding: 28px 18px; }
.hero { text-align: center; margin-bottom: 18px; }
.hero .big { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 20px; display: grid; place-items: center; font-size: 30px; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.hero h1 { margin: 0; font-size: 26px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin-top: 14px; color: var(--text); font-weight: 400; }
.check input { width: auto; margin-top: 3px; }

@media (max-width: 420px) { .row { grid-template-columns: 1fr; } .bubble { max-width: 92%; } }
