/* Ground network dashboard. Unlayered on purpose: global.css is unlayered, so
   layered rules here would lose to it. Built on the Debrowser tokens (src/styles/tokens.css,
   inlined by the page) and the shared classes in global.css: panel, kicker, tag,
   button. Shipped as a plain file so the inspector shows the authored CSS. */

:root {
  --sidebar-w: 16.5rem;
  --chart-down: var(--orbit-line);
  --chart-up: var(--brand-ultramarine);
  --chart-grid: var(--color-border);
  --row-hover: color-mix(in oklab, var(--color-accent) 7%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root {
    --chart-up: var(--brand-ice);
  }
}
:root body {
  background:
    radial-gradient(60rem 30rem at 85% -10%, var(--halo-soft), transparent 70%),
    var(--stars), var(--color-bg);
  min-height: 100dvh;
}
.muted {
  color: var(--color-text-muted);
  font-size: var(--text-small);
}
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100dvh;

  @media (min-width: 64rem) {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }
}
.sidebar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--gutter);
  background: color-mix(in oklab, var(--color-surface) 72%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--color-border);

  nav {
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  nav ul {
    display: flex;
    gap: var(--space-1);
  }
  .sidebar-card,
  .operator {
    display: none;
  }

  @media (min-width: 64rem) {
    flex-direction: column;
    align-items: stretch;
    height: 100dvh;
    padding: var(--space-5) var(--space-4);
    border-bottom: 0;
    border-right: 1px solid var(--color-border);

    nav ul {
      flex-direction: column;
    }
    .sidebar-card,
    .operator {
      display: grid;
    }
  }
}
.main {
  display: grid;
  gap: var(--space-5);
  align-content: start;
  padding: var(--space-5) var(--gutter) var(--space-7);
  max-width: 90rem;
}
.grid {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: minmax(0, 1fr);

  @media (min-width: 48rem) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    .card-wide,
    .card-map {
      grid-column: 1 / -1;
    }
  }
  @media (min-width: 80rem) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    .card-wide:first-child {
      grid-column: span 2;
    }
    .card-map {
      grid-column: span 2;
    }
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text);
  font-weight: var(--weight-strong);
  font-size: var(--text-h4);
  letter-spacing: var(--tracking-snug);
  white-space: nowrap;

  img {
    border-radius: var(--radius-sm);
    filter: drop-shadow(0 0 10px var(--orbit-glow));
  }
  small {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: var(--weight-mono);
    color: var(--color-text-faint);
    letter-spacing: 0;
  }
  &:hover {
    text-decoration: none;
  }
  @media (max-width: 47.99rem) {
    small {
      display: none;
    }
  }
}
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.5rem;
  padding-inline: var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: var(--text-small);
  white-space: nowrap;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);

  svg {
    width: 1.125rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  &:hover {
    color: var(--color-text);
    background: var(--color-accent-soft);
    text-decoration: none;
  }
  &.active {
    color: var(--color-accent);
    background: var(--color-accent-soft);
    box-shadow: inset 2px 0 0 var(--orbit-line);
  }
  @media (max-width: 63.99rem) {
    span {
      display: none;
    }
    &.active span {
      display: inline;
    }
  }
}
.sidebar-card {
  gap: var(--space-1);
  margin-top: auto;
  padding: var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background:
    linear-gradient(var(--color-surface), var(--color-surface)) padding-box,
    var(--edge-spec) border-box;
  box-shadow: var(--inset-spec);

  .next-sat {
    font-weight: var(--weight-strong);
  }
}
.operator {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  line-height: var(--leading-snug);

  strong {
    font-size: var(--text-small);
    font-weight: var(--weight-strong);
    display: block;
  }
  small {
    color: var(--color-text-faint);
    font-size: var(--text-label);
  }
}
.avatar {
  display: grid;
  place-items: center;
  width: 2.25rem;
  aspect-ratio: 1;
  border-radius: 50%;
  color: var(--color-on-accent);
  font-size: var(--text-label);
  font-weight: var(--weight-strong);
  background: linear-gradient(
    150deg,
    var(--brand-royal),
    var(--brand-ultramarine-800)
  );
  box-shadow: var(--glow-cyan);
}
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-4);

  .title {
    margin-top: var(--space-2);
    font-size: var(--text-h2);
    font-weight: var(--weight-light);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    background: var(--display-fill);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);

  button {
    appearance: none;
    border: 0;
    min-height: 2.25rem;
    padding-inline: var(--space-4);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    font: var(--weight-mono) var(--text-label) / 1 var(--font-mono);
    cursor: pointer;
  }
  button[aria-selected="true"] {
    color: var(--color-text);
    background: var(--color-surface);
    box-shadow: var(--inset-spec), var(--shadow-sm);
  }
}
.button.compact {
  min-height: 2.5rem;
  padding-inline: var(--space-4);
  font-family: inherit;
  cursor: pointer;
}
#live-status {
  &.paused::before {
    background: var(--color-text-faint);
    box-shadow: none;
  }
  &:not(.paused)::before {
    animation: pulse var(--duration-pulse) var(--ease-out) infinite;
  }
}
.card {
  display: grid;
  gap: var(--space-4);
  align-content: start;
  padding: var(--space-5);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-4);

  h2 {
    font-size: var(--text-h4);
    font-weight: var(--weight-strong);
    letter-spacing: var(--tracking-snug);
    line-height: var(--leading-snug);
  }
}
.legend {
  display: flex;
  gap: var(--space-4);
  font: var(--weight-mono) var(--text-label) / 1.2 var(--font-mono);
  color: var(--color-text-muted);

  li {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }
}
.dot {
  width: 0.5rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 8px var(--c);
}
.dot-down {
  --c: var(--chart-down);
}
.dot-up {
  --c: var(--chart-up);
}

.kpis {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));

  @media (min-width: 64rem) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-5);
  }
}
.kpi {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(var(--color-surface), var(--color-surface)) padding-box,
    var(--edge-spec) border-box;
  box-shadow: var(--inset-spec), var(--shadow-md);
  overflow: hidden;

  canvas {
    width: 100%;
    height: 3rem;
  }
  &.skeleton :is(.kpi-label, .kpi-value) {
    border-radius: var(--radius-xs);
    background: var(--color-surface-raised);
    color: transparent;
  }
}
.kpi-label {
  font: var(--weight-mono) var(--text-label) / 1.2 var(--font-mono);
  color: var(--color-text-muted);
}
.kpi-value {
  font-size: clamp(1.75rem, 1.3rem + 1.6vw, 2.5rem);
  font-weight: var(--weight-light);
  line-height: 1;
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;

  small {
    font-size: 0.5em;
    color: var(--color-text-muted);
    margin-left: 0.15em;
    letter-spacing: 0;
  }
}
.delta {
  font: var(--weight-mono) 0.75rem / 1 var(--font-mono);
  color: var(--color-success);

  &.down {
    color: var(--color-danger);
  }
  &.good-down {
    color: var(--color-success);
  }
}

.map {
  width: 100%;
  border-radius: var(--radius-md);
  background: var(--stage);
  border: 1px solid var(--color-border);
}
.forecast {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: var(--space-2);

  li {
    display: grid;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--color-surface-raised);
    font: var(--weight-mono) 0.75rem / 1.3 var(--font-mono);
    color: var(--color-text-muted);
    animation: rise var(--duration-base) var(--ease-out) both;
  }
  strong {
    color: var(--color-text);
    font-weight: var(--weight-strong);
  }
}

.table-wrap {
  overflow-x: auto;
  margin-inline: calc(var(--space-5) * -1);
  padding-inline: var(--space-5);
}
.activity {
  width: 100%;
  min-width: 40rem;
  border-collapse: collapse;
  font-size: var(--text-small);

  th {
    text-align: left;
    font: var(--weight-mono) 0.75rem / 1.2 var(--font-mono);
    color: var(--color-text-faint);
    padding: 0 var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--color-border-strong);
  }
  td {
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
  }
  td:first-child,
  td.num {
    font-family: var(--font-mono);
    font-size: var(--text-label);
    color: var(--color-text-muted);
  }
  tbody tr {
    transition: background-color var(--duration-fast) var(--ease-out);
    &:hover {
      background: var(--row-hover);
    }
    &.fresh {
      animation: flash 1.6s var(--ease-out);
    }
  }
}
.status {
  &.ok::before {
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
  }
  &.warn::before {
    background: var(--color-warning);
    box-shadow: 0 0 6px var(--color-warning);
  }
  &.error::before {
    background: var(--color-danger);
    box-shadow: 0 0 6px var(--color-danger);
  }
}
.foot {
  color: var(--color-text-faint);
  font-size: var(--text-label);
  font-family: var(--font-mono);
}

.chart svg,
.bars svg,
.donut-wrap svg {
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart {
  .grid-line {
    stroke: var(--chart-grid);
    stroke-dasharray: 2 4;
  }
  .axis {
    fill: var(--color-text-faint);
    font: var(--weight-mono) 11px var(--font-mono);
  }
  .area-down {
    fill: url(#fill-down);
  }
  .line-down {
    fill: none;
    stroke: var(--chart-down);
    stroke-width: 2;
    filter: drop-shadow(0 0 6px var(--orbit-glow));
  }
  .area-up {
    fill: url(#fill-up);
  }
  .line-up {
    fill: none;
    stroke: var(--chart-up);
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
  }
  .line-down {
    animation: draw 1.2s var(--ease-out) both;
  }
}
.bars {
  .bar {
    fill: url(#fill-bar);
    transform-box: fill-box;
    transform-origin: bottom;
    animation: grow 700ms var(--ease-out) both;
    animation-delay: calc(var(--i) * 60ms);
  }
  .bar-label,
  .bar-value {
    font: var(--weight-mono) 11px var(--font-mono);
    fill: var(--color-text-faint);
  }
  .bar-value {
    fill: var(--color-text-muted);
  }
}
.donut-wrap {
  display: grid;
  grid-template-columns: minmax(8rem, 11rem) 1fr;
  align-items: center;
  gap: var(--space-5);

  .seg {
    fill: none;
    stroke-width: 14;
    stroke-linecap: butt;
    transition: stroke-width var(--duration-fast) var(--ease-out);
    &:hover {
      stroke-width: 18;
    }
  }
  .donut-total {
    fill: var(--color-text);
    font-size: 22px;
    font-weight: var(--weight-light);
  }
  .donut-caption {
    fill: var(--color-text-faint);
    font: var(--weight-mono) 9px var(--font-mono);
  }
  ul {
    display: grid;
    gap: var(--space-2);
    font: var(--weight-mono) var(--text-label) / 1.2 var(--font-mono);
    color: var(--color-text-muted);
  }
  li {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: var(--space-2);
  }
  li b {
    color: var(--color-text);
    font-weight: var(--weight-mono);
  }
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 4px
      color-mix(in oklab, var(--color-success) 25%, transparent);
  }
}
@keyframes rise {
  from {
    opacity: 0;
    translate: 0 6px;
  }
}
@keyframes grow {
  from {
    scale: 1 0;
  }
}
@keyframes draw {
  from {
    stroke-dashoffset: var(--len, 2000);
    stroke-dasharray: var(--len, 2000);
  }
  to {
    stroke-dasharray: var(--len, 2000);
  }
}
@keyframes flash {
  from {
    background: var(--color-accent-soft);
  }
}

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