:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1d2320;
  --muted: #66706a;
  --line: #dde1dc;
  --accent: #1f6f4a;
  --accent-ink: #ffffff;
  --warn: #b7791f;
  --danger: #b4372f;
  --bot: #3b5bdb;
  --esc: #c2410c;
  --human: #1f6f4a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  font-family: "Rubik", "Assistant", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --panel: #1b1f1c;
    --ink: #e7ebe8;
    --muted: #9aa49e;
    --line: #2c322e;
    --accent: #3fa774;
    --bot: #7b93ff;
    --esc: #f08a4b;
    --human: #3fa774;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; }
h2, h3 { margin: 0; font-weight: 600; }
h3 { font-size: .95rem; color: var(--muted); margin: 20px 0 8px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; }
.logo {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700;
}
.brand-title { font-weight: 700; }
.brand-sub { font-size: .8rem; color: var(--muted); }
.status { display: flex; gap: 8px; align-items: center; }
.chip {
  font-size: .78rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted);
}
.chip[data-state="on"] { color: var(--human); border-color: var(--human); }
.chip[data-state="warn"] { color: var(--warn); border-color: var(--warn); }

.layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; padding: 16px 20px; }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }

.calls, .detail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.calls { padding: 14px; align-self: start; }
.calls-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.count { background: var(--bg); border-radius: 999px; padding: 2px 10px; font-size: .85rem; }
.call-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.call-item {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; background: var(--panel);
}
.call-item:hover { border-color: var(--muted); }
.call-item[aria-selected="true"] { outline: 2px solid var(--accent); border-color: transparent; }
.call-item .where { font-weight: 600; }
.call-item .meta { font-size: .8rem; color: var(--muted); grid-column: 1 / -1; }
.call-item.ended { opacity: .5; }
.empty { color: var(--muted); font-size: .9rem; text-align: center; margin: 24px 0; }

.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 6px; color: #fff; background: var(--muted); }
.badge.bot { background: var(--bot); }
.badge.escalating { background: var(--esc); animation: pulse 1.2s infinite; }
.badge.handed_over { background: var(--human); }
.badge.ended { background: var(--muted); }
@keyframes pulse { 50% { opacity: .55; } }

.detail { padding: 18px 20px; min-height: 420px; }
.placeholder { color: var(--muted); text-align: center; margin-top: 120px; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; }
.detail-head h2 { margin-bottom: 6px; }
.timer { font-variant-numeric: tabular-nums; font-size: 1.4rem; color: var(--muted); }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 16px 0; }
.facts div { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.facts .wide { grid-column: 1 / -1; }
.facts dt { font-size: .75rem; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; direction: auto; unicode-bidi: plaintext; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.warn { border-color: var(--warn); color: var(--warn); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.ghost { border-color: transparent; }

.transcript { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 46vh; overflow: auto; }
.transcript li { max-width: 80%; padding: 8px 12px; border-radius: 10px; line-height: 1.45; unicode-bidi: plaintext; }
.transcript li.caller { background: var(--bg); justify-self: start; }
.transcript li.bot { background: color-mix(in srgb, var(--bot) 14%, transparent); justify-self: end; }
.transcript time { display: block; font-size: .7rem; color: var(--muted); }

.incoming {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  margin: 12px 20px 0; padding: 12px 16px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--esc) 16%, var(--panel)); border: 1px solid var(--esc);
}
.incoming-actions { display: flex; gap: 8px; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); padding: 0; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.login { display: grid; gap: 12px; padding: 22px; min-width: 320px; }
.login label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.login input { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.login .row { display: flex; gap: 8px; }
.hint { font-size: .75rem; color: var(--muted); margin: 0; }

.toasts { position: fixed; bottom: 16px; inset-inline-start: 16px; display: grid; gap: 8px; z-index: 10; }
.toast { background: var(--ink); color: var(--panel); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--danger); color: #fff; }
