:root {
  --nav: #071d35;
  --nav-soft: #102c49;
  --canvas: #f4f7fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dce4ec;
  --line-strong: #c9d4df;
  --text: #132238;
  --muted: #68778a;
  --brand: #0798b8;
  --brand-dark: #067992;
  --mint: #15976c;
  --mint-soft: #e8f7f1;
  --amber: #b76a09;
  --amber-soft: #fff5df;
  --red: #c43b45;
  --red-soft: #fff0f1;
  --blue-soft: #eaf5fa;
  --shadow: 0 8px 28px rgba(25, 49, 76, 0.08);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 18px; line-height: 1.3; }
h3 { font-size: 15px; line-height: 1.3; }
p { color: var(--muted); line-height: 1.5; }
.app-shell { min-height: 100vh; }
.hidden { display: none !important; }

.loading-view,
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.loading-view { background: var(--canvas); }
.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-page {
  background: var(--nav);
}
.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0,0,0,.24);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.brand-symbol {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
}
.login-brand strong { display: block; font-size: 18px; }
.login-brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.login-card > p { margin-top: 8px; }

.workspace {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
}
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 244px;
  display: flex;
  flex-direction: column;
  padding: 20px 14px 14px;
  background: var(--nav);
  color: #d8e6f3;
  z-index: 30;
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
}
.side-brand .brand-symbol { width: 40px; height: 40px; font-size: 16px; }
.side-brand strong { display: block; color: #fff; font-size: 15px; }
.side-brand span { display: block; margin-top: 2px; color: #8fa7be; font-size: 11px; }
.nav-label {
  padding: 6px 12px 7px;
  color: #718da8;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}
.nav-list { display: grid; gap: 3px; }
.nav-button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #adc0d2;
  font-size: 13px;
  text-align: left;
}
.nav-button svg { width: 18px; height: 18px; stroke-width: 1.8; }
.nav-button:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-button.active {
  background: var(--nav-soft);
  color: #fff;
  box-shadow: inset 3px 0 var(--brand);
}
.side-profile {
  margin-top: auto;
  display: grid;
  grid-template-columns: 34px minmax(0,1fr) 32px;
  align-items: center;
  gap: 9px;
  padding: 12px 8px 4px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #d9f3f8;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
}
.profile-copy { min-width: 0; }
.profile-copy strong,
.profile-copy span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-copy strong { color: #fff; font-size: 12px; }
.profile-copy span { color: #7893ad; font-size: 10px; margin-top: 2px; }

.main-shell {
  grid-column: 2;
  min-width: 0;
}
.topbar {
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
}
.topbar-context { color: var(--muted); font-size: 12px; }
.service-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); }
.status-dot.pending { background: var(--amber); }
.icon-btn.menu-button { display: none; }
.content { padding: 28px; }
.content-inner { width: min(1440px, 100%); margin: 0 auto; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
.eyebrow { color: var(--brand-dark); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.page-head h1 { margin-top: 4px; }
.page-head p { margin-top: 6px; max-width: 720px; font-size: 13px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  min-height: 116px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(25,49,76,.04);
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 7px; background: var(--blue-soft); color: var(--brand-dark); }
.stat-icon svg { width: 17px; height: 17px; }
.stat-value { display: block; margin-top: 10px; font-size: 27px; line-height: 1; }
.stat-note { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }
.stat-note strong { color: var(--mint); }

.surface {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.surface-head {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.surface-head p { margin-top: 3px; font-size: 12px; }
.surface-body { padding: 18px; }
.split-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .7fr); gap: 18px; }

.btn,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 700;
}
.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--brand-dark); }
.btn.secondary { border-color: var(--line-strong); background: #fff; color: var(--text); }
.btn.secondary:hover { background: var(--surface-soft); }
.btn.danger { background: var(--red); }
.btn.danger-soft { border-color: #f0c7ca; background: var(--red-soft); color: var(--red); }
.btn.compact { min-height: 32px; padding: 0 10px; }
.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-color: var(--line);
  background: #fff;
  color: var(--muted);
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand-dark); background: var(--blue-soft); }
.icon-btn.danger:hover { border-color: #efc2c6; color: var(--red); background: var(--red-soft); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-actions { display: flex; flex-wrap: wrap; gap: 5px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.search-box { min-width: 220px; position: relative; }
.search-box svg { position: absolute; left: 11px; top: 10px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search-box input { padding-left: 34px; }
.field { display: grid; gap: 6px; }
.field label { color: #4f6073; font-size: 11px; font-weight: 800; }
.field input,
.field select,
.field textarea,
.search-box input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 11px;
  outline: 0;
}
.field textarea {
  min-height: 110px;
  resize: vertical;
  padding: 10px 11px;
}
.field input:focus,
.field select:focus,
.field textarea:focus,
.search-box input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(7,152,184,.12); }
.number-assignment {
  min-width: 150px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 9px;
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.helper { color: var(--muted); font-size: 11px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 780px; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid #e8edf2; text-align: left; vertical-align: middle; }
th { background: #f3f7fa; color: #718195; font-size: 10px; font-weight: 800; text-transform: uppercase; }
td { color: #425269; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfdfe; }
.primary-cell strong { display: block; color: var(--text); font-size: 13px; }
.primary-cell span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.mono { font-family: Consolas, monospace; font-size: 11px; }
.badge {
  min-height: 23px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf1f5;
  color: #657488;
  font-size: 10px;
  font-weight: 800;
  text-transform: capitalize;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.active,
.badge.available,
.badge.assigned,
.badge.completed,
.badge.answered { background: var(--mint-soft); color: var(--mint); }
.badge.suspended,
.badge.pending,
.badge.ringing,
.badge.queued { background: var(--amber-soft); color: var(--amber); }
.badge.archived,
.badge.disabled,
.badge.failed,
.badge.missed { background: var(--red-soft); color: var(--red); }

.empty-state { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty-icon { width: 42px; height: 42px; display: grid; place-items: center; margin: 0 auto 12px; border-radius: 8px; background: var(--surface-soft); color: var(--brand-dark); }
.empty-icon svg { width: 21px; height: 21px; }
.empty-state strong { display: block; color: var(--text); font-size: 14px; }
.empty-state span { display: block; margin-top: 5px; font-size: 12px; }

.client-banner { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px; border-bottom: 1px solid var(--line); }
.client-identity { display: flex; align-items: center; gap: 12px; }
.client-monogram { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 8px; background: var(--blue-soft); color: var(--brand-dark); font-weight: 800; }
.client-identity p { margin-top: 3px; font-size: 11px; }
.seat-strip { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 9px; }
.seat-tile { padding: 13px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-soft); }
.seat-tile strong { display: block; color: var(--text); font-size: 14px; }
.seat-tile span { display: block; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; }
.seat-tile .badge { margin-top: 10px; }

.provider-status { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.connection-box { padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.connection-line { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.connection-line svg { width: 24px; height: 24px; color: var(--brand-dark); }
.definition-list { display: grid; gap: 0; }
.definition-row { display: flex; justify-content: space-between; gap: 20px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.definition-row:last-child { border-bottom: 0; }
.definition-row span { color: var(--muted); }
.definition-row strong { text-align: right; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3,19,34,.68);
}
.modal {
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
}
.modal.wide { width: min(920px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head p { margin-top: 4px; font-size: 12px; }
.modal-body { padding: 20px; }
.credential-list { display: grid; gap: 8px; margin-top: 14px; }
.credential-row { display: grid; grid-template-columns: 60px minmax(0,1fr) minmax(0,1fr) 34px; gap: 8px; align-items: center; padding: 9px; border: 1px solid var(--line); border-radius: 7px; }
.credential-row code { overflow: hidden; font-size: 11px; text-overflow: ellipsis; }

.toast-stack { position: fixed; top: 78px; right: 20px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100vw - 40px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid #acdaca; border-radius: 7px; background: #f2fbf7; color: #146849; box-shadow: var(--shadow); font-size: 12px; }
.toast.error { border-color: #efc4c8; background: #fff5f5; color: var(--red); }
.toast svg { width: 17px; height: 17px; flex: 0 0 auto; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .split-grid,
  .provider-status { grid-template-columns: 1fr; }
  .seat-strip { grid-template-columns: repeat(3,minmax(0,1fr)); }
}

@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .workspace.menu-open .sidebar { transform: translateX(0); }
  .main-shell { grid-column: 1; }
  .topbar { height: 58px; padding: 0 14px; }
  .icon-btn.menu-button { display: inline-grid; }
  .content { padding: 16px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .page-actions { justify-content: flex-start; }
  .stats-grid,
  .form-grid { grid-template-columns: 1fr; }
  .seat-strip { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .surface-head { align-items: flex-start; flex-direction: column; }
  .toolbar,
  .search-box { width: 100%; }
  .credential-row { grid-template-columns: 50px minmax(0,1fr) 34px; }
  .credential-row .credential-password { grid-column: 2 / 3; }
}

@media (max-width: 430px) {
  .stats-grid { grid-template-columns: 1fr; }
  .seat-strip { grid-template-columns: 1fr; }
  .login-card { padding: 24px; }
}
