/* ===== SUGM Explorer — styles ===== */
:root {
  --bg: #0e1117;
  --bg-2: #151a23;
  --bg-3: #1c232f;
  --panel: #161b25;
  --line: #262e3b;
  --txt: #e6ebf2;
  --txt-dim: #9aa6b8;
  --txt-faint: #66718a;
  --accent: #6d8cff;
  --accent-2: #4a6bff;
  --green: #2bb673;
  --amber: #e8a13a;
  --red: #e5564b;
  --blue: #3a9ad8;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
}
[data-theme="light"] {
  --bg: #f4f6fb; --bg-2: #ffffff; --bg-3: #eef1f7; --panel: #ffffff;
  --line: #e1e6ef; --txt: #1a2230; --txt-dim: #5b6678; --txt-faint: #8b96a8;
  --shadow: 0 8px 30px rgba(20,30,60,.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--txt);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
button { font-family: inherit; cursor: pointer; }
select, input { font-family: inherit; }

.app { display: grid; grid-template-columns: 230px 1fr; height: 100vh; }

/* ===== Nav ===== */
.nav {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand-mark { font-size: 22px; color: var(--accent); }
.brand-txt strong { display: block; font-size: 16px; letter-spacing: .5px; }
.brand-txt small { color: var(--txt-faint); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; }
.nav-links { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; color: var(--txt-dim);
  padding: 10px 12px; border-radius: 9px; text-align: left; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--bg-3); color: var(--txt); }
.nav-item.active { background: var(--accent-2); color: #fff; }
.nav-item .ni { font-size: 15px; width: 18px; text-align: center; }
.nav-foot { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; }
.ghost-btn { background: var(--bg-3); border: 1px solid var(--line); color: var(--txt-dim); padding: 7px 10px; border-radius: 8px; font-size: 12.5px; }
.ghost-btn:hover { color: var(--txt); }
.health { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--txt-faint); padding: 0 4px; }
.health .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--txt-faint); }
.health.ok .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.health.down .dot { background: var(--red); }

/* ===== Main / topbar ===== */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--bg-2);
  gap: 16px; flex-wrap: wrap;
}
.tb-left { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--txt-faint); }
.field select {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--txt);
  padding: 7px 10px; border-radius: 8px; min-width: 200px; font-size: 13px;
}
.id-meta { font-size: 12px; color: var(--txt-dim); font-family: var(--mono); align-self: center; }
.tb-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.view-title { font-size: 13px; color: var(--txt-faint); letter-spacing: 1px; text-transform: uppercase; }

/* role-scoped surface indicator (top bar) */
.role-surface {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 20px;
  padding: 5px 12px; font-size: 12px;
}
.role-surface .rs-role {
  font-weight: 600; color: var(--accent); text-transform: none;
  letter-spacing: .3px;
}
.role-surface .rs-count { color: var(--txt-dim); }
.role-surface .rs-risks { display: inline-flex; gap: 4px; }
.role-surface .rs-risks .badge { padding: 1px 6px; }

/* ===== Views ===== */
.view { flex: 1; min-height: 0; overflow: auto; padding: 20px; }
.view.hidden, .hidden { display: none !important; }

/* ===== Decision strip (shared) ===== */
.decision-strip {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.ds-empty, .vt-empty, .replay-empty, .ds-row .muted { color: var(--txt-faint); font-size: 12.5px; }
.ds-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ds-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--txt-faint); width: 64px; }
.ds-intent { font-family: var(--mono); font-size: 12.5px; color: var(--txt); }
.badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  letter-spacing: .5px; text-transform: uppercase; border: 1px solid transparent;
}
.badge.risk-LOW { background: rgba(43,182,115,.15); color: var(--green); border-color: rgba(43,182,115,.4); }
.badge.risk-MEDIUM { background: rgba(232,161,58,.15); color: var(--amber); border-color: rgba(232,161,58,.4); }
.badge.risk-HIGH { background: rgba(229,86,75,.15); color: var(--red); border-color: rgba(229,86,75,.4); }
.badge.risk-CRITICAL { background: rgba(229,86,75,.28); color: #ff8a80; border-color: var(--red); }
.badge.dec-execute { background: rgba(43,182,115,.15); color: var(--green); border-color: rgba(43,182,115,.4); }
.badge.dec-clarify { background: rgba(232,161,58,.15); color: var(--amber); border-color: rgba(232,161,58,.4); }
.badge.dec-block, .badge.dec-escalate { background: rgba(229,86,75,.15); color: var(--red); border-color: rgba(229,86,75,.4); }
.badge.dec-notify { background: rgba(58,154,216,.15); color: var(--blue); border-color: rgba(58,154,216,.4); }
.badge.dec-continue { background: var(--bg-3); color: var(--txt-dim); border-color: var(--line); }
.ds-vr { font-size: 11.5px; color: var(--amber); }
.ds-cid { font-family: var(--mono); font-size: 11px; color: var(--txt-faint); }

/* ===== VOICE ===== */
.voice-wrap { display: grid; grid-template-columns: 1fr 360px; gap: 20px; height: 100%; }
.voice-side { display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow: auto; }
.phone {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden; min-height: 0;
}
.phone-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; background: linear-gradient(135deg, #1d2740, #141a28);
  border-bottom: 1px solid var(--line);
}
.callee { display: flex; align-items: center; gap: 12px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--accent-2); color: #fff; display: grid; place-items: center; font-weight: 700; }
.callee-name { font-weight: 600; }
.call-state { font-size: 12px; color: var(--txt-dim); }
.call-state.connected { color: var(--green); }
.call-timer { font-family: var(--mono); font-size: 13px; color: var(--txt-dim); }
.waveform {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  height: 80px; background: var(--bg-3); border-bottom: 1px solid var(--line);
}
.waveform span { width: 5px; height: 10px; background: var(--accent); border-radius: 4px; opacity: .35; }
.waveform.speaking span { animation: wave 1s ease-in-out infinite; opacity: 1; }
.waveform.speaking span:nth-child(2n) { animation-delay: .12s; }
.waveform.speaking span:nth-child(3n) { animation-delay: .24s; }
.waveform.speaking span:nth-child(4n) { animation-delay: .36s; }
.waveform.speaking span:nth-child(5n) { animation-delay: .48s; }
@keyframes wave { 0%,100% { height: 10px; } 50% { height: 56px; } }
.call-actions { display: flex; justify-content: center; padding: 14px; gap: 12px; }
.call-btn { border: 0; border-radius: 24px; padding: 11px 26px; font-weight: 600; font-size: 14px; color: #fff; }
.call-btn.dial { background: var(--green); }
.call-btn.hangup { background: var(--red); }
.phone-transcript { flex: 1; overflow: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.vt-line { max-width: 82%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4; }
.vt-line.user { align-self: flex-end; background: var(--accent-2); color: #fff; border-bottom-right-radius: 4px; }
.vt-line.agent { align-self: flex-start; background: var(--bg-3); border-bottom-left-radius: 4px; }
.speak-bar { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.speak-bar input { flex: 1; background: var(--bg-3); border: 1px solid var(--line); color: var(--txt); padding: 10px 12px; border-radius: 22px; }
.speak-bar button { background: var(--accent-2); color: #fff; border: 0; border-radius: 22px; padding: 10px 18px; font-weight: 600; }
.speak-bar input:disabled, .speak-bar button:disabled { opacity: .45; cursor: not-allowed; }
.card-stream { display: flex; flex-direction: column; gap: 12px; }

/* ===== WHATSAPP ===== */
.wa-wrap { display: grid; grid-template-columns: 1fr 360px; gap: 20px; height: 100%; }
.wa-phone {
  background: #0b141a; border: 1px solid var(--line); border-radius: 16px;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow); min-height: 0;
}
.wa-header { display: flex; align-items: center; gap: 12px; background: #1f2c33; padding: 12px 16px; }
.wa-avatar { width: 38px; height: 38px; border-radius: 50%; background: #25d366; color: #04321b; display: grid; place-items: center; font-weight: 700; }
.wa-name { color: #e9edef; font-weight: 600; }
.wa-sub { color: #8696a0; font-size: 11.5px; }
.wa-body {
  flex: 1; overflow: auto; padding: 16px;
  background: #0b141a;
  background-image: radial-gradient(rgba(255,255,255,.02) 1px, transparent 1px);
  background-size: 18px 18px;
  display: flex; flex-direction: column; gap: 8px;
}
.wa-bubble { max-width: 78%; padding: 8px 11px; border-radius: 10px; font-size: 13.5px; line-height: 1.45; position: relative; color: #e9edef; }
.wa-bubble.in { align-self: flex-start; background: #202c33; border-top-left-radius: 3px; }
.wa-bubble.out { align-self: flex-end; background: #005c4b; border-top-right-radius: 3px; }
.wa-time { display: block; font-size: 10px; color: rgba(233,237,239,.5); text-align: right; margin-top: 3px; }
.wa-input { display: flex; gap: 8px; padding: 10px 12px; background: #1f2c33; }
.wa-input input { flex: 1; background: #2a3942; border: 0; color: #e9edef; padding: 10px 14px; border-radius: 22px; }
.wa-send { background: #25d366; color: #04321b; border: 0; width: 42px; height: 42px; border-radius: 50%; font-size: 16px; }
.wa-action {
  margin-top: 8px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  color: #8bd4ff; width: 100%; padding: 9px; border-radius: 8px; font-weight: 600; font-size: 13px;
}
.wa-action:hover { background: rgba(255,255,255,.12); }

/* ===== PORTAL ===== */
.portal-wrap { display: grid; grid-template-columns: 1fr 360px; gap: 20px; height: 100%; }
.portal-chat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; border-bottom: 1px solid var(--line); }
.chip { background: var(--bg-3); border: 1px solid var(--line); color: var(--txt-dim); padding: 7px 13px; border-radius: 20px; font-size: 12.5px; }
.chip:hover { border-color: var(--accent); color: var(--txt); }
.portal-body { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.p-msg { max-width: 80%; padding: 10px 13px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; }
.p-msg.user { align-self: flex-end; background: var(--accent-2); color: #fff; border-bottom-right-radius: 4px; }
.p-msg.agent { align-self: flex-start; background: var(--bg-3); border-bottom-left-radius: 4px; }
.portal-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.portal-input input { flex: 1; background: var(--bg-3); border: 1px solid var(--line); color: var(--txt); padding: 11px 14px; border-radius: 10px; }
.portal-input button { background: var(--accent-2); color: #fff; border: 0; border-radius: 10px; padding: 11px 20px; font-weight: 600; }

/* ===== Visual cards (shared) ===== */
.vcard { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; max-width: 100%; }
.wa-bubble .vcard, .p-msg .vcard { background: rgba(255,255,255,.05); margin-top: 6px; }
.vcard-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--txt-faint); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.vcard-title .vc-ico { font-size: 13px; }
.bal-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.bal-cell { flex: 1; min-width: 70px; background: var(--bg-3); border-radius: 8px; padding: 9px; text-align: center; }
.bal-type { font-size: 11px; color: var(--txt-faint); letter-spacing: 1px; }
.bal-num { font-size: 20px; font-weight: 700; color: var(--accent); }
.bal-sub { font-size: 10px; color: var(--txt-faint); }
.kv { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--txt-faint); }
.kv .v { font-family: var(--mono); }
.status-pill { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 11px; font-weight: 700; }
.status-PENDING { background: rgba(232,161,58,.18); color: var(--amber); }
.status-APPROVED { background: rgba(43,182,115,.18); color: var(--green); }
.status-CANCELLED, .status-REJECTED { background: rgba(229,86,75,.18); color: var(--red); }
.att-bar { height: 8px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.att-bar > i { display: block; height: 100%; background: var(--green); }
.securelink { display: flex; align-items: center; gap: 10px; }
.securelink .lock { font-size: 20px; }
.replay-card .rc-row { font-size: 12px; padding: 5px 0; border-bottom: 1px dashed var(--line); }

/* ===== GOVERNANCE ===== */
.gov-wrap { max-width: 1000px; }
.gov-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 18px; }
.gov-head h2 { margin: 0; }
.gov-version { font-family: var(--mono); font-size: 12.5px; color: var(--txt-faint); }
.gov-version span { color: var(--accent); font-weight: 700; }
.gov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.gov-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.gov-panel h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--txt-faint); }
.gov-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.gov-row:last-child { border-bottom: 0; }
.gov-row label { font-size: 13px; }
.seg { display: inline-flex; background: var(--bg-3); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { background: transparent; border: 0; color: var(--txt-dim); padding: 5px 11px; border-radius: 6px; font-size: 12px; }
.seg button.on { background: var(--accent-2); color: #fff; }
.toggle { position: relative; width: 42px; height: 24px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 14px; transition: background .2s; }
.toggle.on { background: var(--green); }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; }
.toggle.on::after { left: 21px; }
.num-input { width: 64px; background: var(--bg-3); border: 1px solid var(--line); color: var(--txt); padding: 6px 8px; border-radius: 7px; text-align: center; }
.gov-cat { font-family: var(--mono); font-size: 12.5px; }

/* ===== AUDIT ===== */
.audit-wrap { display: flex; flex-direction: column; height: 100%; }
.audit-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.audit-head h2 { margin: 0; }
.audit-split { display: grid; grid-template-columns: 1fr 420px; gap: 16px; flex: 1; min-height: 0; }
.audit-table-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.audit-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.audit-table th { position: sticky; top: 0; background: var(--bg-2); text-align: left; padding: 10px 12px; color: var(--txt-faint); text-transform: uppercase; font-size: 10.5px; letter-spacing: 1px; border-bottom: 1px solid var(--line); }
.audit-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
.audit-table tbody tr { cursor: pointer; }
.audit-table tbody tr:hover { background: var(--bg-3); }
.audit-table tbody tr.sel { background: rgba(109,140,255,.12); }
.audit-table .mono { font-family: var(--mono); }
.muted { color: var(--txt-faint); }
.replay { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; overflow: auto; }
.replay-hd { margin-bottom: 12px; }
.replay-hd h3 { margin: 0 0 6px; font-size: 14px; }
.replay-meta { font-family: var(--mono); font-size: 11.5px; color: var(--txt-dim); display: flex; flex-wrap: wrap; gap: 6px 14px; }
.replay-steps { list-style: none; margin: 14px 0 0; padding: 0; position: relative; }
.replay-steps::before { content: ""; position: absolute; left: 11px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.rstep { position: relative; padding: 0 0 16px 34px; }
.rstep .node { position: absolute; left: 4px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--bg-3); border: 2px solid var(--accent); }
.rstep.det .node { border-color: var(--blue); }
.rstep.llm .node { border-color: var(--amber); }
.rstep.stop .node { border-color: var(--red); background: var(--red); }
.rstep-name { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.rstep-kind { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--txt-faint); margin-left: 6px; }
.rstep-dec { font-size: 11px; margin-left: 6px; }
.rstep-snap { margin-top: 4px; font-family: var(--mono); font-size: 11px; color: var(--txt-dim); background: var(--bg-3); border-radius: 6px; padding: 6px 8px; white-space: pre-wrap; word-break: break-word; }
.rstep-ts { font-size: 10px; color: var(--txt-faint); }

/* ===== Responsive ===== */
@media (max-width: 1080px) {
  .voice-wrap, .wa-wrap, .portal-wrap, .audit-split { grid-template-columns: 1fr; }
  .voice-side { max-height: 320px; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 64px 1fr; }
  .brand-txt, .nav-item span:not(.ni), .nav-foot { display: none; }
  .nav-item { justify-content: center; }
}

/* ===== Role-aware "What I can do" surface panel ===== */
.surface-host { display: flex; flex-direction: column; }
.surface-panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.surface-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; font-weight: 600; color: var(--txt);
  padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--line);
}
.surface-head .surface-sub {
  font-size: 11px; font-weight: 500; color: var(--txt-faint);
}
.surface-group { margin-bottom: 12px; }
.surface-group:last-child { margin-bottom: 0; }
.surface-mod {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--txt-faint); margin-bottom: 7px;
}
.surface-mod .sm-ico { font-size: 13px; }
.surface-mod .sm-n {
  margin-left: auto; font-family: var(--mono); font-size: 10.5px;
  color: var(--txt-faint); background: var(--bg-3);
  border: 1px solid var(--line); border-radius: 10px; padding: 0 7px;
}
.surface-chips { display: flex; flex-direction: column; gap: 6px; }
.surf-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  color: var(--txt-dim); padding: 7px 10px; border-radius: 8px; font-size: 12.5px;
  transition: border-color .12s, color .12s, background .12s;
}
.surf-chip:hover { color: var(--txt); border-color: var(--accent); background: var(--bg-2); }
.surf-chip .sc-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.surf-chip .badge { flex: none; padding: 1px 7px; font-size: 9.5px; }

/* risk-tinted left border on quick-action chips (reuses risk palette) */
.risk-bd-LOW { border-left-color: var(--green); }
.risk-bd-MEDIUM { border-left-color: var(--amber); }
.risk-bd-HIGH { border-left-color: var(--red); }
.risk-bd-CRITICAL { border-left-color: #ff8a80; }
.chip.risk-bd-LOW, .chip.risk-bd-MEDIUM, .chip.risk-bd-HIGH, .chip.risk-bd-CRITICAL {
  border-left-width: 3px; border-left-style: solid;
}
