:root {
  --accent: #d81b60;
  --accent-soft: #fce4ec;
  --accent-rgb: 216, 27, 96;
  --success: #00ba7c;
  --info: #3b82f6;
  --warn: #f59e0b;
  --danger: #e5484d;
  --violet: #856ac4;

  --bg: #fcfcfd;
  --bg-soft: #f5f7fa;
  --text: #1a2a44;
  --text-muted: #657786;
  --border: #e1e8ed;
  --topbar-bg: rgba(255, 255, 255, .85);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --topbar-h: 60px;
  --page-max: 1120px;
}

:root[data-theme="dark"] {
  --bg: #0f1419;
  --bg-soft: #16181c;
  --text: #e7e9ea;
  --text-muted: #71767b;
  --border: #2f3336;
  --danger: #ff5d62;
  --accent-soft: #2a1622;
  --violet: #ae98eb;
  --topbar-bg: rgba(15, 20, 25, .85);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

button,
input {
  font-family: inherit;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
}

.tb-left,
.tb-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tb-left {
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-name {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.01em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .2s var(--ease);
}

.topbar.scrolled .brand-name {
  opacity: 1;
}

.brand-logo {
  display: block;
  width: 24px;
  height: 24px;
  color: var(--accent);
}

.theme-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.theme-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.theme-btn .i-sun {
  display: none;
}

:root[data-theme="dark"] .theme-btn .i-sun {
  display: block;
}

:root[data-theme="dark"] .theme-btn .i-moon {
  display: none;
}

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 32px 18px 64px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.15;
}

.updated-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 22px 0 24px;
}

.stat {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.stat:hover,
.stat.active {
  border-color: var(--accent);
}

.stat-val {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
}

.stat-label {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.stat.operational .stat-val { color: var(--success); }
.stat.degraded .stat-val    { color: var(--warn); }
.stat.outage .stat-val      { color: var(--danger); }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-bottom: 14px;
}

.search-wrap {
  position: relative;
  flex: 1 1 240px;
  max-width: 360px;
}

.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  outline: none;
}

.search-input:focus-visible {
  border-color: var(--accent);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.filters {
  position: relative;
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
}

.filter-btn:hover,
.filter-btn.active,
.filters.open .filter-btn {
  border-color: var(--accent);
}

.filter-btn svg {
  color: var(--text-muted);
}

.filter-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  color: #fff;
  background: var(--accent);
}

.filter-count:empty {
  display: none;
}

.filter-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  min-width: 220px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .14);
}

.filters.open .filter-panel {
  display: block;
}

.filter-group {
  padding: 10px 14px 6px;
}

.filter-group + .filter-group {
  border-top: 1px solid var(--border);
}

.filter-group-name {
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.filter-check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 0;
  font-size: 14px;
  cursor: pointer;
}

.filter-check input {
  margin: 0;
  accent-color: var(--accent);
}

.filter-clear {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 13px;
  text-align: left;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}

.filter-clear:hover {
  color: var(--accent);
}

.filter-overlay {
  display: none;
}

.sort-wrap {
  position: relative;
}

.sort-wrap::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 12px;
  width: 12px;
  height: 12px;
  transform: translateY(-50%);
  background: var(--text-muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  pointer-events: none;
}

.sort-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 36px 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  outline: none;
}

.sort-select:focus-visible {
  border-color: var(--accent);
}

.toolbar-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.tool-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-muted);
  cursor: pointer;
}

.tool-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.list-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  overflow: clip;
}

.t-head,
.t-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
}

.t-head {
  position: sticky;
  top: var(--topbar-h);
  z-index: 10;
  height: 40px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-label {
  padding: 14px 16px 6px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.t-row-wrap:not([hidden]) ~ .t-row-wrap {
  border-top: 1px solid var(--border);
}

.t-row {
  min-height: 52px;
  padding-top: 12px;
  padding-bottom: 12px;
  cursor: pointer;
  transition: background .15s var(--ease);
}

.t-row:hover {
  background: var(--bg-soft);
}

.c-model,
.td-model {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
}

.c-route,
.td-route {
  width: 80px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.c-meta,
.td-meta {
  width: 132px;
  flex-shrink: 0;
  display: flex;
  gap: 6px;
}

.td-nums {
  display: contents;
}

.c-num,
.td-num {
  width: 88px;
  flex-shrink: 0;
  text-align: right;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-muted);
}

.td-num.dim {
  opacity: .5;
}

.c-status,
.td-status {
  width: 124px;
  flex-shrink: 0;
  text-align: right;
}

.chevron {
  width: 14px;
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform .15s var(--ease);
}

.t-row.expanded .chevron {
  transform: rotate(180deg);
}

.route-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}

.route-dot.operational   { background: var(--success); }
.route-dot.degraded      { background: var(--warn); }
.route-dot.outage        { background: var(--danger); }
.route-dot.misconfigured { background: var(--violet); }
.route-dot.nodata        { background: var(--border); }

.route-dot.none {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--text-muted);
  opacity: .45;
}

.route-dot.serving {
  outline: 1.5px solid var(--text-muted);
  outline-offset: 2px;
}

.model-name {
  font-family: var(--mono);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 20px;
  background: var(--bg-soft);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.status-pill.operational { color: var(--success); background: rgba(0, 186, 124, .14); }
.status-pill.degraded    { color: var(--warn);    background: rgba(245, 158, 11, .16); }
.status-pill.outage      { color: var(--danger);  background: rgba(229, 72, 77, .14); }

.status-note {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.empty-state {
  display: none;
  padding: 48px 16px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

.history-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .25s var(--ease);
  background: var(--bg-soft);
}

.history-panel.open {
  grid-template-rows: 1fr;
}

.history-inner {
  min-height: 0;
  overflow: hidden;
}

.history-panel.open .history-inner {
  padding-bottom: 24px;
}

.t-row.expanded {
  background: var(--bg-soft);
}

.history-inner > * {
  margin-left: 35px;
  margin-right: 16px;
}

.history-inner > :first-child {
  margin-top: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .history-panel,
  .chevron {
    transition: none;
  }

  .fade-in {
    animation: none;
  }
}

.history-loading {
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-muted);
}

.panel-nums {
  display: none;
}

.bars-row {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 28px;
}

.chain {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}

.chain-hop {
  flex: 1;
  min-width: 0;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px 10px;
  cursor: pointer;
}

.chain-hop:hover,
.chain-hop.open {
  background: rgba(var(--accent-rgb), .08);
}

.chain-name {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chain-name.degraded      { color: var(--warn); }
.chain-name.outage        { color: var(--danger); }
.chain-name.misconfigured { color: var(--violet); }

.hop-detail {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.hop-detail-item + .hop-detail-item {
  margin-top: 16px;
}

.hop-detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
}

.hop-detail-where {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.hop-detail-role {
  font-size: 13px;
  color: var(--text-muted);
}

.hop-detail-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.hop-detail-where.misconfigured  { color: var(--violet); }
.hop-detail-status.operational   { color: var(--success); }
.hop-detail-status.degraded      { color: var(--warn); }
.hop-detail-status.outage        { color: var(--danger); }
.hop-detail-status.misconfigured { color: var(--violet); }

.hop-detail-num,
.hop-detail-checked {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
}

.hop-detail-model {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text);
  opacity: .8;
}

.hop-detail-error {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.chain-slug {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-muted);
  opacity: .6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chain-role {
  margin-top: 10px;
  font-size: 10.5px;
  color: var(--text-muted);
}

.bars-row.mini {
  margin-top: 10px;
  height: 12px;
}

.timeline-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.bar {
  flex: 1;
  min-width: 1px;
  height: 100%;
  border-radius: 2px;
  background: var(--border);
  cursor: default;
}

.bar.operational   { background: var(--success); }
.bar.degraded      { background: var(--warn); }
.bar.outage        { background: var(--danger); }
.bar.misconfigured { background: var(--violet); }
.bar.nodata        { background: var(--border); }

.bar:hover {
  opacity: .75;
}

.global-tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  display: none;
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.legend {
  margin-top: 36px;
}

.legend-title {
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.legend-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.legend-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name {
  font-size: 15px;
  font-weight: 700;
}

.legend-desc {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-muted);
}

.legend-desc b {
  color: var(--text);
  font-weight: 600;
}

.page-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 16px;
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
}

.loading-state {
  padding: 80px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 20px;
  height: 20px;
  margin: 0 auto 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.fade-in {
  animation: fade-in .15s var(--ease);
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (max-width: 960px) {
  .c-meta,
  .td-meta {
    display: none;
  }

  .search-wrap {
    flex-basis: 100%;
    max-width: none;
  }
}

@media (max-width: 720px) {
  .page {
    padding: 22px 16px 48px;
  }

  .page-title {
    font-size: 26px;
  }

  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-val {
    font-size: 22px;
  }

  .t-head {
    display: none;
  }

  .t-row {
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 10px 14px;
  }

  .td-model {
    flex: 1 1 0;
  }

  .td-status {
    width: auto;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .status-pill {
    width: 10px;
    height: 10px;
    padding: 0;
    border-radius: 50%;
    font-size: 0;
    color: transparent;
  }

  .status-pill.operational { background: var(--success); }
  .status-pill.degraded    { background: var(--warn); }
  .status-pill.outage      { background: var(--danger); }

  body[data-internal="1"] .status-pill {
    display: none;
  }

  .status-note {
    order: -1;
    margin: 0;
  }

  .td-route {
    flex-basis: 100%;
    order: 1;
  }

  .td-nums {
    display: none;
  }

  .history-inner > * {
    margin-left: 14px;
    margin-right: 14px;
  }

  .panel-nums {
    display: block;
    padding-top: 10px;
    font-family: var(--mono);
    font-size: 13px;
    color: var(--text-muted);
  }

  .filters,
  .sort-wrap {
    flex: 1 1 0;
    min-width: 0;
  }

  .filter-btn,
  .sort-select {
    width: 100%;
  }

  .filter-btn {
    justify-content: center;
  }

  .filter-panel {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    min-width: 0;
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: 16px 16px 0 0;
    box-shadow: none;
  }

  .filters.open + .filter-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, .45);
  }

  .toolbar-actions {
    margin-left: 0;
  }

  .chain {
    flex-direction: column;
    gap: 8px;
  }

  .chain-hop {
    text-align: left;
  }

  .bars-row {
    height: 22px;
  }
}
