:root {
  --bg: #0b0f14;
  --card: #141a22;
  --line: #222c38;
  --fg: #e8eef6;
  --muted: #8a97a8;
  --accent: #4f9cff;
  --ok: #35c26b;
  --warn: #f0a92e;
  --bad: #f2564b;
  --radius: 14px;
  font-synthesis: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }

/* ---- login ---- */
body.login { align-items: center; justify-content: center; }
body.login form {
  width: min(92vw, 340px); display: grid; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px;
}
body.login h1 { margin: 0 0 4px; font-size: 22px; }
body.login input, button { font: inherit; }
body.login input {
  background: #0e141b; border: 1px solid var(--line); color: var(--fg);
  border-radius: 10px; padding: 12px;
}
body.login button, .composer button {
  background: var(--accent); color: #04121f; border: 0; border-radius: 10px;
  padding: 12px; font-weight: 600;
}
.muted { color: var(--muted); margin: 0; }
.err { color: var(--bad); min-height: 18px; margin: 0; font-size: 13px; }

/* ---- header ---- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px calc(10px);
  background: rgba(11,15,20,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.chips { display: flex; gap: 6px; flex: 1; overflow: hidden; }
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.chip.ok { color: var(--ok); border-color: rgba(53,194,107,.35); }
.chip.bad { color: var(--bad); border-color: rgba(242,86,75,.35); }
.icon {
  background: none; border: 1px solid var(--line); color: var(--fg);
  width: 34px; height: 34px; border-radius: 10px; font-size: 17px;
}

/* ---- tabs ---- */
.tabs {
  position: sticky; top: 55px; z-index: 19;
  display: flex; gap: 6px; padding: 8px 10px;
  overflow-x: auto; scrollbar-width: none;
  background: rgba(11,15,20,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; white-space: nowrap;
  background: #10161e; border: 1px solid var(--line); color: var(--muted);
  padding: 8px 12px; border-radius: 999px; font-size: 13px;
}
.tab.active { color: var(--fg); border-color: var(--accent); background: #12202f; }
.badge {
  display: none; margin-left: 6px; font-size: 11px;
  background: var(--accent); color: #04121f; border-radius: 999px; padding: 1px 6px;
}
.badge.on { display: inline-block; }

/* ---- panes ---- */
main { flex: 1; min-height: 0; }
.pane { display: none; padding: 12px; }
.pane.active { display: block; }
.chatpane.active { display: flex; flex-direction: column; height: calc(100vh - 110px); padding: 10px 12px 0; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
}
.row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.row.sub { margin-top: 6px; font-size: 13px; }
.name { font-weight: 600; word-break: break-word; }
.stage {
  font-size: 11px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}
.phone { color: var(--accent); text-decoration: none; }
.ext { color: var(--muted); text-decoration: none; font-size: 12px; }
.msg { color: var(--muted); margin: 8px 0 10px; white-space: pre-wrap; }
textarea {
  width: 100%; background: #0e141b; border: 1px solid var(--line); color: var(--fg);
  border-radius: 10px; padding: 10px; font: inherit; resize: vertical; min-height: 64px;
}
.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions button {
  flex: 1; background: #12202f; color: var(--fg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; font-weight: 600;
}
.actions button.primary { background: var(--accent); color: #04121f; border-color: transparent; }
.actions button:disabled { opacity: .5; }
.empty { color: var(--muted); text-align: center; padding: 34px 10px; }
.log { font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); white-space: pre-wrap; }

/* ---- chat ---- */
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-bottom: 10px; }
.bubble { max-width: 85%; padding: 10px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.bubble.me { align-self: flex-end; background: #174b7a; }
.bubble.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.bubble.sys { align-self: center; background: none; color: var(--muted); font-size: 12px; }
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 0 calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg);
}
.composer textarea { min-height: 42px; max-height: 140px; }
.composer button { width: 46px; height: 42px; padding: 0; font-size: 16px; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #1d2735; border: 1px solid var(--line); color: var(--fg);
  padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .2s; font-size: 13px; max-width: 90vw;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
