:root {
  color-scheme: dark;
  --bg: #07110d;
  --bg-deep: #040907;
  --surface: rgba(14, 30, 24, 0.86);
  --surface-strong: #10251c;
  --surface-soft: rgba(20, 43, 33, 0.58);
  --surface-hover: rgba(35, 75, 55, 0.48);
  --line: rgba(164, 213, 183, 0.14);
  --line-strong: rgba(164, 213, 183, 0.26);
  --text: #edf8f0;
  --muted: #9db5a6;
  --muted-strong: #c3d8c9;
  --accent: #7df0aa;
  --accent-strong: #31d77b;
  --accent-ink: #052011;
  --warning: #ffd27d;
  --danger: #ff9b9b;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-deep);
  color: var(--text);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg-deep); }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 85% -5%, rgba(48, 145, 89, 0.24), transparent 32rem),
    radial-gradient(circle at 5% 20%, rgba(29, 93, 68, 0.18), transparent 28rem),
    linear-gradient(145deg, var(--bg) 0%, var(--bg-deep) 72%);
  color: var(--text);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 48px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(9, 22, 16, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand, .top-actions, .toolbar, .token-row, .connection-meta, .draft-actions, .conversation-top, .conversation-side { display: flex; align-items: center; }
.brand { gap: 12px; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--accent), #b3ffd0);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: -0.08em;
  box-shadow: 0 8px 24px rgba(49, 215, 123, 0.22);
}
.brand-name { color: var(--text); font-size: 14px; font-weight: 800; letter-spacing: -0.01em; }
.brand-sub { margin-top: 3px; color: var(--muted); font-size: 11px; }
.top-actions { gap: 10px; }
.live-sync { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.live-sync::before { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); content: ""; box-shadow: 0 0 10px rgba(125, 240, 170, 0.8); }
.live-sync.stale { color: var(--warning); }
.live-sync.stale::before { background: var(--warning); box-shadow: 0 0 10px rgba(255, 210, 125, 0.75); }
.pill, .agent-badge, .test-badge, .state-label, .conversation-label, .unread { border-radius: 999px; white-space: nowrap; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid rgba(125, 240, 170, 0.22);
  background: rgba(125, 240, 170, 0.08);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}
.pill::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; box-shadow: 0 0 12px currentColor; }
.ghost-button, .primary-button {
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 750;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
.ghost-button { background: rgba(255, 255, 255, 0.035); color: var(--muted-strong); }
.ghost-button:hover:not(:disabled) { transform: translateY(-1px); border-color: rgba(125, 240, 170, 0.42); background: rgba(125, 240, 170, 0.09); color: var(--text); }
.primary-button { border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: var(--accent-ink); box-shadow: 0 8px 18px rgba(49, 215, 123, 0.16); }
.primary-button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(49, 215, 123, 0.28); }

.layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(330px, 0.85fr); gap: 18px; margin-top: 18px; align-items: start; }
.main-column, .side-column { display: grid; gap: 18px; min-width: 0; }
.side-column { position: sticky; top: 18px; }
.intro-row { display: flex; justify-content: space-between; gap: 24px; align-items: end; padding: 25px 4px 5px; }
.eyebrow { margin: 0 0 9px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { max-width: 760px; margin-bottom: 12px; color: var(--text); font-size: clamp(28px, 4vw, 50px); line-height: 1.02; letter-spacing: -0.055em; }
h2 { margin-bottom: 0; color: var(--text); font-size: 17px; line-height: 1.2; letter-spacing: -0.025em; }
.intro-copy, .panel-copy { color: var(--muted); font-size: 12px; line-height: 1.65; }
.intro-copy { max-width: 640px; margin-bottom: 0; }
.secure-note { display: flex; align-items: center; gap: 8px; padding-bottom: 5px; color: var(--muted-strong); font-size: 11px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px rgba(125, 240, 170, 0.8); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat-card, .panel { border: 1px solid var(--line); background: linear-gradient(145deg, rgba(19, 42, 31, 0.86), rgba(8, 21, 15, 0.88)); box-shadow: var(--shadow); }
.stat-card { min-height: 104px; padding: 15px; border-radius: 16px; }
.stat-card span, .stat-card small { display: block; color: var(--muted); font-size: 10px; }
.stat-card strong { display: block; margin: 10px 0 4px; color: var(--text); font-size: 26px; line-height: 1; letter-spacing: -0.06em; }
.stat-card small { color: var(--muted-strong); }
.panel { overflow: hidden; border-radius: 18px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 19px 14px; }
.panel-copy { margin: 0 19px 15px; }
.toolbar { gap: 8px; }

input, textarea, select { width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; background: rgba(3, 11, 7, 0.48); color: var(--text); font-size: 12px; }
input, select { min-height: 36px; padding: 8px 10px; }
textarea { resize: vertical; min-height: 94px; padding: 11px 12px; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: #6e8878; }
select { width: auto; min-width: 104px; color: var(--muted-strong); }

.conversation-list { border-top: 1px solid var(--line); }
.conversation-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 14px 19px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; transition: background 160ms ease, padding 160ms ease; }
.conversation-row:hover, .conversation-row.selected { padding-left: 23px; background: var(--surface-hover); }
.conversation-row.selected { box-shadow: inset 3px 0 0 var(--accent); }
.conversation-main { min-width: 0; flex: 1; }
.conversation-top { gap: 8px; min-width: 0; }
.conversation-name { overflow: hidden; color: var(--muted-strong); font-size: 12px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.conversation-label { padding: 4px 7px; background: rgba(255, 210, 125, 0.09); color: var(--warning); font-size: 9px; font-weight: 750; }
.conversation-message { display: block; overflow: hidden; margin-top: 6px; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-side { flex-direction: column; align-items: flex-end; gap: 7px; }
.conversation-time { color: var(--muted); font-size: 10px; white-space: nowrap; }
.unread { min-width: 20px; padding: 3px 6px; background: rgba(125, 240, 170, 0.13); color: var(--accent); font-size: 9px; text-align: center; }

.thread-header { align-items: center; border-bottom: 1px solid var(--line); }
.muted { color: var(--muted); }
.tiny { font-size: 10px; }
.thread-header .muted { margin: 7px 0 0; font-size: 11px; }
.alias-row { display: flex; align-items: center; gap: 7px; margin-top: 10px; max-width: 430px; }
.alias-row label { flex: 0 0 auto; }
.alias-row input { min-width: 0; min-height: 32px; }
.alias-row .ghost-button { flex: 0 0 auto; min-height: 32px; padding: 6px 10px; }
.message-list { display: flex; flex-direction: column; gap: 10px; min-height: 180px; max-height: 440px; overflow-y: auto; padding: 18px 19px; background: rgba(3, 11, 7, 0.2); }
.message { align-self: flex-start; max-width: min(78%, 560px); padding: 11px 13px; border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; background: var(--surface-soft); color: var(--muted-strong); font-size: 12px; line-height: 1.55; white-space: pre-wrap; }
.message.outbound { align-self: flex-end; border-color: rgba(125, 240, 170, 0.2); border-radius: 14px 14px 4px 14px; background: rgba(47, 135, 83, 0.25); color: var(--text); }
.message-meta { display: block; margin-top: 7px; color: var(--muted); font-size: 9px; }
.empty-state { display: grid; min-height: 100px; place-items: center; padding: 28px; color: var(--muted); font-size: 11px; text-align: center; }

.agent-badge, .test-badge { padding: 6px 8px; background: rgba(125, 240, 170, 0.08); color: var(--accent); font-size: 9px; font-weight: 800; }
.test-badge { background: rgba(255, 210, 125, 0.09); color: var(--warning); }
.agent-panel form { display: grid; gap: 8px; padding: 0 19px; }
label { color: var(--muted-strong); font-size: 10px; font-weight: 700; }
.agent-panel .primary-button { justify-self: start; }
.inline-status { min-height: 18px; margin: 10px 19px 0; color: var(--warning); font-size: 10px; }
.draft-card { margin: 5px 19px 19px; padding: 13px; border: 1px solid rgba(125, 240, 170, 0.19); border-radius: 13px; background: rgba(125, 240, 170, 0.045); }
.draft-label { margin-bottom: 8px; color: var(--accent); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; }
.draft-card textarea { min-height: 130px; }
.draft-actions { justify-content: flex-end; gap: 8px; margin-top: 10px; }
.source-list { display: grid; gap: 5px; margin-top: 9px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.analysis-box { display: grid; gap: 3px; margin-top: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: rgba(3, 11, 7, 0.22); font-size: 10px; line-height: 1.45; }
.analysis-box strong { color: var(--muted-strong); font-size: 10px; }
.analysis-box .risk { color: var(--warning); }

.autopilot-panel { border-color: rgba(255, 210, 125, 0.2); }
.autopilot-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 19px 10px; }
.toggle-label { display: flex; align-items: center; gap: 8px; color: var(--muted-strong); font-size: 11px; }
.toggle-label input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-strong); }
.autopilot-copy { margin: 0 19px 10px; color: var(--warning); font-size: 10px; line-height: 1.5; }
.autopilot-rules { display: grid; gap: 4px; margin: 0 19px 19px; color: var(--muted); font-size: 10px; line-height: 1.45; }

.connection-panel .panel-copy, .price-panel .panel-copy { margin-bottom: 17px; }
.connection-panel > #reconnect-button { margin: 0 19px 15px; }
.state-label { padding: 6px 9px; background: rgba(125, 240, 170, 0.09); color: var(--accent); font-size: 10px; font-weight: 800; }
.qr-box { margin: 0 19px 15px; padding: 15px; border: 1px dashed rgba(125, 240, 170, 0.25); border-radius: 13px; background: rgba(0, 0, 0, 0.16); }
.qr-box p { margin: 0 0 13px; color: var(--muted-strong); font-size: 11px; line-height: 1.5; }
.qr-box img { display: block; width: min(100%, 210px); margin: 0 auto; border-radius: 8px; background: #fff; }
.connection-meta { gap: 10px; margin: 0 19px 19px; }
.connection-meta > div { flex: 1; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(3, 11, 7, 0.25); }
.connection-meta span, .connection-meta strong { display: block; }
.connection-meta span { margin-bottom: 5px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; }
.connection-meta strong { color: var(--muted-strong); font-size: 12px; }
.price-preview { margin: 0 19px 19px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: rgba(3, 11, 7, 0.24); font-size: 11px; line-height: 1.5; }
.audit-list { display: grid; gap: 0; margin: 0 19px 19px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: rgba(3, 11, 7, 0.24); }
.audit-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 10px; border-bottom: 1px solid var(--line); color: var(--muted-strong); font-size: 10px; }
.audit-row:last-child { border-bottom: 0; }
.audit-row span { color: var(--muted); white-space: nowrap; }
.test-panel form { display: grid; gap: 8px; padding: 0 19px; }
.test-panel .ghost-button { justify-self: start; }

.token-box { margin: 0 19px 14px; padding: 12px; border: 1px dashed rgba(255, 210, 125, 0.28); border-radius: 10px; background: rgba(255, 210, 125, 0.05); }
.token-box label { display: block; margin-bottom: 7px; color: var(--warning); font-size: 10px; }
.token-row { gap: 7px; }
.token-row input { min-width: 0; flex: 1; }
.token-box .tiny { margin: 7px 0 0; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; max-width: min(360px, calc(100vw - 44px)); padding: 11px 13px; border: 1px solid rgba(125, 240, 170, 0.28); border-radius: 11px; background: #102b1e; color: var(--text); font-size: 11px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(12px); transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.hidden { display: none !important; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .side-column { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .agent-panel { grid-column: span 2; }
}
@media (max-width: 680px) {
  .shell { width: min(100% - 24px, 600px); padding-top: 12px; }
  .topbar, .intro-row { align-items: flex-start; flex-direction: column; }
  .topbar { gap: 13px; }
  .top-actions { width: 100%; justify-content: space-between; }
  .intro-row { padding-top: 15px; }
  h1 { font-size: 34px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-column { display: grid; grid-template-columns: 1fr; }
  .agent-panel { grid-column: auto; }
  .panel-head { flex-wrap: wrap; }
  .toolbar { width: 100%; }
  .toolbar input { min-width: 0; }
  .message { max-width: 90%; }
}
