/* CBC VoIP Ops Console - shared design system.
   Self-contained: no external fonts/icons/JS. Dark NOC-style theme,
   consistent across every page via views/partials/*. */

:root {
  color-scheme: dark;
  --bg: #0b1120;
  --bg-elevated: #0f172a;
  --sidebar-bg: #0a0f1d;
  --card: #131c2e;
  --card-hover: #17223a;
  --border: #253248;
  --border-soft: #1b2637;
  --text: #e6ebf5;
  --text-dim: #aebbd1;
  --muted: #7a889f;
  --accent: #4f7fff;
  --accent-dim: rgba(79, 127, 255, 0.14);
  --accent-strong: #6d94ff;
  --ok: #2dd4a7;
  --ok-dim: rgba(45, 212, 167, 0.14);
  --warn: #f5b13d;
  --warn-dim: rgba(245, 177, 61, 0.14);
  --bad: #f2607a;
  --bad-dim: rgba(242, 96, 122, 0.14);
  --info: #60a5fa;
  --info-dim: rgba(96, 165, 250, 0.14);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 224px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
svg { display: block; }

/* ---------- App shell: sidebar + topbar + content ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.15rem 1.1rem;
  border-bottom: 1px solid var(--border-soft);
}
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 0.8rem; flex: none;
}
.brand .name { font-weight: 650; font-size: 0.95rem; letter-spacing: -0.01em; }
.brand .sub { color: var(--muted); font-size: 0.7rem; margin-top: 0.1rem; }

.nav { padding: 0.75rem 0.6rem; display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.nav a svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.nav a:hover { background: var(--card); color: var(--text); }
.nav a.active { background: var(--accent-dim); color: var(--accent-strong); }
.nav a.active svg { opacity: 1; }
.nav .nav-section {
  color: var(--muted); font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.06em; font-weight: 650; padding: 0.9rem 0.65rem 0.3rem;
}

.sidebar-foot { padding: 0.85rem 1.1rem; border-top: 1px solid var(--border-soft); }
.sidebar-foot .who { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.55rem; overflow-wrap: anywhere; }
.sidebar-foot .who strong { color: var(--text-dim); }
.sidebar-foot form { margin: 0; }
.sidebar-foot button {
  width: 100%; background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem; font-size: 0.78rem; cursor: pointer;
}
.sidebar-foot button:hover { color: var(--text); border-color: var(--accent); }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.75rem;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 17, 32, 0.7);
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: blur(6px);
}
.topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.topbar .crumb { color: var(--muted); font-size: 0.78rem; margin-top: 0.15rem; }
.topbar-right { display: flex; align-items: center; gap: 0.6rem; }

.content { padding: 1.5rem 1.75rem 3rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.content.narrow { max-width: 760px; }

/* ---------- Primitives ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
}
.card + .card { margin-top: 1.1rem; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.9rem; }
.card-head h2 { margin: 0; font-size: 0.92rem; font-weight: 650; }
.card-head .sub, .card .sub { color: var(--muted); font-size: 0.8rem; margin: 0.25rem 0 0; line-height: 1.55; }
.section-title {
  color: var(--muted); font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.06em; font-weight: 650; margin: 1.75rem 0 0.7rem;
}
.section-title:first-child { margin-top: 0; }

.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.stat-card .label { color: var(--muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; display: flex; align-items: center; gap: 0.4rem; }
.stat-card .label svg { width: 14px; height: 14px; opacity: 0.8; }
.stat-card .value { font-size: 1.7rem; font-weight: 680; margin-top: 0.4rem; letter-spacing: -0.02em; }
.stat-card .value .unit { font-size: 0.95rem; color: var(--muted); font-weight: 500; margin-left: 0.15rem; }
.stat-card .delta { font-size: 0.78rem; margin-top: 0.35rem; color: var(--muted); }
.stat-card .delta.up { color: var(--ok); }
.stat-card .delta.down { color: var(--bad); }

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 650;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.ok, .badge.answered, .badge.active, .badge.registered { background: var(--ok-dim); color: var(--ok); }
.badge.warn, .badge.no-answer, .badge.busy, .badge.ringing { background: var(--warn-dim); color: var(--warn); }
.badge.bad, .badge.failed, .badge.disabled, .badge.unregistered { background: var(--bad-dim); color: var(--bad); }
.badge.info { background: var(--info-dim); color: var(--info); }
.badge.unknown, .badge.neutral { background: rgba(122, 136, 159, 0.16); color: var(--muted); }

.banner { border-radius: var(--radius); padding: 0.9rem 1.15rem; margin-bottom: 1.1rem; font-size: 0.87rem; line-height: 1.55; }
.banner.ok { background: var(--ok-dim); border: 1px solid rgba(45, 212, 167, 0.35); }
.banner.bad { background: var(--bad-dim); border: 1px solid rgba(242, 96, 122, 0.35); }
.banner.info { background: var(--info-dim); border: 1px solid rgba(96, 165, 250, 0.35); }
.banner p { margin: 0.3rem 0; }
.banner code { background: rgba(0, 0, 0, 0.28); padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.95em; }
.banner .creds { margin-top: 0.5rem; font-size: 1rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; align-items: center; }
.banner .creds-qr { margin-top: 0.75rem; display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.banner .creds-qr svg { background: #fff; border-radius: 6px; padding: 6px; width: 96px; height: 96px; flex: none; }
.banner .creds-qr p { max-width: 320px; }

/* ---------- Buttons & forms ---------- */
button, .btn {
  font-family: inherit; cursor: pointer; border-radius: var(--radius-sm);
  font-size: 0.83rem; font-weight: 600; padding: 0.5rem 1rem; border: none;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn-primary, form.create button[type=submit], .save-btn { background: var(--accent); color: white; }
.btn-primary:hover, form.create button[type=submit]:hover, .save-btn:hover { background: var(--accent-strong); }
.btn-neutral { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-neutral:hover { color: var(--text); border-color: var(--accent); }
.btn-danger, .danger-btn { background: rgba(242, 96, 122, 0.15); color: var(--bad); }
.btn-danger:hover, .danger-btn:hover { background: rgba(242, 96, 122, 0.28); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.76rem; }

.field { display: flex; flex-direction: column; gap: 0.32rem; margin-bottom: 1rem; }
.field label { font-size: 0.76rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); padding: 0.5rem 0.65rem; font-size: 0.87rem; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 3rem; }
.hint { color: var(--muted); font-size: 0.78rem; margin-top: 0.6rem; line-height: 1.5; }

form.filters, form.create, form.inline-row {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end;
}
form.filters .field, form.create .field { margin-bottom: 0; }
form.filters button, form.create button { height: fit-content; }
a.clear-link { color: var(--muted); font-size: 0.83rem; text-decoration: none; align-self: center; padding-bottom: 0.5rem; }
a.clear-link:hover { color: var(--text); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; background: var(--card); }
th, td { text-align: left; padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  color: var(--muted); font-weight: 650; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.03em; position: sticky; top: 0; background: var(--card);
}
th[data-key] { cursor: pointer; user-select: none; }
th[data-key]:hover { color: var(--text); }
th .arrow { opacity: 0.5; font-size: 0.68rem; margin-left: 0.2rem; }
tbody tr:hover { background: var(--card-hover); }
tbody tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; }

.empty {
  text-align: center; padding: 3rem 1.25rem; color: var(--muted);
  background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty .icon { width: 34px; height: 34px; margin: 0 auto 0.75rem; color: var(--muted); opacity: 0.7; }
.empty h2 { color: var(--text); font-size: 0.95rem; margin: 0 0 0.4rem; }
.empty p { margin: 0; font-size: 0.83rem; line-height: 1.55; max-width: 440px; margin: 0 auto; }
.count-line { color: var(--muted); font-size: 0.8rem; margin: 0 0 0.65rem; display: flex; justify-content: space-between; align-items: center; }

/* ---------- Charts (inline SVG, no library) ---------- */
.chart-wrap { overflow-x: auto; }
.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 110px; }
.bar-chart .bar-col { flex: 1; min-width: 6px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart .bar { width: 100%; border-radius: 3px 3px 0 0; background: var(--accent); min-height: 2px; transition: background 0.12s; }
.bar-chart .bar-col:hover .bar { background: var(--accent-strong); }
.bar-chart .bar.peak { background: var(--ok); }
.chart-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.68rem; margin-top: 0.4rem; }

.hbar-list { display: flex; flex-direction: column; gap: 0.55rem; }
.hbar-row { display: grid; grid-template-columns: 90px 1fr 46px; align-items: center; gap: 0.6rem; font-size: 0.82rem; }
.hbar-row .hbar-label { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-row .hbar-track { position: relative; background: var(--border-soft); border-radius: 999px; height: 8px; overflow: hidden; }
.hbar-row .hbar-fill { position: absolute; top: 0; left: 0; height: 100%; border-radius: 999px; background: var(--accent); }
.hbar-row .hbar-val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.donut-legend { display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.82rem; }
.donut-legend .item { display: flex; align-items: center; gap: 0.5rem; }
.donut-legend .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.donut-legend .item .lbl { color: var(--text-dim); flex: 1; }
.donut-legend .item .pct { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Misc ---------- */
.pill-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-dim); }
.status-dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-dim); }
.status-dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-dim); }
.status-dot.unknown { background: var(--muted); }

.members { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.members label {
  display: flex; align-items: center; gap: 0.4rem; font-size: 0.83rem;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.4rem 0.7rem; cursor: pointer;
}

.row-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.row-actions form { margin: 0; display: flex; gap: 0.35rem; align-items: center; }
.row-actions input[type=text] {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); padding: 0.35rem 0.5rem; font-size: 0.8rem; width: 130px;
}
details.pop { display: inline-block; }
details.pop summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 0.3rem;
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: var(--radius-sm); padding: 0.35rem 0.75rem; font-size: 0.78rem; font-weight: 600;
}
details.pop summary::-webkit-details-marker { display: none; }
details.pop summary:hover { color: var(--text); border-color: var(--accent); }
details.pop .popover {
  margin-top: 0.4rem; padding: 0.65rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-elevated); display: flex; flex-direction: column; gap: 0.4rem;
}

.digit-row {
  display: grid; grid-template-columns: 2.4rem 1fr; gap: 0.75rem; align-items: center;
  padding: 0.55rem 0; border-bottom: 1px solid var(--border-soft);
}
.digit-row:last-child { border-bottom: none; }
.digit-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; border-radius: var(--radius-sm); background: var(--accent-dim);
  color: var(--accent-strong); font-weight: 700; font-size: 1rem;
}
.preview {
  background: var(--bg-elevated); border: 1px dashed var(--border); border-radius: var(--radius-sm);
  padding: 0.75rem 1rem; font-size: 0.86rem; color: var(--text-dim); font-style: italic;
}

audio { height: 30px; }
audio.wide { width: 100%; max-width: 420px; }

/* ---------- Login page ---------- */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 380px; margin: 1rem; }
.login-card .brand-row { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 1.5rem; }
.login-card .brand-row .mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), #8b5cf6); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; }
.login-card h1 { font-size: 1.1rem; margin: 0; }
.login-card p.sub { color: var(--muted); font-size: 0.83rem; margin: 0.2rem 0 1.5rem; }
.login-card button { width: 100%; justify-content: center; padding: 0.6rem; font-size: 0.9rem; }

/* ---------- Mobile ---------- */
.menu-toggle { display: none; }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: -100%; z-index: 20; transition: left 0.18s; box-shadow: 0 0 0 100vmax rgba(0,0,0,0); }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.5); }
  .menu-toggle {
    display: inline-flex; background: transparent; border: 1px solid var(--border); color: var(--text-dim);
    border-radius: var(--radius-sm); padding: 0.4rem 0.55rem;
  }
  .content { padding: 1.1rem 1rem 2.5rem; }
  .topbar { padding: 0.85rem 1rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
