:root {
  --bg: #080a14;
  --bg2: #0d1020;
  --panel: rgba(255, 255, 255, .035);
  --panel-2: rgba(255, 255, 255, .06);
  --line: rgba(255, 255, 255, .08);
  --text: #e8eaf5;
  --muted: #8b90a8;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #f43f5e;
  --info: #3b82f6;
  --idle: #64748b;
  --r: 16px;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, .6);
  font-family: Inter, "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, .18), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(34, 211, 238, .12), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.02em; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.muted { color: var(--muted); }
.mono { font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.hidden { display: none !important; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 16px; cursor: pointer; transition: .15s; display: inline-flex; align-items: center; gap: 8px;
}
button:hover { background: rgba(255, 255, 255, .1); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--grad); border: 0; color: #fff; font-weight: 600; box-shadow: 0 8px 24px -8px rgba(124, 92, 255, .7); }
button.primary:hover { filter: brightness(1.1); }
button.danger { background: rgba(244, 63, 94, .15); border-color: rgba(244, 63, 94, .4); color: #fda4af; }
button.ghost { background: transparent; border-color: transparent; }
button.small { padding: 5px 10px; font-size: 12.5px; border-radius: 9px; }
input, select, textarea {
  font: inherit; color: var(--text); background: rgba(0, 0, 0, .3); border: 1px solid var(--line);
  border-radius: 11px; padding: 9px 12px; outline: none; transition: .15s; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .25); }
select option { background: var(--bg2); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-items: end; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px;
  backdrop-filter: blur(16px); box-shadow: var(--shadow);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap;
}
.chip.provider { color: #c4b5fd; border-color: rgba(124, 92, 255, .4); }
.chip.reseller { color: #67e8f9; border-color: rgba(34, 211, 238, .4); }
.chip.customer { color: #86efac; border-color: rgba(34, 197, 94, .4); }
.chip.luna { background: rgba(124, 92, 255, .2); color: #ddd6fe; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--idle); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 11px 12px; border-bottom: 1px solid rgba(255, 255, 255, .04); }
tr:hover td { background: rgba(255, 255, 255, .02); }

/* ---------- states ---------- */
.s-available { --c: var(--ok); }
.s-ringing { --c: var(--warn); }
.s-busy, .s-connected, .s-dialing { --c: var(--bad); }
.s-held { --c: #a855f7; }
.s-wrap { --c: var(--info); }
.s-paused { --c: #f97316; }
.s-offline { --c: var(--idle); }
.state-dot { background: var(--c); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 25%, transparent); }
.state-pill { color: var(--c); border-color: color-mix(in srgb, var(--c) 50%, transparent); background: color-mix(in srgb, var(--c) 12%, transparent); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(420px, 100%); padding: 36px; }
.logo { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; letter-spacing: -.02em; }
.logo-mark { width: 38px; height: 38px; border-radius: 11px; background: var(--grad); display: grid; place-items: center; box-shadow: 0 10px 30px -8px rgba(124, 92, 255, .8); }
.logo-mark svg { width: 20px; height: 20px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 290px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 16px; background: rgba(0, 0, 0, .2); position: sticky; top: 0; height: 100vh; overflow: auto; }
.main { padding: 28px 36px; min-width: 0; }
.tree-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; cursor: pointer; color: var(--text); }
.tree-item:hover { background: var(--panel-2); }
.tree-item.active { background: rgba(124, 92, 255, .18); box-shadow: inset 0 0 0 1px rgba(124, 92, 255, .4); }
.tree-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-children { margin-left: 14px; border-left: 1px dashed var(--line); padding-left: 6px; }
.k { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.k.provider { background: rgba(124, 92, 255, .25); color: #c4b5fd; }
.k.reseller { background: rgba(34, 211, 238, .2); color: #67e8f9; }
.k.customer { background: rgba(34, 197, 94, .2); color: #86efac; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 20px 0 22px; overflow-x: auto; }
.tab { padding: 10px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-color: var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi .v { font-size: 30px; font-weight: 700; letter-spacing: -.03em; margin-top: 6px; }
.bar { height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--grad); border-radius: 6px; }

/* ---------- agent desktop ---------- */
.desk { height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: rgba(0, 0, 0, .25); backdrop-filter: blur(16px); }
.desk-body { display: grid; grid-template-columns: 380px 1fr 320px; gap: 20px; padding: 20px 24px; min-height: 0; }
.desk-body > * { min-height: 0; overflow: auto; }
.phone { display: flex; flex-direction: column; gap: 18px; text-align: center; }
.call-ring { position: relative; width: 120px; height: 120px; margin: 8px auto; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); }
.call-ring svg { width: 44px; height: 44px; opacity: .9; }
.call-ring.ringing { background: rgba(245, 158, 11, .15); border-color: rgba(245, 158, 11, .5); }
.call-ring.ringing::before, .call-ring.ringing::after { content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--warn); animation: ripple 1.6s ease-out infinite; }
.call-ring.ringing::after { animation-delay: .8s; }
.call-ring.connected { background: rgba(34, 197, 94, .15); border-color: rgba(34, 197, 94, .5); }
@keyframes ripple { from { transform: scale(1); opacity: .9; } to { transform: scale(1.7); opacity: 0; } }
.caller { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.timer { font-variant-numeric: tabular-nums; font-size: 15px; color: var(--muted); }
.call-actions { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.round { width: 58px; height: 58px; border-radius: 50%; padding: 0; justify-content: center; font-size: 20px; }
.round.answer { background: var(--ok); border: 0; box-shadow: 0 10px 30px -8px rgba(34, 197, 94, .8); }
.round.hang { background: var(--bad); border: 0; box-shadow: 0 10px 30px -8px rgba(244, 63, 94, .8); }
.round svg { width: 24px; height: 24px; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pad button { justify-content: center; padding: 12px 0; font-size: 17px; font-weight: 600; }
.status-menu { position: relative; }
.menu { position: absolute; top: calc(100% + 8px); left: 0; z-index: 20; min-width: 220px; padding: 6px; background: #151a2e; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.menu button { width: 100%; justify-content: flex-start; background: transparent; border: 0; }
.menu button:hover { background: var(--panel-2); }
.contact-avatar { width: 64px; height: 64px; border-radius: 20px; background: var(--grad); display: grid; place-items: center; font-size: 24px; font-weight: 700; }
.hist-item { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid rgba(255, 255, 255, .04); font-size: 13px; }

/* ---------- wallboard ---------- */
.wall { padding: 28px 36px; min-height: 100vh; }
.wall-queues { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 20px; }
.wq { position: relative; overflow: hidden; }
.wq.alert { box-shadow: 0 0 0 1px rgba(244, 63, 94, .6), 0 0 50px -10px rgba(244, 63, 94, .6); }
.wq .big { font-size: 84px; font-weight: 800; line-height: 1; letter-spacing: -.05em; }
.wq-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.wq-stats .v { font-size: 22px; font-weight: 700; }
.wq-stats .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.ring-svg { width: 132px; height: 132px; }
.agents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-top: 24px; }
.agent-tile { padding: 14px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c); transition: .3s; }
.agent-tile .n { font-weight: 650; }
.agent-tile .t { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* ---------- modal & toasts ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(4, 6, 14, .7); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { width: min(560px, 100%); }
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { padding: 12px 16px; border-radius: 12px; background: #161b31; border: 1px solid var(--line); box-shadow: var(--shadow); animation: slide .25s ease-out; max-width: 380px; }
.toast.err { border-color: rgba(244, 63, 94, .5); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

.integ { display: flex; flex-direction: column; gap: 10px; }
.integ .logo-sq { width: 40px; height: 40px; border-radius: 11px; background: var(--panel-2); display: grid; place-items: center; font-weight: 800; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

@media (max-width: 1100px) {
  .desk-body { grid-template-columns: 1fr; }
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
}

/* ---------- supervisor live board ---------- */
.monitor-bar { margin-bottom: 16px; padding: 12px 18px; border-color: rgba(244, 63, 94, .45); background: rgba(244, 63, 94, .08); }
.live-queues { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 18px; }
.lq { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.lq.alert { box-shadow: 0 0 0 1px rgba(244, 63, 94, .55), 0 0 40px -12px rgba(244, 63, 94, .6); }
.lq-big { font-size: 40px; font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.load-bar { height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.load-bar > i { display: block; height: 100%; border-radius: 6px; transition: width .6s; }
.load-bar.ok > i { background: var(--ok); }
.load-bar.warn > i { background: var(--warn); }
.load-bar.bad > i { background: var(--bad); }
.live-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.agents-table td { vertical-align: middle; }
.agents-table tr.monitored td { background: rgba(244, 63, 94, .06); }
.avatar-sm { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none;
  background: color-mix(in srgb, var(--c, var(--accent)) 22%, transparent); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--c, rgba(255,255,255,.1)); }
.qchip { padding: 3px 10px; font-size: 12px; border-radius: 99px; background: transparent; border: 1px dashed rgba(255, 255, 255, .18); color: var(--muted); }
.qchip.on { background: rgba(124, 92, 255, .22); border: 1px solid rgba(124, 92, 255, .6); color: #ddd6fe; }
.qchip:hover { border-color: var(--accent); color: var(--text); }
.icon-btn { padding: 6px 8px; border-radius: 10px; font-size: 15px; background: transparent; border-color: transparent; }
.icon-btn:hover { background: var(--panel-2); border-color: var(--line); }

/* ---------- statistics ---------- */
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend i, .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart-wrap { position: relative; }
.vchart { width: 100%; height: auto; display: block; }
.vchart .ax { fill: var(--muted); font-size: 11px; }
.vchart .hit { cursor: crosshair; }
.vchart .hit.on { fill: rgba(255, 255, 255, .04); }
.tip { position: absolute; top: 0; width: 160px; padding: 10px 12px; border-radius: 12px; background: #161b31; border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 13px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.hbar { height: 8px; border-radius: 6px; background: var(--panel-2); margin-top: 5px; overflow: hidden; }
.hbar > i { display: block; height: 100%; background: #3987e5; border-radius: 0 4px 4px 0; }

/* ---------- CRM & knowledge ---------- */
tr.clickable { cursor: pointer; }
tr.sel td { background: rgba(124, 92, 255, .1); }
.tl-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.tl-item .dot { margin-top: 6px; }
.note { background: rgba(245, 158, 11, .08); border: 1px solid rgba(245, 158, 11, .25); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; white-space: pre-wrap; }
.kb-item { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; transition: .15s; }
.kb-item:hover { background: var(--panel-2); }
.kb-item.sel { border-color: rgba(124, 92, 255, .6); background: rgba(124, 92, 255, .1); }
.kb-reader { line-height: 1.6; font-size: 14.5px; }
.kb-reader p { margin: 0 0 12px; }
.kb-reader ol, .kb-reader ul { margin: 0 0 12px; padding-left: 22px; }

/* ---------- agent desktop extras ---------- */
.seg { display: inline-flex; padding: 4px; gap: 4px; border-radius: 12px; background: rgba(0, 0, 0, .25); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.coach-msg { padding: 10px 12px; border-radius: 12px; background: rgba(124, 92, 255, .12); border: 1px solid rgba(124, 92, 255, .35); font-size: 13.5px; animation: slide .25s ease-out; }
.coach-msg.fresh { box-shadow: 0 0 0 2px rgba(124, 92, 255, .6), 0 0 30px -6px rgba(124, 92, 255, .8); }
@media (max-width: 1300px) { .live-grid { grid-template-columns: 1fr; } }
.ctilog { max-height: 360px; overflow: auto; margin: 0; padding: 12px; border-radius: 12px; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); font-size: 11.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-all; }

/* ---------- real-time alerts (status = icon + label, never colour alone) ---------- */
.alerts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.alert { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 12px; font-size: 13.5px; font-weight: 500; border: 1px solid; }
.alert.critical { background: rgba(244, 63, 94, .12); border-color: rgba(244, 63, 94, .55); color: #fecdd3; }
.alert.warning { background: rgba(250, 178, 25, .1); border-color: rgba(250, 178, 25, .45); color: #fde68a; }
.wall .alert { font-size: 16px; padding: 10px 16px; }
