/* FaxCore SIP Monitoring Portal — operations console theme
   Type: Segoe UI (Windows/Azure-native) + Cascadia/Consolas for identifiers
   Color: slate-navy ground, one azure accent, status colors reserved for state */

:root {
  --ground: #0b111d;
  --panel: #111a2b;
  --raised: #182440;
  --line: #243049;
  --line-soft: #1a2539;

  --ink: #e6ebf4;
  --ink-2: #9ba8bf;
  --ink-3: #6f7d96;

  --azure: #3d9bff;
  --azure-strong: #1f6fd1;
  --azure-dim: rgba(61, 155, 255, 0.14);
  --ok: #2fc08a;
  --ok-dim: rgba(47, 192, 138, 0.14);
  --warn: #e8a838;
  --warn-dim: rgba(232, 168, 56, 0.14);
  --crit: #ef5b6b;
  --crit-dim: rgba(239, 91, 107, 0.14);
  --violet: #9d8cff;

  --radius: 6px;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", ui-monospace, Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
h1, h2, h3, p, dl, dd, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, input, select { font: inherit; color: inherit; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

:focus-visible { outline: 2px solid var(--azure); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--ink-3); }
.num { text-align: right; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.container { max-width: 1680px; margin: 0 auto; padding: 20px 24px 40px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(11, 17, 29, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1680px; margin: 0 auto; padding: 10px 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.brand h1 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.brand p { font-size: 12px; color: var(--ink-2); }

.topbar-status { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.freshness { display: flex; align-items: baseline; gap: 12px; font-size: 12px; color: var(--ink-2); }
.freshness .is-stale { color: var(--warn); font-weight: 600; }

.status-chip {
  display: inline-flex; align-items: center; gap: 8px;
  height: 28px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  background: var(--panel);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; display: inline-block; }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-crit { background: var(--crit); }
.status-chip[data-mode="live"] { color: var(--ok); border-color: rgba(47, 192, 138, 0.4); }
.status-chip[data-mode="live"] .dot { background: var(--ok); animation: pulse 2.4s ease-in-out infinite; }
.status-chip[data-mode="polling"] { color: var(--azure); border-color: rgba(61, 155, 255, 0.4); }
.status-chip[data-mode="polling"] .dot { background: var(--azure); }
.status-chip[data-mode="reconnecting"] { color: var(--warn); border-color: rgba(232, 168, 56, 0.4); }
.status-chip[data-mode="reconnecting"] .dot { background: var(--warn); }
.status-chip[data-mode="offline"] { color: var(--crit); border-color: rgba(239, 91, 107, 0.4); }
.status-chip[data-mode="offline"] .dot { background: var(--crit); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47, 192, 138, 0.5); }
  50% { box-shadow: 0 0 0 5px rgba(47, 192, 138, 0); }
}

/* ---------- Deployment context ---------- */
.context {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 32px; margin-bottom: 16px; padding: 0 2px;
}
.context dt { font-size: 12px; color: var(--ink-3); }
.context dd { font-size: 13px; color: var(--ink); }

/* ---------- Panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding: 14px 16px 0;
}
.panel-head h2 { font-size: 14px; font-weight: 600; }
.panel-meta { font-size: 12px; color: var(--ink-3); }
.panel-body { padding: 12px 16px 16px; }
.section-gap { margin-bottom: 16px; }

/* ---------- Alerts ---------- */
.alerts { margin-bottom: 16px; display: grid; gap: 8px; }
.alert {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 14px; border-radius: var(--radius); border: 1px solid; border-left-width: 4px;
  font-size: 13px;
}
.alert-critical { background: var(--crit-dim); border-color: rgba(239, 91, 107, 0.45); color: #ffc2c9; }
.alert-warning { background: var(--warn-dim); border-color: rgba(232, 168, 56, 0.45); color: #f6dba3; }
.alert-cat { font-weight: 700; margin-right: 6px; }
.alert-value { font-weight: 700; white-space: nowrap; }

/* ---------- Traffic path ---------- */
.path {
  display: grid; align-items: stretch;
  grid-template-columns: minmax(0, 1fr) 56px minmax(0, 1fr) 56px minmax(0, 1fr);
  margin-bottom: 16px;
}
.stage { padding: 14px 18px; border-left: 3px solid transparent; }
.stage[data-state="warn"] { border-left-color: var(--warn); }
.stage[data-state="crit"] { border-left-color: var(--crit); }
.stage-label { font-size: 12px; color: var(--ink-2); }
.stage-value { font-size: 20px; font-weight: 600; line-height: 1.3; margin-top: 2px; }
.stage-sub { font-size: 12px; color: var(--ink-3); }
.path-link { position: relative; align-self: center; height: 1px; background: var(--line); }
.path-link::after {
  content: ""; position: absolute; right: 0; top: -3px; width: 6px; height: 6px;
  border-top: 1px solid var(--ink-3); border-right: 1px solid var(--ink-3);
  transform: rotate(45deg);
}
.origin-tally { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.origin-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 24px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--ground);
  font-family: var(--mono); font-size: 12px; color: var(--ink-3);
}
.origin-chip b { font-weight: 600; color: var(--ink-3); }
.origin-chip.is-active { border-color: rgba(61, 155, 255, 0.45); background: var(--azure-dim); color: var(--ink); }
.origin-chip.is-active b { color: var(--azure); }
.meter { height: 4px; border-radius: 2px; background: var(--ground); margin-top: 10px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; border-radius: 2px; background: var(--azure); transition: width 0.4s ease; }

/* ---------- KPI strip ---------- */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 16px;
}
.kpi { background: var(--panel); padding: 14px 16px; display: flex; flex-direction: column; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--ink-2); }
.kpi-value { font-size: 28px; font-weight: 600; line-height: 1.2; letter-spacing: -0.02em; margin: 2px 0; }
.kpi-note { font-size: 12px; color: var(--ink-3); }
.kpi-target { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.kpi-target::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); flex: none; }
.kpi[data-state="ok"] .kpi-target::before { background: var(--ok); }
.kpi[data-state="warn"] .kpi-target::before { background: var(--warn); }
.kpi[data-state="crit"] .kpi-target::before { background: var(--crit); }
.kpi[data-state="warn"] .kpi-value { color: var(--warn); }
.kpi[data-state="crit"] .kpi-value { color: var(--crit); }
.kpi[data-state="warn"] .meter-fill { background: var(--warn); }
.kpi[data-state="crit"] .meter-fill { background: var(--crit); }

/* ---------- Main grid ---------- */
.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .grid-main { grid-template-columns: 1fr; } }

.legend { display: flex; gap: 4px; flex-wrap: wrap; }
.legend-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 8px;
  background: transparent; border: 1px solid transparent; border-radius: 4px;
  font-size: 12px; color: var(--ink-2); cursor: pointer;
}
.legend-btn:hover { background: var(--raised); }
.legend-btn[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
.swatch { width: 14px; height: 0; border-top: 2px solid; display: inline-block; }
.swatch-dash { border-top-style: dashed; }
.swatch-dot { border-top-style: dotted; border-top-width: 3px; }

.chart { position: relative; height: 240px; }
.chart svg { display: block; }
.chart-tip {
  position: absolute; top: 8px; z-index: 5; pointer-events: none;
  min-width: 150px; padding: 8px 10px;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); font-size: 12px;
}
.chart-tip[hidden] { display: none; }
.chart-tip strong { display: block; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--ink-2); }
.tip-row span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.tip-row b { color: var(--ink); font-weight: 600; }
.tip-sw { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.empty { padding: 28px 16px; text-align: center; color: var(--ink-3); }

/* ---------- Breakdown bars ---------- */
.bd-group + .bd-group { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.bd-title { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.bd-row { display: grid; grid-template-columns: minmax(90px, 1.2fr) 2fr auto; gap: 10px; align-items: center; padding: 4px 0; font-size: 13px; }
.bd-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd-track { height: 6px; border-radius: 3px; background: var(--ground); overflow: hidden; }
.bd-fill { height: 100%; border-radius: 3px; background: var(--azure); }
.bd-fill.is-t38 { background: var(--ok); }
.bd-fill.is-g711 { background: var(--warn); }
.bd-value { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.bd-value b { color: var(--ink); font-weight: 600; }

/* ---------- Tags ---------- */
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 4px; border: 1px solid;
  font-size: 12px; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.tag-t38 { background: var(--ok-dim); color: #4fd8a2; border-color: rgba(47, 192, 138, 0.4); }
.tag-g711 { background: var(--warn-dim); color: #f0bc57; border-color: rgba(232, 168, 56, 0.4); }
.tag-ok { background: var(--ok-dim); color: #4fd8a2; border-color: rgba(47, 192, 138, 0.4); }
.tag-warn { background: var(--warn-dim); color: #f0bc57; border-color: rgba(232, 168, 56, 0.4); }
.tag-crit { background: var(--crit-dim); color: #ff8a97; border-color: rgba(239, 91, 107, 0.4); }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; max-height: 520px; }
.table-wrap.is-short { max-height: none; }
table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
th {
  position: sticky; top: 0; z-index: 2;
  background: var(--raised); color: var(--ink-2);
  padding: 9px 12px; font-size: 12px; font-weight: 600; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.025); }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--ink-3); }
.cell-id { font-family: var(--mono); font-size: 12px; color: var(--azure); }
.mini-bar { height: 3px; width: 72px; border-radius: 2px; background: var(--ground); margin-top: 4px; overflow: hidden; }
.mini-bar > div { height: 100%; background: var(--azure); }
.trunk-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }

/* ---------- Tabs & toolbars ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 12px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 12px 12px 10px;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--ink-2); font-weight: 600; cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--azure); }
.tab-count { padding: 0 7px; border-radius: 999px; background: var(--raised); color: var(--ink-2); font-size: 12px; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.toolbar-spacer { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.toolbar-count { font-size: 12px; color: var(--ink-3); }

.field {
  height: 32px; padding: 0 10px; min-width: 0;
  background: var(--ground); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); font-size: 13px;
}
.field::placeholder { color: var(--ink-3); }
.field:hover { border-color: #33425f; }
.field:focus { border-color: var(--azure); outline: none; box-shadow: 0 0 0 2px var(--azure-dim); }
.field-search { width: 260px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 14px; border: 1px solid transparent; border-radius: var(--radius);
  background: var(--azure-strong); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #2a7be0; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--raised); border-color: #33425f; }
.btn-ghost[aria-pressed="true"] { background: var(--warn-dim); border-color: rgba(232, 168, 56, 0.5); color: var(--warn); }
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }

/* ---------- Signaling modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(4, 7, 13, 0.78); backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 980px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; font-weight: 600; }
.modal-head p { font-size: 12px; color: var(--ink-2); }
.modal-body { padding: 16px 20px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }

.ladder { display: flex; flex-direction: column; gap: 4px; }
.ladder-step {
  display: grid; grid-template-columns: 96px minmax(0, 1fr) minmax(130px, auto) minmax(0, 1fr);
  gap: 12px; align-items: center; width: 100%; text-align: left; cursor: pointer;
  padding: 8px 12px; background: var(--ground);
  border: 1px solid var(--line-soft); border-left: 3px solid var(--line-soft); border-radius: 4px;
  font-size: 13px;
}
.ladder-step:hover { border-color: #33425f; }
.ladder-step[aria-current="true"] { background: var(--raised); border-color: var(--line); border-left-color: var(--azure); }
.ladder-time { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.ladder-entity { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ladder-entity.is-right { text-align: right; }
.ladder-mid { text-align: center; }
.ladder-arrow { display: block; font-size: 12px; color: var(--ink-3); line-height: 1.2; }

.raw-head { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--ink-2); }
.raw {
  margin: 0; padding: 14px; max-height: 280px; overflow: auto;
  background: #070c16; border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--mono); font-size: 12px; line-height: 1.6; color: #b9d6ff; white-space: pre-wrap;
}

/* ---------- Responsive & motion ---------- */
@media (max-width: 900px) {
  .container { padding: 16px 14px 32px; }
  .topbar-inner { padding: 10px 14px; }
  .path { grid-template-columns: 1fr; }
  .path-link { display: none; }
  .stage + .path-link + .stage { border-top: 1px solid var(--line-soft); }
  .field-search { width: 100%; }
  .ladder-step { grid-template-columns: 1fr; gap: 2px; }
  .ladder-entity.is-right { text-align: left; }
  .ladder-mid { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
