:root {
  --wa-teal-dark: #075E54;
  --wa-green: #128C7E;
  --wa-bright: #25D366;
  --wa-out-bubble: #D9FDD3;
  --wa-in-bubble: #FFFFFF;
  --wa-chat-bg: #EFE7DE;
  --wa-tick-read: #53BDEB;
  --wa-tick: #8696a0;
  --wa-meta: #667781;
  --wa-text: #111b21;
  --font-main: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Devanagari", "Noto Sans Tamil", sans-serif;

  --page-bg: #f0f2f1;
  --panel-bg: #ffffff;
  --panel-border: #e2e6e4;
  --ink: #1c2b27;
  --muted: #6a7a75;
  --ok: #1f9d55;
  --warn: #c77700;
  --bad: #d14343;
  --info: #2c7be5;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-main);
  color: var(--ink);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Top bar / controls ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--wa-teal-dark);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand .muted { color: rgba(255,255,255,.7); font-size: 13px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--wa-bright); box-shadow: 0 0 0 4px rgba(37,211,102,.25); }
.mode-switch {
  display: inline-flex; padding: 3px; gap: 2px;
  background: rgba(0,0,0,.22); border-radius: 99px;
}
.mode-switch button {
  border: 0; background: transparent; color: rgba(255,255,255,.8);
  padding: 7px 16px; border-radius: 99px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
}
.mode-switch button:hover { color: #fff; }
.mode-switch button[aria-selected="true"] { background: #fff; color: var(--wa-teal-dark); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.mode-badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 99px; background: #ffd27a; color: #4a3500; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ctl {
  border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.08);
  color: #fff;
  padding: 7px 12px; border-radius: 99px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s;
}
.ctl:hover { background: rgba(255,255,255,.18); }
.ctl[aria-pressed="false"] { opacity: .6; }
.ctl-primary { background: var(--wa-bright); border-color: var(--wa-bright); color: #053b2f; font-weight: 600; }
.ctl-primary:hover { background: #3be07a; }
.ctl-select select {
  background: transparent; border: 0; color: #fff; cursor: pointer; outline: none;
}
.ctl-select select option { color: #111; }

.chips {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 12px 20px 0;
}
.chip {
  border: 1px solid var(--panel-border); background: #fff; color: var(--wa-teal-dark);
  padding: 6px 12px; border-radius: 99px; font-size: 13px; cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.chip:hover { border-color: var(--wa-green); }
.chip:active { transform: scale(.97); }
.chip .chip-tag { color: var(--muted); font-size: 11px; margin-left: 4px; }

.tabs { display: none; }

/* ---------- Stage layout ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 400px minmax(280px, 1fr);
  gap: 24px;
  align-items: start;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 24px 32px;
}
.stage.hide-bts { grid-template-columns: 0 400px minmax(280px, 1fr); }
.stage.hide-right { grid-template-columns: minmax(260px, 1fr) 400px 0; }
.stage.hide-bts.hide-right { grid-template-columns: 0 400px 0; justify-content: center; }
.stage.hide-bts .panel-left, .stage.hide-right .panel-right { display: none; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  max-height: 820px;
  overflow: auto;
}
.panel-right { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.panel-right > section { padding: 16px; }
.panel-right > section + section { border-top: 1px solid var(--panel-border); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-head h2 { font-size: 15px; margin: 0; color: var(--wa-teal-dark); }

/* ---------- Phone ---------- */
.phone-wrap { display: flex; justify-content: center; }
.phone {
  position: relative;
  width: 390px; height: 800px;
  border-radius: 54px;
  background: var(--wa-chat-bg);
  border: 12px solid #1b1f1e;
  box-shadow: 0 0 0 2px #3a403e, 0 30px 60px -20px rgba(0,0,0,.35);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.notch {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: 110px; height: 30px; border-radius: 20px; background: #000; z-index: 5;
}
.statusbar {
  height: 44px; flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 28px 0 32px;
  background: var(--wa-teal-dark); color: #fff;
  font-size: 14px; font-weight: 600;
}
.status-icons { display: inline-flex; gap: 5px; align-items: center; }
.status-icons svg { fill: currentColor; }
.home-indicator {
  position: absolute; bottom: 7px; left: 50%; transform: translateX(-50%);
  width: 130px; height: 5px; border-radius: 3px; background: rgba(0,0,0,.75); z-index: 6;
  pointer-events: none;
}

.chat-header {
  flex: none;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px 8px 4px;
  background: var(--wa-teal-dark); color: #fff;
}
.icon-btn {
  border: 0; background: transparent; padding: 6px; border-radius: 50%;
  display: inline-flex; cursor: pointer; color: inherit;
}
.icon-btn svg { fill: currentColor; }
.avatar { width: 38px; height: 38px; border-radius: 50%; overflow: hidden; flex: none; background: #fff; display: flex; align-items: center; justify-content: center; }
.avatar-text { font-weight: 700; font-size: 12px; color: var(--wa-green); letter-spacing: .02em; }
.who { flex: 1; min-width: 0; padding-left: 4px; }
.who .name { display: flex; align-items: center; gap: 4px; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.verified { flex: none; }
#botName { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.presence { font-size: 12.5px; opacity: .85; min-height: 16px; }
.header-actions { display: flex; gap: 14px; padding-right: 2px; flex: none; }
.header-actions svg { fill: #fff; }

.chat {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 10px 14px 12px;
  background-color: var(--wa-chat-bg);
  background-image:
    radial-gradient(rgba(0,0,0,.035) 1.2px, transparent 1.3px),
    radial-gradient(rgba(0,0,0,.025) 1.2px, transparent 1.3px);
  background-size: 22px 22px, 22px 22px;
  background-position: 0 0, 11px 11px;
  scroll-behavior: smooth;
}
.chat::-webkit-scrollbar { width: 5px; }
.chat::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }

/* System notes and chips */
.date-chip, .sys-note {
  display: block; width: fit-content; max-width: 88%;
  margin: 8px auto; padding: 5px 12px;
  font-size: 12px; text-align: center; color: #54656f;
  background: #fff; border-radius: 8px;
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
}
.date-chip { text-transform: uppercase; letter-spacing: .02em; }
.sys-note.biz { background: #fff5c4; color: #54656f; }
.sys-note.biz strong { color: var(--wa-teal-dark); }
.sys-note.handover { background: #e1f3fb; }

/* Bubbles */
.msg { display: flex; flex-direction: column; margin-top: 2px; animation: pop .18s ease-out; }
.msg.first { margin-top: 8px; }
.msg.out { align-items: flex-end; }
.msg.in { align-items: flex-start; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

.bubble {
  position: relative;
  max-width: 78%;
  padding: 6px 8px 8px 9px;
  border-radius: 8px;
  font-size: 14.2px; line-height: 1.38;
  color: var(--wa-text);
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
  word-wrap: break-word; overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.in .bubble { background: var(--wa-in-bubble); }
.msg.out .bubble { background: var(--wa-out-bubble); }
.msg.first.in .bubble { border-top-left-radius: 0; }
.msg.first.out .bubble { border-top-right-radius: 0; }
.msg.first.in .bubble::before, .msg.first.out .bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px;
}
.msg.first.in .bubble::before { left: -8px; background: linear-gradient(to bottom left, var(--wa-in-bubble) 50%, transparent 50%); }
.msg.first.out .bubble::before { right: -8px; background: linear-gradient(to bottom right, var(--wa-out-bubble) 50%, transparent 50%); }
.bubble a { color: #027eb5; text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble .meta {
  float: right; margin: 6px 0 -4px 10px;
  font-size: 11px; color: var(--wa-meta);
  display: inline-flex; align-items: center; gap: 3px;
  white-space: nowrap;
}
.bubble .ai-tag {
  font-size: 10px; font-weight: 600; letter-spacing: .02em;
  color: var(--wa-green); margin-right: 4px;
}
.bubble .source {
  display: block; margin-top: 4px; font-size: 12.5px; color: var(--wa-meta);
}
.ticks { width: 16px; height: 11px; fill: var(--wa-tick); transition: fill .3s; }
.ticks.read { fill: var(--wa-tick-read); }

.bubble.wide { width: 78%; }
.bubble.template { border-top: 3px solid var(--wa-green); }
.template-label { font-size: 11px; color: var(--wa-meta); display: flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.template-title { font-weight: 700; margin-bottom: 2px; }
.template-footer { font-size: 12px; color: var(--wa-meta); margin-top: 4px; }

/* Quick replies + list button (attached to bot bubble) */
.qr-group, .list-btn {
  max-width: 78%; width: 78%;
  margin-top: 2px;
  display: flex; flex-direction: column; gap: 2px;
}
.qr, .list-btn button {
  border: 0; background: var(--wa-in-bubble); color: #027eb5;
  padding: 10px 8px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .12s;
}
.qr:hover:not(:disabled), .list-btn button:hover:not(:disabled) { background: #f5f6f6; }
.qr:disabled, .list-btn button:disabled { color: #9aa6ac; cursor: default; }
.qr svg, .list-btn svg { fill: currentColor; }

/* Typing indicator */
.typing .bubble { padding: 12px 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: #9aa6ac; animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* Cards */
.card-doc {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,.04); border-radius: 6px; padding: 10px; margin-bottom: 4px;
  color: inherit; text-decoration: none;
}
.card-doc:hover { background: rgba(0,0,0,.07); text-decoration: none !important; }
.pdf-icon {
  flex: none; width: 34px; height: 40px; border-radius: 4px; background: #e5483f; color: #fff;
  font-size: 10px; font-weight: 700; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px;
  position: relative;
}
.pdf-icon::after { content: ""; position: absolute; top: 0; right: 0; border-width: 0 10px 10px 0; border-style: solid; border-color: transparent #f7b3ae transparent transparent; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; color: var(--wa-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 12px; color: var(--wa-meta); }
.doc-dl { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--wa-meta); display: flex; align-items: center; justify-content: center; }
.doc-dl svg { fill: var(--wa-meta); }

.card-status { min-width: 230px; }
.status-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.status-ref { font-weight: 700; font-size: 14px; letter-spacing: .01em; }
.status-chip { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.status-chip.review { background: #fff1d6; color: #8a5a00; }
.status-chip.approved { background: #d8f5e2; color: #12733a; }
.status-chip.pending { background: #fde2e1; color: #a12c2c; }
.status-rows { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; margin: 0 0 4px; }
.status-rows dt { color: var(--wa-meta); }
.status-rows dd { margin: 0; }

.card-link {
  display: block; text-decoration: none !important; color: inherit !important;
  background: rgba(0,0,0,.04); border-left: 3px solid var(--wa-green); border-radius: 6px;
  padding: 8px 10px; margin: 6px 0 2px;
}
.card-link:hover { background: rgba(0,0,0,.07); }
.link-title { font-weight: 600; font-size: 13.5px; }
.link-desc { font-size: 12.5px; color: var(--wa-meta); }
.link-domain { font-size: 11.5px; color: var(--wa-meta); margin-top: 2px; }

.card-image { display: block; border-radius: 6px; width: 100%; height: auto; margin-bottom: 4px; background: #ddd; }

/* Bottom sheet */
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); z-index: 10; animation: fade .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 11;
  background: #fff; border-radius: 18px 18px 0 0;
  max-height: 75%; display: flex; flex-direction: column;
  padding-bottom: 22px;
  animation: slideup .25s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: #d1d7db; margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid #eef0f1; }
.sheet-head .icon-btn svg { fill: var(--wa-meta); }
.sheet-head h3 { margin: 0; font-size: 16px; flex: 1; text-align: center; padding-right: 32px; }
.sheet-body { overflow-y: auto; padding: 4px 0; }
.sheet-section { font-size: 13px; color: var(--wa-green); font-weight: 600; padding: 12px 20px 4px; }
.sheet-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  border: 0; background: none; text-align: left; cursor: pointer;
  padding: 12px 20px;
}
.sheet-row:hover { background: #f5f6f6; }
.sheet-row .row-text { flex: 1; min-width: 0; }
.sheet-row .row-title { font-size: 15px; color: var(--wa-text); }
.sheet-row .row-desc { font-size: 13px; color: var(--wa-meta); margin-top: 1px; }
.sheet-row .radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #8696a0; flex: none; }

/* Input bar */
.inputbar {
  flex: none;
  display: flex; align-items: flex-end; gap: 6px;
  padding: 6px 8px 24px;
  background: transparent;
}
.input-pill {
  flex: 1; display: flex; align-items: center;
  background: #fff; border-radius: 24px; padding: 2px 4px;
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
  min-height: 46px;
}
.input-pill .icon-btn { color: #54656f; }
.input-pill input {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent;
  font-size: 15px; padding: 10px 4px;
}
.send {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: var(--wa-green); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.send svg { fill: #fff; }
.send .i-send { display: none; }
.inputbar.has-text .send .i-send { display: block; }
.inputbar.has-text .send .i-mic { display: none; }

/* ---------- Behind the scenes ---------- */
.pipeline {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  font-size: 11.5px; margin-bottom: 12px;
}
.pipeline span { background: #eef6f4; color: var(--wa-teal-dark); padding: 3px 8px; border-radius: 6px; font-weight: 500; }
.pipeline i { color: var(--muted); font-style: normal; }
.bts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 10px; }
.bts-item {
  border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px; animation: pop .2s ease-out;
}
.bts-item.ai { border-left: 3px solid var(--info); }
.bts-item.scripted { border-left: 3px solid var(--wa-green); }
.bts-item.fallback { border-left: 3px solid var(--warn); }
.bts-q { font-weight: 600; color: var(--ink); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bts-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tag { font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: #eef1f0; color: #3e4d49; text-transform: uppercase; letter-spacing: .03em; }
.tag.route-ai { background: #e3eefc; color: #1d5bb8; }
.tag.route-scripted { background: #e0f4ef; color: #0b6b5f; }
.tag.warn { background: #fff1d6; color: #8a5a00; }
.tag.bad { background: #fde2e1; color: #a12c2c; }
.bts-grid { display: grid; grid-template-columns: 82px 1fr; gap: 4px 8px; margin: 0; }
.bts-grid dt { color: var(--muted); }
.bts-grid dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.conf { display: flex; align-items: center; gap: 6px; }
.conf-bar { flex: 1; height: 6px; border-radius: 3px; background: #eef1f0; overflow: hidden; max-width: 110px; }
.conf-bar span { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.conf-bar.low span { background: var(--bad); }
.conf-bar.mid span { background: var(--warn); }
.empty { font-size: 13px; line-height: 1.5; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi { background: #f6f8f7; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.kpi-val { font-size: 22px; font-weight: 700; color: var(--wa-teal-dark); font-variant-numeric: tabular-nums; transition: color .3s; }
.kpi-val.bump { color: var(--wa-bright); }
.kpi-label { font-size: 11.5px; color: var(--muted); }
.top-intents { margin-top: 12px; }
.intent-bars { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.intent-row { display: grid; grid-template-columns: 90px 1fr 22px; align-items: center; gap: 8px; font-size: 12px; }
.intent-row .bar { height: 7px; border-radius: 4px; background: #eef1f0; overflow: hidden; }
.intent-row .bar span { display: block; height: 100%; background: var(--wa-green); transition: width .3s; }
.intent-row b { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Agent view ---------- */
.agent { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.agent-state { font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 99px; background: #eef1f0; color: var(--muted); }
.agent-state.live { background: #fde2e1; color: #a12c2c; animation: pulse 1.6s infinite; }
.agent-state.done { background: #d8f5e2; color: #12733a; }
@keyframes pulse { 50% { opacity: .6; } }
.agent-empty { font-size: 13px; line-height: 1.5; }
.agent-body { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.agent-ctx { display: grid; grid-template-columns: 96px 1fr; gap: 4px 8px; font-size: 12.5px; margin: 0; background: #f6f8f7; padding: 10px; border-radius: 10px; }
.agent-ctx dt { color: var(--muted); }
.agent-ctx dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.agent-transcript {
  flex: 1; overflow-y: auto; min-height: 140px; max-height: 300px;
  border: 1px solid var(--panel-border); border-radius: 10px; padding: 8px;
  display: flex; flex-direction: column; gap: 4px; font-size: 12.5px;
}
.tline { flex-shrink: 0; padding: 5px 8px; border-radius: 6px; max-width: 92%; white-space: pre-wrap; overflow-wrap: anywhere; }
.tline small { display: block; font-size: 10.5px; color: var(--muted); }
.tline.user { background: var(--wa-out-bubble); align-self: flex-end; }
.tline.bot { background: #f1f3f2; align-self: flex-start; }
.tline.agent { background: #e1f3fb; align-self: flex-start; }
.tline.system { align-self: center; color: var(--muted); font-size: 11.5px; }
.agent-reply { display: flex; gap: 6px; }
.agent-reply input { flex: 1; min-width: 0; border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px 10px; outline: none; }
.agent-reply input:focus { border-color: var(--wa-green); }
.agent-reply button, .agent-end {
  border: 0; border-radius: 8px; padding: 8px 12px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.agent-reply button { background: var(--wa-green); color: #fff; }
.agent-end { background: #eef1f0; color: var(--ink); }
.agent-end:hover { background: #e2e6e4; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1c2b27; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: pop .2s;
  max-width: calc(100vw - 32px);
}

/* ---------- Responsive ---------- */
@media (max-width: 1279px) {
  .stage, .stage.hide-bts, .stage.hide-right, .stage.hide-bts.hide-right {
    grid-template-columns: 1fr; max-width: 640px; gap: 16px;
  }
  .tabs {
    display: flex; justify-content: center; gap: 4px; flex-wrap: wrap;
    padding: 12px 16px 0;
  }
  .tabs button {
    border: 1px solid var(--panel-border); background: #fff; padding: 6px 14px; border-radius: 99px;
    font-size: 13px; cursor: pointer;
  }
  .tabs button.active { background: var(--wa-teal-dark); color: #fff; border-color: var(--wa-teal-dark); }
  #btnToggleBts, #btnToggleRight { display: none; }
  .stage [data-panel] { display: none; }
  .stage .panel-right { display: none; }
  .stage[data-tab="phone"] .phone-wrap { display: flex; }
  .stage[data-tab="bts"] .panel-left { display: block !important; }
  .stage[data-tab="agent"] .panel-right, .stage[data-tab="dash"] .panel-right { display: flex !important; }
  .stage[data-tab="agent"] .agent { display: flex; }
  .stage[data-tab="dash"] .dash { display: block; }
  .stage[data-tab="agent"] .panel-right > section + section { border-top: 0; }
  .panel { max-height: none; }
}

@media (max-width: 600px) {
  body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
  .topbar { padding: 8px 16px; gap: 6px; flex: none; }
  .brand strong, .brand .muted { display: none; }
  .mode-switch { width: 100%; }
  .mode-switch button { flex: 1; padding: 6px 8px; }
  .brand:has(.mode-badge[hidden]) { display: none; }
  .controls { flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; }
  .ctl { padding: 5px 10px; font-size: 12px; white-space: nowrap; flex: none; }
  .chips { display: none; }
  .tabs { padding: 6px 16px; flex: none; flex-wrap: nowrap; }
  .tabs button { padding: 4px 10px; font-size: 12px; white-space: nowrap; }
  .stage { flex: 1; min-height: 0; display: block; padding: 0; overflow-y: auto; }
  .stage:not([data-tab="phone"]) { padding: 12px 16px; }
  .stage[data-tab="phone"] { overflow: hidden; }
  .stage[data-tab="phone"] .phone-wrap { display: block; height: 100%; }
  .phone {
    width: 100%; height: 100%;
    border: 0; border-radius: 0; box-shadow: none;
  }
  .notch, .home-indicator, .statusbar { display: none; }
  .chat-header { padding-top: 8px; }
  .inputbar { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

/* ---------- Home screen (chat list) ---------- */
.avatar img { width: 32px; height: 32px; object-fit: contain; }
.home-view {
  position: absolute; left: 0; right: 0; top: 44px; bottom: 0; z-index: 8;
  display: flex; flex-direction: column;
  background: #fff; color: var(--wa-text);
  animation: fade .18s ease-out;
}
.home-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 6px; background: #fff;
}
.home-header h2 { margin: 0; font-size: 24px; font-weight: 700; color: var(--wa-green); }
.home-actions { display: flex; gap: 18px; }
.home-actions svg { fill: #54656f; }
.home-search {
  margin: 6px 14px 4px; padding: 9px 14px; border-radius: 22px; background: #f0f2f5;
  display: flex; align-items: center; gap: 10px; color: #8696a0; font-size: 15px;
}
.home-search svg { fill: #8696a0; }
.home-filters { display: flex; gap: 6px; padding: 6px 14px 8px; overflow-x: auto; scrollbar-width: none; }
.home-filters span { flex: none; padding: 5px 12px; border-radius: 16px; background: #f0f2f5; color: #54656f; font-size: 13px; }
.home-filters span.active { background: #d9fdd3; color: #0b6b5f; font-weight: 600; }
.chat-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.cl-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  border: 0; background: none; text-align: left; cursor: pointer;
  padding: 9px 14px; font: inherit; color: inherit;
}
.cl-row:hover { background: #f5f6f6; }
.cl-row.eci { background: #f3fbf6; }
.cl-row.eci:hover { background: #e9f7ee; }
.cl-avatar {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 16px;
}
.cl-avatar.logo { background: #fff; border: 1px solid #e3e6e8; }
.cl-avatar.logo img { width: 38px; height: 38px; object-fit: contain; }
.cl-body { flex: 1; min-width: 0; border-bottom: 1px solid #f0f2f5; padding-bottom: 10px; margin-bottom: -10px; }
.cl-top, .cl-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cl-name { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 16px; font-weight: 500; }
.cl-name > span, .cl-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-verified { width: 16px; height: 16px; flex: none; }
.cl-time { flex: none; font-size: 12px; color: #667781; }
.cl-time.unread { color: #1fa855; font-weight: 600; }
.cl-bottom { margin-top: 2px; }
.cl-msg { display: flex; align-items: center; gap: 3px; min-width: 0; font-size: 14px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-msg.typing { color: #1fa855; font-weight: 500; }
.cl-ticks { width: 16px; height: 11px; flex: none; fill: #8696a0; }
.cl-ticks.read { fill: var(--wa-tick-read); }
.cl-right { flex: none; display: flex; align-items: center; }
.cl-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: #25d366; color: #fff; font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.cl-pin { width: 16px; height: 16px; fill: #8696a0; }
.home-nav {
  flex: none; display: flex; justify-content: space-around;
  padding: 8px 6px 26px; border-top: 1px solid #e9edef; background: #fff;
}
.home-nav span { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; color: #54656f; }
.home-nav span svg { fill: #54656f; padding: 3px 16px; box-sizing: content-box; border-radius: 16px; }
.home-nav span.active { color: var(--wa-text); font-weight: 600; }
.home-nav span.active svg { fill: #0b6b5f; background: #d9fdd3; }
.home-nav b {
  position: absolute; top: -4px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: #25d366; color: #fff; font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}
.phone.on-home .statusbar { background: #fff; color: var(--wa-text); }
@media (max-width: 600px) {
  .home-view { top: 0; }
  .home-nav { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}
/* Fit the full "Election Commission of India" name in the chat header */
.header-actions svg:not(:last-child) { display: none; }
.header-actions { gap: 12px; }
.who .name { font-size: 15px; }
