:root {
  --bg: #0b0c12;
  --bg-2: #0f1119;
  --panel: #14172250;
  --panel-solid: #14182a;
  --border: #232943;
  --border-strong: #2d3454;
  --ink: #e9ecf3;
  --ink-2: #c2c7d6;
  --muted: #7b8198;
  --accent: #7c5cff;
  --accent-2: #a48cff;
  --ok: #3ddc97;
  --warn: #ffb547;
  --err: #ff6b6b;
  --info: #5bc0ff;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; min-height: 100vh; }
body { background:
  radial-gradient(1100px 700px at 80% -10%, rgba(124,92,255,.18), transparent),
  radial-gradient(700px 500px at 10% 100%, rgba(91,192,255,.08), transparent),
  var(--bg);
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }
input, select, textarea {
  font: inherit; background: var(--bg-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px;
  padding: .55rem .8rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(124,92,255,.5); outline-offset: 1px; border-color: transparent; }
label { display: block; font-size: .8rem; color: var(--muted); margin: .8rem 0 .35rem; }
textarea { min-height: 120px; resize: vertical; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; gap: 1rem; align-items: center; }
.row-wrap { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ── Buttons ──────────────────────────────────────────── */
.btn { background: var(--panel-solid); color: var(--ink); border: 1px solid var(--border-strong); padding: .55rem 1rem; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: .5rem; transition: all .15s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, #7c5cff, #5a3cf0); border-color: transparent; }
.btn.primary:hover { box-shadow: 0 4px 18px rgba(124,92,255,.45); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: rgba(255,107,107,.3); }
.btn.danger:hover { background: rgba(255,107,107,.08); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }

/* ── Login ───────────────────────────────────────────── */
.login-shell { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem; }
.login-card { background: var(--panel-solid); border: 1px solid var(--border); border-radius: 18px; padding: 2.4rem; max-width: 420px; width: 100%; box-shadow: 0 10px 60px rgba(0,0,0,.5); }
.login-card .brand { display: flex; gap: .9rem; align-items: center; margin-bottom: 1.8rem; }
.login-card .brand img { width: 44px; height: 44px; }
.login-card h1 { font-size: 1.5rem; margin: 0 0 1.2rem; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 1.2rem; }
.login-card .err { background: rgba(255,107,107,.1); border: 1px solid rgba(255,107,107,.3); border-radius: 8px; padding: .6rem; margin-top: 1rem; color: var(--err); font-size: .88rem; }
.brand-mark { font-size: 1.2rem; font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: .78rem; color: var(--muted); }

/* ── Layout ──────────────────────────────────────────── */
body { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
body.login-shell { display: flex; }
.sidebar {
  background: rgba(15,17,25,.7);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  padding: 1.4rem 1rem;
  display: flex; flex-direction: column; gap: 1rem;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; gap: .7rem; align-items: center; padding: 0 .4rem; margin-bottom: 1.2rem; }
.sidebar .brand img { width: 36px; height: 36px; }
.sidebar nav { display: flex; flex-direction: column; gap: .15rem; }
.sidebar nav a { display: flex; align-items: center; gap: .65rem; padding: .65rem .75rem; border-radius: 9px; color: var(--ink-2); cursor: pointer; font-size: .94rem; transition: all .12s; position: relative; }
.sidebar nav a:hover { background: rgba(255,255,255,.04); color: var(--ink); }
.sidebar nav a.active { background: linear-gradient(135deg, rgba(124,92,255,.25), rgba(124,92,255,.1)); color: var(--ink); }
.sidebar nav a .ico { width: 22px; text-align: center; }
.badge { background: var(--accent); color: #fff; font-size: .72rem; padding: .12rem .5rem; border-radius: 12px; margin-left: auto; font-weight: 600; }
.badge.urgent { background: var(--err); }
.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); font-size: .85rem; }
.sidebar-foot .me { color: var(--ink-2); margin-bottom: .4rem; }
.sidebar-foot .logout { color: var(--muted); font-size: .82rem; }
.sidebar-foot .logout:hover { color: var(--err); }

main { padding: 2rem 2.4rem; max-width: 1280px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1.6rem; flex-wrap: wrap; gap: 1rem; }
.page-head h1 { font-size: 1.8rem; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); margin-top: .3rem; font-size: .95rem; }

/* ── Cards / panels ──────────────────────────────────── */
.card { background: var(--panel-solid); border: 1px solid var(--border); border-radius: 14px; padding: 1.2rem 1.3rem; }
.card h2 { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 0 0 .8rem; font-weight: 600; }
.card h3 { font-size: 1.05rem; margin: 0 0 .8rem; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.6rem; }
.kpi { background: var(--panel-solid); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem 1.2rem; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; inset: 0; opacity: .08; background: radial-gradient(120px 80px at 30% 0%, var(--accent), transparent); pointer-events: none; }
.kpi .lbl { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.kpi .val { font-size: 2rem; font-weight: 700; margin-top: .3rem; }
.kpi.urgent .val { color: var(--err); }
.kpi.warn .val { color: var(--warn); }
.kpi.ok .val { color: var(--ok); }

.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 1.2rem; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } body { grid-template-columns: 1fr; } .sidebar { position: relative; height: auto; } }

/* ── Tables ──────────────────────────────────────────── */
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th, table.t td { padding: .65rem .8rem; text-align: left; border-bottom: 1px solid var(--border); }
table.t th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
table.t tr:hover td { background: rgba(255,255,255,.02); }
table.t tr.clickable { cursor: pointer; }

/* ── Pills ───────────────────────────────────────────── */
.pill { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
.pill.new        { background: rgba(91,192,255,.15);  color: var(--info); }
.pill.read       { background: rgba(255,255,255,.06); color: var(--muted); }
.pill.actioned   { background: rgba(61,220,151,.15);  color: var(--ok); }
.pill.archived   { background: rgba(255,255,255,.04); color: var(--muted); }
.pill.urgent     { background: rgba(255,107,107,.18); color: var(--err); }
.pill.high       { background: rgba(255,181,71,.18);  color: var(--warn); }
.pill.normal     { background: rgba(255,255,255,.06); color: var(--ink-2); }
.pill.low        { background: rgba(255,255,255,.04); color: var(--muted); }
.pill.open       { background: rgba(91,192,255,.15);  color: var(--info); }
.pill.in_progress{ background: rgba(255,181,71,.18);  color: var(--warn); }
.pill.resolved   { background: rgba(61,220,151,.15);  color: var(--ok); }
.pill.closed     { background: rgba(255,255,255,.04); color: var(--muted); }
.pill.forwarded  { background: rgba(124,92,255,.18);  color: var(--accent-2); }
.pill.message_taken { background: rgba(91,192,255,.15); color: var(--info); }
.pill.ticket_created { background: rgba(255,181,71,.15); color: var(--warn); }
.pill.answered_question { background: rgba(61,220,151,.15); color: var(--ok); }
.pill.hangup, .pill.abandoned, .pill.error { background: rgba(255,107,107,.12); color: var(--err); }
.pill.in_progress.live { background: rgba(61,220,151,.18); color: var(--ok); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100%{opacity:.6} 50%{opacity:1} }

/* ── Live calls panel ────────────────────────────────── */
.live-call { background: linear-gradient(135deg, rgba(61,220,151,.08), rgba(61,220,151,.02)); border: 1px solid rgba(61,220,151,.3); border-radius: 12px; padding: 1rem 1.2rem; margin-bottom: .8rem; display: flex; align-items: center; gap: 1rem; }
.live-call .dot { width: 10px; height: 10px; background: var(--ok); border-radius: 50%; box-shadow: 0 0 0 4px rgba(61,220,151,.2); animation: pulse 1.2s infinite; }
.live-call .who { font-weight: 600; }
.live-call .meta { color: var(--muted); font-size: .85rem; margin-top: .1rem; }

/* ── Detail panes ────────────────────────────────────── */
.transcript { background: var(--bg-2); border-radius: 12px; padding: 1rem 1.2rem; max-height: 480px; overflow-y: auto; }
.tx { padding: .55rem 0; border-bottom: 1px dashed var(--border); display: flex; gap: 1rem; font-size: .92rem; }
.tx:last-child { border-bottom: 0; }
.tx .role { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; min-width: 60px; padding-top: .2rem; }
.tx .role.caller { color: var(--ok); }
.tx .role.tomi { color: var(--accent-2); }
.tx .role.tool { color: var(--warn); }
.tx .txt { flex: 1; white-space: pre-wrap; }

.tool-row { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; padding: .55rem .8rem; background: rgba(255,181,71,.06); border-left: 3px solid var(--warn); margin: .4rem 0; border-radius: 6px; }
.tool-row .name { color: var(--warn); font-weight: 600; }

/* ── Trend bars ──────────────────────────────────────── */
.trend { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin-top: 1rem; }
.trend .bar { flex: 1; background: linear-gradient(180deg, var(--accent), rgba(124,92,255,.3)); border-radius: 4px 4px 0 0; min-height: 4px; position: relative; }
.trend .bar:hover::after { content: attr(data-n); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--panel-solid); padding: .2rem .5rem; border-radius: 6px; font-size: .75rem; white-space: nowrap; }

/* ── Toast ───────────────────────────────────────────── */
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--panel-solid); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: .8rem 1.2rem; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: toast-in .25s ease-out; max-width: 380px; }
.toast.err { border-left-color: var(--err); }
.toast.ok  { border-left-color: var(--ok); }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Modal ───────────────────────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); display: flex; align-items: flex-start; justify-content: center; padding: 4rem 1rem 2rem; z-index: 100; }
.modal { background: var(--panel-solid); border: 1px solid var(--border); border-radius: 16px; max-width: 720px; width: 100%; padding: 1.6rem 1.8rem; max-height: 80vh; overflow-y: auto; }
.modal h2 { margin: 0 0 1rem; font-size: 1.3rem; }
.modal .actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.4rem; }

/* ── Empty states ────────────────────────────────────── */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .ico { font-size: 2.6rem; margin-bottom: .6rem; opacity: .5; }
.empty h3 { color: var(--ink-2); margin: 0 0 .4rem; font-weight: 500; }

.copyable { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; background: var(--bg-2); padding: .35rem .6rem; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; display: inline-block; }
.copyable:hover { border-color: var(--accent); }

/* ── Business-state bar ──────────────────────────────── */
.status-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 1rem 1.2rem; background: var(--panel-solid); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 1.4rem; }
.status-badge { display: inline-flex; align-items: center; gap: .5rem; padding: .4rem .9rem; border-radius: 999px; font-weight: 600; font-size: .9rem; }
.status-badge.open   { background: rgba(61,220,151,.15); color: var(--ok);   border: 1px solid rgba(61,220,151,.3); }
.status-badge.closed { background: rgba(255,107,107,.12); color: var(--err); border: 1px solid rgba(255,107,107,.3); }
.status-badge.hold   { background: rgba(255,181,71,.15); color: var(--warn); border: 1px solid rgba(255,181,71,.3); }
.status-held { color: var(--muted); font-size: .88rem; margin-top: .35rem; }

/* ── Business hours grid ─────────────────────────────── */
.hours-grid { display: grid; gap: .35rem; }
.hours-row { display: grid; grid-template-columns: 110px 130px auto 130px auto; align-items: center; gap: .7rem; padding: .35rem 0; }
.hours-day { color: var(--ink-2); margin: 0; font-size: .92rem; font-weight: 500; }
.hours-hint { font-size: .78rem; }
.hours-row input[type=time] { padding: .35rem .55rem; }
