: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;
  position: relative;
}
.draggable-tile {
  cursor: grab;
}
.draggable-tile.dragging {
  opacity: 0.55;
  cursor: grabbing;
  z-index: 2;
}
.tile-grip {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.tile-grip span {
  pointer-events: none;
}
.tile-grip:hover,
.tile-grip:active {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text);
}
.tile-grip:active {
  cursor: grabbing;
}
.arrange-mode .feat,
.arrange-mode .queue {
  outline: 1px dashed rgba(255, 255, 255, 0.15);
  outline-offset: -1px;
}
.arrange-mode .draggable-tile:hover {
  outline-color: var(--accent);
}
.tile-ghost {
  opacity: 0.35;
}
.tile-chosen {
  z-index: 3;
}
.arrange-btn.active {
  background: #5a8f4a;
  color: #fff;
  border-color: #5a8f4a;
}
.layout-hint {
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: none;
}
.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);
}
.board-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-flow: row dense;
  gap: 0 12px;
  align-items: start;
}
.board-layout > section {
  min-width: 0;
}
.board-layout > section[data-width="full"],
.board-layout > section:not([data-width]) {
  grid-column: 1 / -1;
}
.board-layout > section[data-width="half"] {
  grid-column: auto;
}
.board-layout > section[hidden] {
  display: none !important;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.arrange-mode .section-head {
  cursor: grab;
}
.section-head h2 { flex: 1; min-width: 0; }
.section-drag,
.section-width-btn {
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid #122044;
  background: var(--panel);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}
.section-drag {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  cursor: grab;
}
.section-width-btn { padding: 4px 8px; white-space: nowrap; }
.arrange-mode .section-drag,
.arrange-mode .section-width-btn { display: inline-flex; }
.arrange-mode .board-layout > section {
  outline: 1px dashed rgba(255, 255, 255, 0.14);
  outline-offset: -1px;
  border-radius: 6px;
}
.board-layout > section[data-width="half"] .live-calls,
.board-layout > section[data-width="half"] .table-wrap {
  overflow-x: auto;
}
.agent-login {
  display: block;
  font-size: 10px;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 700px) {
  .board-layout > section[data-width="half"] { grid-column: 1 / -1; }
}

.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;
  position: relative;
}
.queue .tile-grip {
  border-color: rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.35);
  color: rgba(0, 0, 0, 0.55);
}
.queue .tile-grip:hover,
.queue .tile-grip:active {
  background: rgba(255, 255, 255, 0.65);
  color: rgba(0, 0, 0, 0.85);
}
.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;
}
.queue .roster-meta {
  font-size: 10px;
  margin-top: 6px;
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.queue .agent-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .agent-state {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}
.queue .agent.out {
  opacity: 0.55;
}
.queue .agent.out .agent-name {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #2d7a28;
  display: inline-block;
  flex-shrink: 0;
}
.dot.ready { background: #2d7a28; }
.dot.busy { background: #a31f1f; }
.dot.in { background: #2f6f90; }
.dot.out { background: #6a7076; }

.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; }
.setup-prompt strong { color: var(--text); font-weight: 600; }

.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; }
td.login-hist {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}
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; }
/* Queue state. The class is the label lowercased with spaces stripped, so
   "On queue" -> .onqueue and "Off queue" -> .offqueue. Off queue is amber, not
   the red used for unavail/offline: someone who has stepped off the queue is
   still at their desk and reachable, which is a different thing from an
   unregistered phone, and the board should not make the two look alike.
   Without these rules Off queue would inherit the default green and go on
   implying "available", which is the bug this change exists to fix. */
.badge.onqueue { background: #5a8f4a; }
.badge.offqueue { background: #9a7326; }
.logged-queues {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 220px;
  white-space: normal;
}
.q-chip {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #122044;
  border: 1px solid #1a2d55;
  font-size: 11px;
  color: var(--text);
}
.muted { color: var(--muted); }

.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; }

.board-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.board-switch select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #122044;
  border-radius: 4px;
  padding: 4px 8px;
  max-width: 160px;
}
.user-role {
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
}
.access-banner {
  margin: 8px 14px 0;
  padding: 8px 12px;
  background: #1a2744;
  border: 1px solid #2a3f6a;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
}
.access-banner.hidden { display: none; }
.impersonate-banner {
  margin: 8px 14px 0;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #3a2a10;
  border: 1px solid #8a5a18;
  border-radius: 6px;
  color: #f3d9a8;
  font-size: 13px;
}
.impersonate-banner.hidden { display: none; }
.impersonate-banner .btn { flex-shrink: 0; }
.impersonate-people { max-height: min(60vh, 520px); }
.impersonate-person {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid #122044;
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  cursor: pointer;
}
.impersonate-person:hover { border-color: #2a4a88; }
.impersonate-person .gu-name { font-weight: 600; font-size: 13px; display: block; }
.impersonate-person .gu-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.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-card-wide {
  width: min(1280px, 96vw);
  max-height: min(92vh, 980px);
}
.grants-layout {
  display: grid;
  grid-template-columns: minmax(340px, 1.2fr) minmax(300px, 1fr);
  gap: 20px;
}
.grants-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.grants-col-head h3 { margin: 0; }
.grants-col-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.btn-tiny {
  padding: 3px 8px !important;
  font-size: 11px !important;
}
.grants-filter {
  width: 100%;
  margin-bottom: 8px;
  padding: 7px 10px;
  border-radius: 4px;
  border: 1px solid #122044;
  background: #070f22;
  color: var(--text);
  font-size: 13px;
}
.grants-filter-row {
  display: grid;
  grid-template-columns: minmax(140px, 0.9fr) minmax(160px, 1.1fr);
  gap: 8px;
  margin-bottom: 4px;
}
.grants-filter-row .grants-filter { margin-bottom: 0; }
.grants-filter-row .grants-filter-label { margin-bottom: 8px; }
.grants-users {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: min(58vh, 560px);
  overflow: auto;
  padding-right: 4px;
}
.grants-user {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid #122044;
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  cursor: pointer;
}
.grants-user:hover { border-color: #2a4a88; }
.grants-user:has(input:checked) {
  border-color: var(--accent);
  background: #122044;
}
.grants-user input { margin-top: 2px; }
.grants-user .gu-body { min-width: 0; flex: 1; }
.grants-user .gu-name { font-weight: 600; font-size: 13px; display: block; }
.grants-user .gu-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.grants-user .gu-count {
  display: inline;
  margin-top: 0;
  margin-left: 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-weight: 600;
}
.pref-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  min-height: 0;
}
.pref-templates .tpl-btn {
  background: #122044;
  border: 1px solid #1e3a6e;
  color: var(--text);
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 11px;
}
.pref-templates .tpl-btn:hover {
  border-color: var(--accent);
  color: #fff;
}
.pref-templates .tpl-btn.active {
  background: #5a8f4a;
  border-color: #5a8f4a;
}
.pref-templates .tpl-empty {
  color: var(--muted);
  font-size: 12px;
}
.grants-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 14px;
}
.grants-tab-panel.hidden { display: none; }
.grants-filter-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}
.admin-template-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid #122044;
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  cursor: pointer;
}
.admin-template-item.active {
  border-color: var(--accent);
  background: #122044;
}
.admin-template-item .ati-name { font-weight: 600; font-size: 13px; display: block; }
.admin-template-item .ati-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.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: 6px 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.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: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(58vh, 560px);
  overflow: auto;
  padding: 8px;
  background: #070f22;
  border: 1px solid #122044;
  border-radius: 6px;
}
.pref-queue {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.pref-queue-row {
  border: 1px solid #122044;
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--panel-2);
}
.pref-queue-perms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 6px 0 2px 22px;
  font-size: 11px;
  color: var(--muted);
}
.pref-queue-perms[hidden] {
  display: none !important;
}
.pref-queue-perms label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.grants-perm-row {
  margin-left: 0;
  padding: 8px 10px;
  background: var(--panel-2);
  border-radius: 6px;
  font-size: 12px;
}
.grants-tpl-perms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 4px 0 10px 22px;
  padding: 6px 8px;
  background: #0c1730;
  border-radius: 6px;
  border: 1px solid #1a2d55;
}
.grants-tpl-perms[hidden] {
  display: none !important;
}
.modal-cols-stack {
  grid-template-columns: 1.4fr 0.8fr;
}
.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-sections label.section-locked {
  opacity: 0.45;
  cursor: not-allowed;
}
.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; }
}
