:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --line: #e3e6ea; --line-2: #d4d8de;
  --ink: #16191d; --ink-2: #4b535d; --ink-3: #7b838e;
  --brand: #0b6e6e; --brand-ink: #ffffff; --brand-soft: #e3f1f1;
  --good: #1a7f37; --warn: #a15c00; --bad: #c0362c; --bad-soft: #fbeceb; --warn-soft: #fff4e0; --good-soft: #e6f4ea;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }

.btn { border: 1px solid var(--line-2); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: #e9b9b5; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: 4px 9px; font-size: 13px; }
input, select, textarea { border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 10px; background: var(--surface); width: 100%; }
textarea { resize: vertical; }
label { display: block; font-size: 12px; color: var(--ink-2); margin: 10px 0 4px; }
.muted { color: var(--ink-3); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.pill.chat { background: #eef2ff; border-color: #d9def8; }
.pill.voice { background: var(--warn-soft); border-color: #f1d7a8; }
.pill.video { background: var(--brand-soft); border-color: #bfdede; }
.pill.good { background: var(--good-soft); border-color: #bfe1c8; color: var(--good); }
.pill.bad { background: var(--bad-soft); border-color: #efc6c2; color: var(--bad); }
.pill.warn { background: var(--warn-soft); border-color: #f1d7a8; color: var(--warn); }

/* login */
.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.login form { background: var(--surface); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 360px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* shell */
.top { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 52px; background: var(--surface); border-bottom: 1px solid var(--line); }
.logo { font-weight: 700; letter-spacing: -.01em; }
.logo span { color: var(--brand); }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--ink-2); position: relative; }
.tabs button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.tabs .count { margin-left: 6px; background: var(--bad); color: #fff; border-radius: 99px; padding: 0 6px; font-size: 11px; }
.me { display: flex; align-items: center; gap: 10px; }
.presence { width: auto; padding: 5px 8px; }
.view { height: calc(100% - 52px); overflow: auto; }

/* inbox */
.inbox { display: grid; grid-template-columns: 300px 1fr 320px; height: 100%; }
.col { border-right: 1px solid var(--line); overflow: auto; background: var(--surface); }
.col:last-child { border-right: 0; }
.col h3 { margin: 0; padding: 14px 14px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.item { padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; display: grid; gap: 3px; }
.item:hover { background: var(--surface-2); }
.item.on { background: var(--brand-soft); }
.item .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 14px; color: var(--ink-3); }
.convo { display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.convo-head { padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.convo-head .grow { flex: 1; min-width: 160px; }
.stage { display: none; background: #0e1114; position: relative; min-height: 260px; }
.stage.on { display: block; }
.stage video { width: 100%; max-height: 52vh; display: block; object-fit: contain; background: #0e1114; }
.stage .self { position: absolute; right: 12px; bottom: 12px; width: 160px; border-radius: 8px; border: 2px solid rgba(255,255,255,.6); }
.stage .label { position: absolute; left: 12px; top: 10px; color: #fff; font-size: 12px; background: rgba(0,0,0,.45); padding: 3px 8px; border-radius: 6px; }
.stage .callbar { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 8px; }
.msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; }
.msg.agent { align-self: flex-end; background: var(--brand); color: #fff; }
.msg.system { align-self: center; background: none; box-shadow: none; color: var(--ink-3); font-size: 12px; padding: 2px; }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 3px; }
.msg img { max-width: 260px; border-radius: 8px; display: block; }
.compose { display: flex; gap: 8px; padding: 12px; background: var(--surface); border-top: 1px solid var(--line); }
.compose textarea { height: 42px; min-height: 42px; }
.card { padding: 14px; border-top: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-word; }
.actions { display: grid; gap: 6px; padding: 14px; border-top: 1px solid var(--line); }
.placeholder { display: grid; place-items: center; height: 100%; color: var(--ink-3); text-align: center; padding: 24px; }

/* tables and pages */
.page { padding: 20px; max-width: 1200px; margin: 0 auto; }
.page h2 { margin: 0 0 14px; font-size: 18px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--ink-3); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile .n { font-size: 24px; font-weight: 700; margin-top: 4px; }
.tile .l { font-size: 12px; color: var(--ink-3); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bars div { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars div.missed { background: var(--bad); }

/* dialogs */
dialog { border: 0; border-radius: 14px; padding: 20px; width: min(480px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15,18,22,.45); }
dialog h3 { margin: 0 0 6px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); }

@media (max-width: 1100px) {
  .inbox { grid-template-columns: 240px 1fr; }
  .inbox .side { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox .list { max-height: 34vh; border-right: 0; border-bottom: 1px solid var(--line); }
}
