:root {
  color-scheme: dark;
  --bg: #0f141b;
  --surface: #151c25;
  --surface2: #1d2631;
  --line: rgba(255,255,255,.09);
  --text: #edf2f7;
  --muted: #8f9ba8;
  --blue: #0a84ff;
  --yellow: #f6c343;
  --green: #30d158;
  --orange: #ff9f0a;
  --red: #ff453a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button, input, textarea, select {
  font: inherit;
}

button {
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

#app {
  display: grid;
  grid-template-columns: 310px minmax(420px, 1fr) 390px;
  height: 100dvh;
  width: 100vw;
}

.sidebar, .inspector {
  background: rgba(21, 28, 37, .94);
  border-right: 1px solid var(--line);
  min-width: 0;
}
.inspector {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.side-header, .chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.side-header h1, .chat-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}
.side-header p, .agent-title p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 14px 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101720;
}
.search input {
  width: 100%;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
}

.agent-list {
  height: calc(100dvh - 150px);
  overflow: auto;
  padding: 0 10px 52px;
}
.agent-row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px;
  margin: 4px 0;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
}
.agent-row.active {
  background: rgba(255,255,255,.08);
  border-color: var(--line);
}
.agent-row h3 {
  margin: 0;
  font-size: 14px;
}
.agent-row p {
  margin: 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}
.avatar, .mini-avatar {
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid var(--blue);
  color: var(--blue);
  background: rgba(10,132,255,.12);
  font-weight: 700;
}
.avatar { width: 44px; height: 44px; }
.mini-avatar { width: 34px; height: 34px; font-size: 13px; }
.pending {
  padding: 2px 7px;
  border-radius: 999px;
  color: #111;
  background: var(--yellow);
  font-size: 11px;
  font-weight: 700;
}
.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  background: currentColor;
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  background: #0f141b;
}
.chat-header {
  background: rgba(15,20,27,.92);
}
.agent-title { min-width: 0; flex: 1; }
.metrics {
  display: flex;
  gap: 8px;
  align-items: center;
}
.metrics span {
  color: var(--muted);
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
}
.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
}
.mobile-only, .mobile-close { display: none; }

.thread {
  overflow: auto;
  padding: 16px;
  scroll-behavior: smooth;
}
.message {
  max-width: 740px;
  margin: 0 0 12px;
  padding: 13px 14px;
  border: 1px solid rgba(10,132,255,.22);
  border-radius: var(--radius);
  background: rgba(10,132,255,.10);
}
.message.from-agent {
  margin-left: auto;
  background: rgba(48,209,88,.10);
  border-color: rgba(48,209,88,.22);
}
.message h4 {
  margin: 0 0 8px;
  font-size: 15px;
}
.message p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
}
.message small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
}

.composer {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: rgba(21,28,37,.96);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.composer-row, .send-row {
  display: flex;
  gap: 8px;
}
.composer input, .composer textarea, .composer select {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: #101720;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
}
.composer textarea { resize: vertical; }
#priority, #route { flex: 0 0 92px; }
#sendBtn {
  flex: 0 0 52px;
  background: var(--blue);
  border-color: transparent;
  font-weight: 800;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1;
  padding: 8px;
}
.tab.active {
  background: var(--blue);
  border-color: var(--blue);
}
.panel {
  height: calc(100dvh - 58px);
  overflow: auto;
  padding: 16px;
}
.card {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card p, .card li {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
pre {
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c8d3df;
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.logout {
  position: absolute;
  left: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(120px);
  max-width: min(520px, calc(100vw - 28px));
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #182230;
  box-shadow: 0 16px 50px rgba(0,0,0,.35);
  transition: transform .2s ease;
  z-index: 10;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.login-body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 0%, #1b2a3b, #0f141b 48%, #090c11);
  overflow: auto;
}
.login-shell {
  width: min(420px, calc(100vw - 32px));
}
.login-card {
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(21,28,37,.86);
  box-shadow: 0 24px 80px rgba(0,0,0,.35);
}
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: white;
  background: var(--blue);
  font-weight: 800;
}
.login-card h1 { margin: 16px 0 4px; }
.login-card p { color: var(--muted); }
.login-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}
.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.login-form input {
  color: var(--text);
  background: #101720;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.login-form button {
  padding: 12px;
  background: var(--blue);
  border-color: var(--blue);
  font-weight: 700;
}
.login-error {
  padding: 10px;
  border-radius: 8px;
  color: #ffd8d5;
  background: rgba(255,69,58,.12);
}

@media (max-width: 980px) {
  body { overflow: hidden; }
  #app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 5;
    width: min(88vw, 340px);
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 18px 0 60px rgba(0,0,0,.35);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only, .mobile-close { display: grid; }
  .chat { grid-column: 1; height: 100dvh; }
  .inspector {
    display: none;
  }
  .metrics {
    display: none;
  }
  .chat-header {
    padding-top: max(12px, env(safe-area-inset-top));
  }
  .thread {
    padding: 12px;
  }
  .message, .message.from-agent {
    margin-left: 0;
    max-width: 100%;
  }
  .composer-row {
    display: grid;
    grid-template-columns: 1fr 78px 86px;
  }
  .send-row {
    align-items: stretch;
  }
  .send-row textarea {
    min-height: 92px;
  }
}

