:root {
  --bg: #00051a;
  --panel: #0a1633;
  --panel-2: #0d1b3d;
  --idle: #8fbf6a;
  --wait: #e0a060;
  --busy: #c45c5c;
  --talk: #6cb3d4;
  --offline: #6a7076;
  --text: #f2f4f6;
  --muted: #9eb0c8;
  --tile: #d7dbe0;
  --tile-text: #1e2328;
  --accent: #3b82ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--bg);
  border-bottom: 1px solid #122044;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.logo {
  height: 42px;
  width: auto;
  display: block;
}
.brand-name {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #fff;
}
.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.clock {
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.06em;
}
.views { display: flex; gap: 6px; }
.view-btn {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid #122044;
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
}
.view-btn.active { background: #5a8f4a; color: #fff; }
.status { font-size: 12px; color: var(--muted); }
.status.error { color: #ff8a8a; }

.featured {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.feat {
  background: var(--panel);
  border-radius: 6px;
  padding: 12px;
}
.feat h3 { margin: 0 0 10px; font-size: 14px; }
.feat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  font-size: 12px;
}
.feat-grid .n { font-size: 22px; font-weight: 700; display: block; }
.feat-grid .l { color: var(--muted); font-size: 10px; text-transform: uppercase; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  padding: 12px 14px;
}
.kpi {
  background: var(--panel);
  border-radius: 6px;
  padding: 10px 12px;
}
.kpi .label { font-size: 11px; text-transform: uppercase; color: var(--muted); }
.kpi .value { font-size: 28px; font-weight: 700; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

section { padding: 0 14px 14px; }
section h2 {
  margin: 8px 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.queues {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.queue {
  min-width: 240px;
  flex: 1 1 240px;
  background: var(--idle);
  color: #163014;
  border-radius: 4px;
  padding: 8px 10px;
}
.queue.has-wait { background: var(--wait); }
.queue.has-talk { background: var(--talk); }
.queue .title { font-weight: 700; font-size: 13px; }
.queue .meta { font-size: 11px; margin-top: 4px; }
.queue .agent {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin-top: 3px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #2d7a28;
  display: inline-block;
}
.dot.busy { background: #a31f1f; }

.live-calls { display: flex; flex-direction: column; gap: 6px; }
.live-call {
  display: grid;
  grid-template-columns: 88px 1fr 1.2fr 160px 90px;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
}
.live-call.live-head {
  background: #0d1b3d;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.live-call.waiting { border-left: 4px solid var(--wait); }
.live-call.talking { border-left: 4px solid var(--talk); }
.live-call .state {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}
.live-call.waiting .state { color: var(--wait); }
.live-call.talking .state { color: var(--talk); }
.live-call .caller { font-weight: 700; font-size: 16px; }
.live-call .timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
.live-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}
.ext {
  background: var(--tile);
  color: var(--tile-text);
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 12px;
  min-height: 42px;
}
.ext.talking { background: #e07a7a; color: #fff; }
.ext.offline { background: #9aa1a8; color: #2b2f33; }
.ext .num { font-weight: 700; }
.ext .name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.table-wrap { overflow: auto; max-height: 42vh; background: var(--panel); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid #122044; white-space: nowrap; }
th { background: #0d1b3d; cursor: pointer; position: sticky; top: 0; }
tr:hover td { background: #122044; }
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  background: #5a8f4a;
}
.badge.unavail, .badge.away, .badge.offline { background: #8a3b3b; }
.badge.talking { background: #2f6f90; }

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.user-bar.hidden { display: none; }
.user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sign-out {
  color: var(--accent);
  text-decoration: none;
}
.sign-out:hover { text-decoration: underline; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  text-align: center;
  background: var(--panel);
  border: 1px solid #122044;
  border-radius: 10px;
  padding: 36px 28px 32px;
}
.login-logo {
  height: 56px;
  width: auto;
  margin: 0 auto 16px;
  display: block;
}
.login-card h1 {
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 600;
}
.login-sub {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}
.login-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border-radius: 6px;
  background: #fff;
  color: #1e2328;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
}
.login-btn:hover { background: #eef2f8; }

.customize-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid #1e3a6e;
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
}
.customize-btn:hover { background: #122044; }

.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 3, 16, 0.72);
}
.modal-card {
  position: relative;
  width: min(760px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid #122044;
  border-radius: 10px;
  padding: 18px 20px 16px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-header h2 {
  margin: 0;
  font-size: 18px;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.modal-help {
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.modal-cols {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
}
.modal-cols h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text);
}
.modal-limit {
  color: var(--muted);
  font-weight: 400;
}
.pref-queues {
  display: grid;
  gap: 4px;
  max-height: 42vh;
  overflow: auto;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid #122044;
  border-radius: 6px;
}
.pref-queue, .pref-sections label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  padding: 4px 2px;
}
.pref-sections {
  display: grid;
  gap: 8px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid #122044;
  border-radius: 6px;
}
.pref-status {
  min-height: 1.2em;
  margin: 12px 0 8px;
  font-size: 12px;
  color: var(--muted);
}
.pref-status.error { color: #e88; }
.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.modal-actions-right {
  display: flex;
  gap: 8px;
}
.btn {
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid #1e3a6e;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
}
.btn.ghost:hover { color: var(--text); background: #122044; }

@media (max-width: 700px) {
  .modal-cols { grid-template-columns: 1fr; }
}
