:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #dce2ea;
  --surface: #f4f6f9;
  --panel: #ffffff;
  --nav: #111c33;
  --nav-hover: #1b2a48;
  --blue: #2459d3;
  --blue-soft: #eaf0ff;
  --green: #18794e;
  --green-soft: #e8f7ef;
  --amber: #9a5b00;
  --amber-soft: #fff3df;
  --red: #b42318;
  --red-soft: #feeeee;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  color: var(--ink);
  background: var(--surface);
}

body.signed-out { grid-template-columns: 1fr; }
body.signed-out aside { display: none; }

aside {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  color: white;
  background: var(--nav);
}

.brand,
.auth-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand { padding: 0 8px 24px; }
.brand strong { display: block; font-size: 17px; }
.brand span:not(.brand-mark) { display: block; margin-top: 2px; color: #9fb0ce; font-size: 12px; }

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 9px;
  color: white;
  background: var(--blue);
  font-weight: 800;
  font-size: 18px;
}

nav { display: grid; gap: 5px; }

nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #cbd5e5;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

nav a:hover,
nav a.active { color: white; background: var(--nav-hover); }

.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7083a4;
}

nav a.active .nav-dot { background: #71a0ff; box-shadow: 0 0 0 3px rgb(113 160 255 / 18%); }

.user-summary {
  margin-top: auto;
  padding: 14px 8px 2px;
  border-top: 1px solid rgb(255 255 255 / 12%);
}

.user-name { font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
.user-role { margin-top: 3px; color: #9fb0ce; font-size: 12px; }

.quiet-button {
  width: 100%;
  margin-top: 12px;
  color: #dbe4f3;
  background: transparent;
  border-color: rgb(255 255 255 / 18%);
}

main { min-width: 0; }

.toolbar {
  padding: 18px 24px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
.toolbar h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.page-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.content {
  display: grid;
  gap: 16px;
  padding: 16px 20px 24px;
}

.loading-card,
.empty-state,
.section-card,
.metric-card,
.grafana-shell,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.loading-card,
.empty-state { padding: 28px; color: var(--muted); text-align: center; }

.grafana-shell { overflow: hidden; }
.grafana-frame { display: block; width: 100%; min-height: 1120px; border: 0; background: white; }
.grafana-panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grafana-panel-frame { display: block; width: 100%; min-height: 340px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.grafana-panel-frame.wide { grid-column: 1 / -1; min-height: 420px; }
.graphs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.graphs-toolbar p { margin: 0; color: var(--muted); font-size: 13px; }
.action-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--blue);
  border-radius: 7px;
  color: white;
  background: var(--blue);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.action-link:hover { filter: brightness(.96); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card { padding: 14px 16px; }
.metric-card span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.metric-card strong { display: block; margin-top: 8px; font-size: 20px; line-height: 1.2; }
.metric-grid.compact .metric-card strong { font-size: 17px; }

.section-card { padding: 18px; }
.section-heading { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-heading h2, .user-card-header h2 { margin: 0; font-size: 17px; }
.section-heading p, .user-card-header p { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.table-wrap { overflow-x: auto; border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 13px; }
th { color: var(--muted); background: #fafbfc; font-size: 11px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }

.status {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  color: #41516d;
  background: #edf1f6;
  font-size: 11px;
  font-weight: 800;
  text-transform: capitalize;
  white-space: nowrap;
}

.status.completed, .status.low { color: var(--green); background: var(--green-soft); }
.status.running, .status.medium, .status.partial { color: var(--amber); background: var(--amber-soft); }
.status.failed, .status.high, .status.critical, .status.disabled { color: var(--red); background: var(--red-soft); }
.good-text { color: var(--green); }
.danger-text { color: var(--red); }
.warning-text { color: var(--amber); }
.status.matched { color: var(--green); background: var(--green-soft); }
.status.mismatch { color: var(--red); background: var(--red-soft); }
.status.partial { color: var(--amber); background: var(--amber-soft); }
.status.unavailable { color: #475467; background: #eef1f5; }

.filter-card {
  display: grid;
  gap: 13px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.filter-grid {
  display: grid;
  grid-template-columns: minmax(160px, 1.2fr) minmax(135px, .9fr) minmax(185px, 1fr) minmax(185px, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.filter-grid label,
.filter-grid input,
.filter-grid select { min-width: 0; }
.filter-grid button { min-width: 112px; }
.range-presets { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.range-presets > span { margin-right: 3px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.range-presets button {
  min-height: 30px;
  padding: 5px 10px;
  color: #344054;
  border-color: #cbd3df;
  background: white;
  font-size: 12px;
}
.range-presets button.active { color: var(--blue); border-color: #a9bff3; background: var(--blue-soft); }
.calendar-period-controls {
  display: grid;
  grid-template-columns: minmax(175px, .7fr) minmax(300px, 1.4fr) auto;
  align-items: end;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.month-period-picker { min-width: 0; }
.month-period-picker select { min-width: 0; }
.period-navigation {
  display: grid;
  grid-template-columns: 36px minmax(190px, 1fr) 36px;
  align-items: center;
  gap: 8px;
}
.period-navigation button {
  min-width: 36px;
  min-height: 36px;
  padding: 4px;
  color: var(--blue);
  border-color: #b8c8ec;
  background: var(--blue-soft);
  font-size: 18px;
}
.period-navigation button:disabled { color: #98a2b3; border-color: var(--line); background: #f4f5f7; }
.period-navigation span {
  overflow: hidden;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.period-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.failure-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: 0;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.failure-toggle input { width: 16px; min-height: 16px; margin: 0; }
.graphs-button {
  color: white;
  border-color: var(--blue);
  background: var(--blue);
}

#call-stats-results { display: grid; gap: 16px; }
#bell-mobile-results { display: grid; gap: 16px; }
.bell-filter-grid { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto; align-items: end; gap: 12px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.dashboard-grid .wide { grid-column: 1 / -1; }
.chart-card { min-width: 0; }
.svg-chart-scroll { width: 100%; overflow-x: auto; overflow-y: hidden; }
.bar-chart-svg, .line-chart { display: block; min-width: 100%; }
.chart-tick line { stroke: #e3e7ed; stroke-width: 1; }
.chart-tick text, .chart-x-tick text, .chart-month-label, .chart-bar-value, .chart-bar-context, .allowance-label { fill: var(--muted); font-size: 10px; }
.chart-bar-context { font-size: 9px; font-weight: 700; }
.chart-x-tick line { stroke: #cfd6e1; stroke-width: 1; }
.chart-axis-title { fill: #475467; font-size: 11px; font-weight: 700; }
.chart-bar { fill: var(--blue); rx: 4px; }
.chart-bar.green { fill: var(--green); }
.chart-bar.amber { fill: #d58a14; }
.chart-bar.red { fill: #c84b3f; }
.chart-bar:hover { filter: brightness(.88); }
.line-chart-wrap { display: grid; gap: 8px; }
.allowance-line { stroke: #8a94a6; stroke-width: 1.5; stroke-dasharray: 7 5; }
.chart-line { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.average { stroke: var(--blue); }
.chart-line.median { stroke: var(--green); }
.chart-line.max { stroke: #c84b3f; }
.chart-point { stroke: white; stroke-width: 1.5; }
.chart-point.average { fill: var(--blue); }
.chart-point.median { fill: var(--green); }
.chart-point.max { fill: #c84b3f; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 11px; }
.legend::before { content: ""; display: inline-block; width: 14px; height: 3px; margin: 0 6px 3px 0; background: currentColor; }
.legend.average { color: var(--blue); }
.legend.median { color: var(--green); }
.legend.max { color: #c84b3f; }
.legend.allowance { color: #8a94a6; }
.line-grid-card { overflow: hidden; }
.line-grid-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 12px; color: var(--muted); font-size: 11px; }
.line-grid-toolbar > span strong { color: #344054; }
.line-grid-toolbar label { width: 150px; }
.line-grid-toolbar select { min-height: 32px; padding: 5px 8px; font-size: 12px; }
.line-grid-controls { display: flex; align-items: end; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.line-month-control { display: flex; align-items: end; gap: 5px; }
.line-month-control label { width: 130px; }
.line-month-control button { width: 32px; min-height: 32px; padding: 4px; }
.line-usage-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 20px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfd; }
.line-usage-row { min-width: 0; display: grid; grid-template-columns: 28px minmax(80px, 1fr) 70px; align-items: center; gap: 7px; border-bottom: 1px solid #edf0f4; font-size: 10px; }
.line-usage-row strong { color: #344054; font-size: 10px; font-variant-numeric: tabular-nums; }
.usage-progress-wrap { position: relative; display: block; height: 10px; }
.usage-progress { width: 100%; height: 10px; appearance: none; overflow: hidden; border: 0; border-radius: 999px; background: #e7ebf1; }
.usage-progress::-webkit-progress-bar { border-radius: 999px; background: #e7ebf1; }
.usage-progress::-webkit-progress-value { border-radius: 999px; }
.usage-progress.low::-webkit-progress-value { background: var(--green); }
.usage-progress.medium::-webkit-progress-value { background: #d58a14; }
.usage-progress.high::-webkit-progress-value { background: #c84b3f; }
.usage-progress.low::-moz-progress-bar { background: var(--green); }
.usage-progress.medium::-moz-progress-bar { background: #d58a14; }
.usage-progress.high::-moz-progress-bar { background: #c84b3f; }
.usage-threshold { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(52, 64, 84, .55); pointer-events: none; }
.usage-threshold-10 { left: 50%; }
.usage-number { color: #475467; font-size: 9px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.usage-band-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.usage-band-legend span::before { content: ""; display: inline-block; width: 11px; height: 7px; margin: 0 5px 1px 0; border-radius: 999px; }
.usage-band-legend .low::before { background: var(--green); }
.usage-band-legend .medium::before { background: #d58a14; }
.usage-band-legend .high::before { background: #c84b3f; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.pagination button { min-height: 32px; padding: 5px 10px; }
.metric-card small { display: block; margin-top: 7px; line-height: 1.35; }
.quality-notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 15px;
  color: #744500;
  border: 1px solid #efd3a5;
  border-radius: 9px;
  background: var(--amber-soft);
  font-size: 13px;
  line-height: 1.45;
}
.quality-notice strong { white-space: nowrap; }
.section-meta { align-self: flex-start; color: var(--muted); font-size: 12px; white-space: nowrap; }
.table-note { display: block; max-width: 360px; margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.table-footnote { margin: 11px 0 0; color: var(--muted); font-size: 12px; }
.method-note {
  padding: 12px 15px;
  color: #526078;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f9fafb;
  font-size: 12px;
  line-height: 1.5;
}
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}
.pagination-summary { margin-right: auto; font-variant-numeric: tabular-nums; }
.rows-per-page { display: flex; align-items: center; gap: 7px; }
.rows-per-page select { width: auto; min-width: 76px; min-height: 34px; padding: 5px 28px 5px 8px; }
.page-buttons { display: flex; align-items: center; gap: 8px; }
.page-buttons span { min-width: 82px; text-align: center; font-variant-numeric: tabular-nums; }
button.secondary-button {
  min-height: 34px;
  padding: 6px 10px;
  color: #344054;
  border-color: #cbd3df;
  background: white;
  font-size: 12px;
}
.failure-metric { border-color: #e7c7c2; background: #fff8f7; }
.failure-section { border-left: 4px solid #b5473c; }
.failure-trend { display: grid; gap: 8px; }
.trend-row { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: 10px; }
.trend-row time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.trend-bars { display: flex; min-height: 22px; overflow: hidden; border-radius: 5px; background: #f1f3f6; }
.trend-bar { display: grid; place-items: center; min-width: 18px; color: white; font-size: 10px; }
.trend-bar.telnyx { background: #2459d3; }
.trend-bar.sogetel { background: #b5473c; }
.trend-bar.bulkvs { background: #7a5af8; }
.trend-bar.voip-ms { background: #008a78; }
.trend-bar.unmapped { background: #667085; }
.trend-bar.failover { background: #d97706; }

button,
input,
select { font: inherit; }

button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--blue);
  border-radius: 7px;
  color: white;
  background: var(--blue);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

button:hover { filter: brightness(.96); }
button:disabled { opacity: .55; cursor: wait; }

label { display: grid; gap: 6px; color: #344054; font-size: 12px; font-weight: 700; }
input, select {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid #cbd3df;
  border-radius: 7px;
  color: var(--ink);
  background: white;
  font-size: 14px;
}

input:focus, select:focus { outline: 3px solid rgb(36 89 211 / 14%); border-color: var(--blue); }
small, .optional { color: var(--muted); font-weight: 400; }

.auth-shell {
  width: min(440px, calc(100% - 32px));
  margin: 8vh auto 0;
}

.auth-brand { justify-content: center; margin-bottom: 18px; font-size: 18px; }
.auth-card { padding: 28px; border: 1px solid var(--line); border-radius: 13px; background: white; box-shadow: 0 14px 40px rgb(20 32 55 / 8%); }
.auth-card h1 { margin: 0; font-size: 25px; }
.auth-description { margin: 8px 0 22px; color: var(--muted); line-height: 1.5; font-size: 14px; }
.form-stack { display: grid; gap: 15px; }
.form-stack button { margin-top: 3px; }

.form-message { display: inline-block; padding: 10px 12px; border-radius: 7px; font-size: 13px; }
.form-message.error { color: var(--red); background: var(--red-soft); }
.form-message.success { color: var(--green); background: var(--green-soft); }

.user-create-grid,
.user-edit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.password-reset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.user-create-grid fieldset, .user-create-grid .form-actions { grid-column: 1 / -1; }
.user-list { display: grid; gap: 12px; }
.user-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }

fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 16px 0 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend { padding: 0 5px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
label.check { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; }
label.check input { width: 16px; min-height: 16px; margin: 0; }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 15px; }

@media (max-width: 1280px) {
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-grid button { width: 100%; }
  .line-usage-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-grid .wide { grid-column: auto; }
  .line-usage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  body { grid-template-columns: 1fr; }
  aside { position: static; width: 100%; height: auto; padding-bottom: 12px; }
  .brand { padding-bottom: 14px; }
  nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .user-summary { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px; margin-top: 14px; }
  .quiet-button { grid-column: 2; grid-row: 1 / span 2; width: auto; margin: 0; }
  .toolbar { padding: 16px; }
  .content { padding: 12px; }
  .metric-grid, .user-create-grid, .user-edit-grid, .password-reset-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .bell-filter-grid { grid-template-columns: 1fr; }
  .line-grid-toolbar { display: grid; }
  .line-grid-controls { justify-content: stretch; }
  .line-month-control { flex: 1 1 100%; }
  .line-month-control label { width: auto; flex: 1; }
  .line-grid-controls > label { width: 100%; }
  .line-usage-grid { grid-template-columns: 1fr; }
  .calendar-period-controls { grid-template-columns: 1fr; }
  .period-navigation { grid-template-columns: 40px minmax(0, 1fr) 40px; }
  .period-actions { display: grid; justify-content: stretch; }
  .quality-notice, .section-heading { display: grid; }
  .graphs-toolbar { display: grid; }
  .graphs-button { width: 100%; margin-left: 0; }
  .failure-toggle { width: 100%; margin-left: 0; }
  .pagination-bar, .page-buttons { flex-wrap: wrap; }
  .pagination-summary { width: 100%; }
  .section-meta { white-space: normal; }
  .grafana-frame { min-height: 1200px; }
  .grafana-panel-grid { grid-template-columns: 1fr; }
  .grafana-panel-frame.wide { grid-column: auto; }
}
