:root {
  --sidebar-bg: #0b1220;
  --sidebar-fg: #c3ccd8;
  --sidebar-muted: #6f7d90;
  --sidebar-hover: rgba(255, 255, 255, 0.045);
  --sidebar-active: #15213a;

  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0e1623;
  --text-2: #435064;
  --muted: #8692a4;
  --line: #e2e7ee;
  --line-2: #edf0f4;

  --accent: #0e9c88;
  --accent-strong: #0a7f6f;
  --accent-soft: #e3f5f1;
  --accent-ring: rgba(14, 156, 136, 0.22);

  --ok: #11904a;
  --ok-soft: #e6f6ec;
  --warn: #b36b06;
  --warn-soft: #fcf1de;
  --bad: #cc3a3a;
  --bad-soft: #fceaea;
  --info: #2a66cf;
  --info-soft: #e8effc;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(15, 23, 36, 0.04), 0 2px 6px rgba(15, 23, 36, 0.04);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d131d;
    --surface: #131b27;
    --surface-2: #17202e;
    --text: #e6ebf2;
    --text-2: #a9b4c3;
    --muted: #7b8798;
    --line: #232e3e;
    --line-2: #1c2634;
    --accent-soft: rgba(14, 156, 136, 0.16);
    --ok-soft: rgba(17, 144, 74, 0.16);
    --warn-soft: rgba(179, 107, 6, 0.18);
    --bad-soft: rgba(204, 58, 58, 0.16);
    --info-soft: rgba(42, 102, 207, 0.18);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── Layout ─────────────────────────────────────────────── */

.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 12px 14px;
  background: var(--sidebar-bg); color: var(--sidebar-fg);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 10px 20px; color: #fff; }
.brand-mark { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 24px; height: 24px; }
.brand-mark i { display: block; border-radius: 3px; background: var(--accent); }
.brand-mark i:nth-child(2) { opacity: 0.55; }
.brand-mark i:nth-child(3) { opacity: 0.3; }
.brand-mark i:nth-child(4) { opacity: 0.8; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; line-height: 1.15; }
.brand-name span { display: block; font-size: 11.5px; font-weight: 500; color: var(--sidebar-muted); letter-spacing: 0; }
.nav-label { padding: 14px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--sidebar-muted); }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px;
  color: var(--sidebar-fg); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--sidebar-hover); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.nav a .count { margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); font-size: 11.5px; text-align: center; }
.nav a .count.hot { background: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, 0.06); font-size: 12.5px; color: var(--sidebar-muted); }
.sidebar-foot .mode { display: flex; align-items: center; gap: 8px; color: var(--sidebar-fg); margin-bottom: 8px; }
.sidebar-foot a { color: var(--sidebar-muted); display: inline-flex; align-items: center; gap: 6px; }
.sidebar-foot a:hover { color: #fff; text-decoration: none; }

.main { min-width: 0; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 28px 36px 20px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.page-title { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; }
.page-sub { margin-top: 3px; color: var(--text-2); }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { padding: 0 36px 56px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 4px 8px; }
  .nav-label, .sidebar-foot { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
}

/* ── Surfaces ───────────────────────────────────────────── */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-title { margin: 0; font-size: 14px; font-weight: 600; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 1100px) { .grid.cols-2, .grid.side { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: inherit; }
a.kpi:hover { border-color: var(--accent); text-decoration: none; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-value { margin-top: 4px; font-size: 24px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-note { margin-top: 2px; font-size: 12px; color: var(--text-2); }

/* ── Tables ─────────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; }
.table th { padding: 9px 14px; text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .r { text-align: right; }
.table .w1 { width: 1%; white-space: nowrap; }
.row-link { color: var(--text); font-weight: 500; }
.row-link:hover { color: var(--accent-strong); }
.sub { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.scroll-x { overflow-x: auto; }

/* ── Chips and status ───────────────────────────────────── */

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; line-height: 18px; white-space: nowrap; background: var(--line-2); color: var(--text-2); }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.chip.plain::before { display: none; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.accent { background: var(--accent-soft); color: var(--accent-strong); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.dot.warn { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
.dot.off { background: #64748b; }
.tag { display: inline-block; padding: 0 6px; border: 1px solid var(--line); border-radius: 5px; font-size: 11.5px; color: var(--text-2); }

/* ── Forms and buttons ──────────────────────────────────── */

label.f { display: block; margin: 14px 0 6px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
label.f:first-child { margin-top: 0; }
.hint { margin-top: 5px; font-size: 12px; color: var(--muted); }
input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 8px 11px;
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 14px; }
.check { display: flex; align-items: flex-start; gap: 9px; margin-top: 12px; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px;
  font: inherit; font-weight: 550; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { border-color: #c9d1dc; background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--line-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: transparent; }
.btn.ghost.danger { color: var(--muted); }
.btn.ghost.danger:hover { color: var(--bad); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 30px; height: 30px; padding: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.actions .spacer { flex: 1; }
form.inline { display: inline; margin: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .search { position: relative; flex: 1 1 280px; }
.toolbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar .search input { padding-left: 32px; }
.toolbar select { width: auto; min-width: 150px; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--line-2); border-radius: 9px; }
.segmented a { padding: 5px 12px; border-radius: 7px; color: var(--text-2); font-weight: 550; font-size: 13px; text-decoration: none; }
.segmented a:hover { color: var(--text); }
.segmented a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented .n { margin-left: 4px; color: var(--muted); font-weight: 500; }

.flash { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); color: var(--accent-strong); font-weight: 550; }
.flash.warn { background: var(--warn-soft); color: var(--warn); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line-2); font-size: 12.5px; color: var(--muted); }
.pager .btns { display: flex; gap: 6px; }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty svg.i { width: 28px; height: 28px; margin-bottom: 8px; color: var(--line); stroke-width: 1.6; }
.empty b { display: block; color: var(--text-2); margin-bottom: 2px; }

/* ── Content blocks ─────────────────────────────────────── */

.prose { white-space: pre-wrap; word-break: break-word; }
.quote { padding: 11px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line-2); white-space: pre-wrap; word-break: break-word; }
.quote.accent { background: var(--accent-soft); border-color: transparent; }
.quote.bad { background: var(--bad-soft); border-color: transparent; }
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; color: var(--text-2); font-size: 12.5px; }
.meta .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--muted); }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
.links a { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; color: var(--text-2); }
.links a:hover { border-color: var(--accent); color: var(--accent-strong); text-decoration: none; }
.diff { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 900px) { .diff { grid-template-columns: 1fr; } }
.diff h4 { margin: 0 0 6px; font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }

.timeline { position: relative; margin: 0; padding: 0; list-style: none; }
.timeline > li { position: relative; padding: 0 0 20px 34px; }
.timeline > li::before { content: ""; position: absolute; left: 11px; top: 26px; bottom: 0; width: 1px; background: var(--line); }
.timeline > li:last-child { padding-bottom: 0; }
.timeline > li:last-child::before { display: none; }
.timeline .node { position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 23px; height: 23px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); }
.timeline .node svg.i { width: 13px; height: 13px; }
.timeline .node.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.timeline .node.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.timeline .node.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.timeline h4 { margin: 2px 0 8px; font-size: 13px; font-weight: 600; }
.timeline h4 .muted { font-weight: 400; }

.chart { width: 100%; height: auto; display: block; }
.chart .bar-suggest { fill: var(--accent); }
.chart .bar-auto { fill: #34c3a6; }
.chart .bar-escalate { fill: #f0a948; }
.chart .bar-handoff { fill: #a7b3c4; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .grid-line { stroke: var(--line-2); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.queue-type { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 8px; background: var(--line-2); color: var(--text-2); }
.queue-type.P { background: var(--accent-soft); color: var(--accent-strong); }
.queue-type.U { background: var(--info-soft); color: var(--info); }
.queue-type.C { background: var(--warn-soft); color: var(--warn); }
.queue-type.G { background: var(--line-2); color: var(--text-2); }
.count-pill { display: inline-block; min-width: 26px; padding: 1px 8px; border-radius: 999px; background: var(--line-2); text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.count-pill.hot { background: var(--warn-soft); color: var(--warn); }

.mode-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.mode-card { position: relative; display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.mode-card input { position: absolute; opacity: 0; }
.mode-card b { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.mode-card span { font-size: 12.5px; color: var(--text-2); }
.mode-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ── Tickets ────────────────────────────────────────────── */

.avatar {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  font-size: 12.5px; font-weight: 650; letter-spacing: 0.02em;
  background: hsl(var(--h, 170) 40% 92%); color: hsl(var(--h, 170) 45% 32%);
}
@media (prefers-color-scheme: dark) { .avatar { background: hsl(var(--h, 170) 30% 22%); color: hsl(var(--h, 170) 55% 78%); } }
.ticket-row { cursor: pointer; }
.ticket-row .name { font-weight: 600; color: var(--text); }
.wait-hot { color: var(--bad); font-weight: 600; }
.wait { color: var(--warn); font-weight: 550; }
.wait svg.i, .wait-hot svg.i, .sub svg.i { width: 13px; height: 13px; vertical-align: -2px; }

.desk { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .desk { grid-template-columns: 1fr; } }
.chat { display: flex; flex-direction: column; overflow: hidden; }
.messages {
  height: calc(100vh - 360px); min-height: 380px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px 20px; background: var(--surface-2);
}
.msg { display: flex; flex-direction: column; gap: 3px; max-width: 74%; }
.msg.in { align-self: flex-start; }
.msg.out, .msg.bot { align-self: flex-end; align-items: flex-end; }
.msg.note { align-self: stretch; max-width: none; }
.bubble {
  padding: 8px 12px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); word-break: break-word;
}
.msg.in .bubble { border-top-left-radius: 5px; }
.msg.out .bubble { background: var(--accent-soft); border-color: transparent; border-top-right-radius: 5px; }
.msg.bot .bubble { background: var(--info-soft); border-color: transparent; border-top-right-radius: 5px; }
.msg.note .bubble { background: var(--warn-soft); border: 1px dashed rgba(179, 107, 6, 0.35); box-shadow: none; }
.msg.deleted .bubble { opacity: 0.55; text-decoration: line-through; }
.msg .prose { white-space: pre-wrap; }
.msg-meta { padding: 0 4px; font-size: 11.5px; color: var(--muted); }
.msg.event { align-self: center; max-width: 90%; text-align: center; font-size: 12px; color: var(--muted); }
.bubble img { display: block; max-width: 300px; max-height: 300px; border-radius: 9px; }
.bubble img.sticker { max-width: 140px; max-height: 140px; }
.bubble video { display: block; max-width: 320px; max-height: 300px; border-radius: 9px; }
.bubble audio { display: block; width: 260px; }
.bubble img + .prose, .bubble video + .prose, .bubble audio + .prose, .bubble .attachment + .prose { margin-top: 6px; }
.attachment { display: inline-flex; align-items: center; gap: 7px; font-weight: 550; }
.day-divider { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.suggestion { margin: 0; padding: 12px 18px; border-top: 1px solid var(--line-2); background: var(--accent-soft); }
.suggestion-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; color: var(--accent-strong); }
.suggestion .prose { white-space: pre-wrap; color: var(--text); }
.suggestion .actions { margin-top: 10px; }
.warn-text { color: var(--warn); }

.composer { padding: 12px 14px; border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { min-height: 76px; border-color: transparent; background: var(--surface-2); }
.composer textarea:focus { background: var(--surface); }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.composer-bar .spacer { flex: 1; }
.composer-bar select { width: auto; max-width: 220px; height: 30px; padding: 0 8px; font-size: 13px; }
.file-label { cursor: pointer; }
.file-label.has-file { color: var(--accent-strong); }

.sound-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 0; margin: 0 0 8px; border: 0; background: none; color: var(--sidebar-muted); font: inherit; font-size: 12.5px; cursor: pointer; }
.sound-toggle:hover { color: #fff; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--sidebar-bg); }
.login .card { width: 100%; max-width: 400px; padding: 28px; }
.login .brand { color: var(--text); padding: 0 0 18px; }
.login .brand-name span { color: var(--muted); }
