:root {
  color-scheme: dark;
  --bg: #07101e;
  --panel: #10233e;
  --line: #2c557d;
  --text: #edf4fb;
  --muted: #aebdd0;
  --up: #56d28b;
  --down: #ef5b5b;
  --mixed: #f4c95d;
  --accent: #e6b86c;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  min-width: 320px;
}

a {
  color: #8bc9ff;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #0b192c;
}

.global-mpc-status {
  order: -1;
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  min-height: 42px;
  margin: -18px -24px 0;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  background: #13253d;
  color: #edf4fb;
  font-weight: 750;
}

.global-mpc-status::before {
  content: "";
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  border-radius: 50%;
  background: #8a96a8;
  box-shadow: 0 0 0 3px rgb(138 150 168 / 18%);
}

.global-mpc-status.up {
  background: #0e3229;
}

.global-mpc-status.up::before {
  background: #56d28b;
  box-shadow: 0 0 0 3px rgb(86 210 139 / 20%);
}

.global-mpc-status.down {
  background: #421d25;
}

.global-mpc-status.down::before {
  background: #ef5b5b;
  box-shadow: 0 0 0 3px rgb(239 91 91 / 22%);
}

.global-mpc-status.regional {
  background: #493912;
}

.global-mpc-status.regional::before {
  background: #ffd45a;
  box-shadow: 0 0 0 3px rgb(255 212 90 / 22%);
}

.global-mpc-status small {
  color: inherit;
  font-weight: 500;
  opacity: 0.88;
}

.own-station-label {
  border-color: #ffd45a;
  background: #101d31;
  color: #fff2b7;
  font-weight: 800;
}

header > img {
  width: 58px;
  height: 58px;
}

header h1 {
  margin: 0;
  font-size: 1.35rem;
}

header p {
  margin: 2px 0;
  color: var(--muted);
}

.header-sample {
  width: min(34vw, 360px);
  min-width: 250px;
  margin-left: auto;
}

.header-sample img,
.sample-map img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.sample-map {
  margin: 0;
}

.sample-map figcaption {
  margin-top: 9px;
  color: var(--muted);
}

.client-required {
  padding: 16px;
  border: 1px solid #47749d;
  border-radius: 9px;
  background: #0b1d33;
}

.client-required h3 {
  margin: 0 0 8px;
  color: var(--text);
}

.client-required ol {
  margin: 10px 0 14px;
}

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 980px);
  gap: 24px;
  padding: 24px;
  transition: grid-template-columns 0.16s ease;
}

.layout.nav-collapsed {
  grid-template-columns: 64px minmax(0, 980px);
}

.nav {
  position: sticky;
  top: 16px;
  height: max-content;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 8px;
}

.nav-toggle {
  width: 32px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #091728;
  color: var(--text);
  cursor: pointer;
}

.nav-toggle:hover,
.nav a:hover {
  background: #183454;
}

.nav a {
  display: block;
  padding: 8px;
  text-decoration: none;
}

.nav.collapsed {
  padding: 8px;
}

.nav.collapsed .nav-head strong,
.nav.collapsed .nav-links {
  display: none;
}

.nav.collapsed .nav-head {
  justify-content: center;
  padding: 0;
}

.language-switch {
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
  background: #173250;
  font-weight: 700;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

main {
  min-width: 0;
}

.card {
  padding: 18px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

h2 {
  margin-top: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 1.2rem;
}

.dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #8a96a8;
}

.dot.up,
.legend-dot.up {
  background: var(--up);
}

.dot.down,
.legend-dot.down {
  background: var(--down);
}

.dot.mixed,
.dot-inline.mixed,
.legend-dot.mixed {
  background: var(--mixed);
}

.dot-inline {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 7px;
  border-radius: 50%;
  background: #8a96a8;
}

.dot-inline.up {
  background: var(--up);
}

.dot-inline.down {
  background: var(--down);
}

.quality.mixed {
  color: var(--mixed);
}

code {
  padding: 2px 5px;
  border: 1px solid var(--line);
  background: #06101d;
}

pre {
  padding: 12px;
  border: 1px solid var(--line);
  background: #06101d;
  white-space: pre-wrap;
}

.button {
  display: inline-block;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: #25689a;
  color: #fff;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  background: #307eb6;
}

.button.secondary {
  border-color: #47749d;
  background: #10233e;
}

.button.secondary:hover {
  background: #183b60;
}

.download-card {
  border-color: #47749d;
}

.download-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.download-grid .button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  text-align: center;
}

.notice {
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: #091728;
}

.ticket-expiry {
  padding: 9px 12px;
  border-left: 4px solid var(--mixed);
  background: #091728;
}

li + li {
  margin-top: 6px;
}

#map {
  width: 100%;
  height: min(68vh, 680px);
  min-height: 430px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #091728;
}

.leaflet-container {
  background: #091728;
  font: 14px system-ui;
}

.leaflet-control-zoom a {
  border-color: #2c557d !important;
  background: #10233e !important;
  color: #edf4fb !important;
}

.map-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}

.map-badge {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #091728;
}

.legend-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 5px;
  border-radius: 50%;
}

.legend-dot.stale {
  background: #8a96a8;
}

.legend-dot.historical {
  box-sizing: border-box;
  border: 2px solid #8a96a8;
  background: transparent;
}

.legend-dot.own {
  box-sizing: border-box;
  border: 3px solid #ffd45a;
  background: transparent;
}

.map-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.history-intro,
.history-downloads {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr);
  gap: 24px;
  align-items: start;
}

.history-legend {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #091728;
}

.history-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 7px;
  border-radius: 3px;
  vertical-align: -2px;
}

.history-swatch.up {
  background: var(--up);
}

.history-swatch.down {
  background: var(--down);
}

.history-swatch.mixed {
  background: var(--mixed);
}

.history-swatch.none {
  background: #4c5b70;
}

.history-swatch.active {
  background: #4da3ff;
}

.history-mixed-help {
  position: relative;
  border-radius: 5px;
  outline: none;
  cursor: help;
}

.history-mixed-help > strong {
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  margin-left: 4px;
  border: 1px solid var(--mixed);
  border-radius: 50%;
  color: var(--mixed);
  font-size: 0.78rem;
}

.history-mixed-help:focus-visible {
  outline: 2px solid var(--mixed);
  outline-offset: 4px;
}

.history-tooltip {
  position: absolute;
  z-index: 1000;
  right: 0;
  top: calc(100% + 9px);
  display: none;
  width: min(430px, 78vw);
  padding: 12px 14px;
  border: 2px solid var(--mixed);
  border-radius: 8px;
  background: #07101e;
  color: #fff;
  box-shadow: 0 12px 30px #000a;
  font-weight: 500;
  line-height: 1.45;
}

.history-mixed-help:hover .history-tooltip,
.history-mixed-help:focus .history-tooltip,
.history-mixed-help:focus-within .history-tooltip {
  display: block;
}

.history-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.history-toolbar label {
  display: grid;
  gap: 5px;
  font-weight: 650;
}

.history-toolbar select {
  min-width: 210px;
  padding: 9px 34px 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: #000;
  font: inherit;
}

.checks-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.checks-toolbar label {
  display: grid;
  gap: 5px;
  font-weight: 650;
}

.checks-date-field {
  position: relative;
  display: grid;
  gap: 5px;
  font-weight: 650;
}

.checks-date-control {
  display: flex;
  gap: 6px;
}

.checks-date-control input {
  width: 145px;
  min-width: 145px;
  cursor: pointer;
}

.checks-calendar {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  width: min(330px, calc(100vw - 48px));
  padding: 12px;
  border: 1px solid #3b6b99;
  border-radius: 9px;
  background: #0c2037;
  box-shadow: 0 14px 34px rgb(0 0 0 / 45%);
  font-weight: 400;
}

.checks-calendar-head,
.checks-calendar-weekdays,
.checks-calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.checks-calendar-head {
  grid-template-columns: 38px 1fr 38px;
  align-items: center;
  margin-bottom: 10px;
  text-align: center;
}

.checks-calendar-head button,
.checks-calendar-days button {
  min-height: 34px;
  border: 1px solid #315578;
  border-radius: 6px;
  background: #153654;
  color: #fff;
  font: inherit;
}

.checks-calendar-head button:not(:disabled),
.checks-calendar-days button.available {
  cursor: pointer;
}

.checks-calendar-head button:not(:disabled):hover,
.checks-calendar-days button.available:hover {
  border-color: #70c7ff;
  background: #225a86;
}

.checks-calendar-weekdays {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.checks-calendar-days button.unavailable {
  border-color: #26384d;
  background: #101b2a;
  color: #637386;
  opacity: 0.62;
}

.checks-calendar-days button.selected {
  border-color: #ffd166;
  outline: 2px solid #ffd166;
  background: #246b47;
}

.checks-calendar small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.checks-toolbar input {
  min-width: 190px;
  box-sizing: border-box;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #091728;
  color: #edf4fb;
  font: inherit;
}

.checks-toolbar input[type="search"] {
  width: min(42vw, 430px);
  min-width: 280px;
}

.preview-client-launch {
  flex: 1 0 100%;
  margin: 0;
  padding: 10px 13px;
  border-left: 4px solid #70e3a0;
  border-radius: 4px;
  background: #102f28;
  color: #eafcf2;
}

.preview-client-launch.error {
  border-left-color: #ff7777;
  background: #3b1820;
  color: #fff1f3;
}

.checks-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 10px 0 16px;
}

.checks-pagination .button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
}

.checks-table {
  width: 100%;
  min-width: 1450px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

.checks-table th,
.checks-table td {
  padding: 8px 9px;
  border-right: 1px solid #223f60;
  border-bottom: 1px solid #223f60;
  text-align: left;
  vertical-align: top;
}

.checks-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  border-top: 1px solid var(--line);
  background: #173453;
  color: #fff;
  cursor: pointer;
  user-select: none;
}

.checks-table th:focus,
.checks-table th:hover {
  background: #22507e;
  outline: none;
}

.checks-table th:first-child,
.checks-table td:first-child {
  border-left: 1px solid var(--line);
}

.checks-table tbody tr:nth-child(even) {
  background: #0b1b2f;
}

.checks-table tbody tr:hover {
  background: #173453;
}

.checks-table td.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.check-status {
  font-weight: 750;
}

.check-status.up {
  color: #70e3a0;
}

.check-status.down {
  color: #ff7777;
}

.check-status.reachable,
.check-status.valid {
  color: #70e3a0;
}

.check-status.failed,
.check-status.invalid {
  color: #ff7777;
}

.check-status.unknown,
.check-status.not_received {
  color: var(--muted);
}

.checks-empty {
  padding: 24px !important;
  color: var(--muted);
  text-align: center !important;
}

.checks-table details summary {
  color: var(--link);
  cursor: pointer;
  white-space: nowrap;
}

.checks-table details dl {
  display: grid;
  grid-template-columns: max-content minmax(160px, 1fr);
  gap: 3px 8px;
  margin: 8px 0 0;
  font-size: 0.82rem;
}

.checks-table details dt {
  color: var(--muted);
}

.checks-table details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

#history-loading {
  min-height: 24px;
  color: var(--muted);
}

.history-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.history-summary > div {
  min-height: 88px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #091728;
}

.history-summary strong,
.history-summary span {
  display: block;
}

.history-summary strong {
  margin-bottom: 5px;
  color: #fff;
  font-size: 1.55rem;
}

.history-summary span {
  color: var(--muted);
  line-height: 1.3;
}

.history-chart-card canvas {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #081727;
  cursor: pointer;
}

.history-hover {
  min-height: 24px;
  margin-bottom: 0;
  color: var(--muted);
}

.station-list {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.station-timeline {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #091728;
}

.station-timeline-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  align-items: start;
  justify-content: space-between;
}

.station-timeline h3,
.station-timeline p {
  margin-top: 0;
}

.station-timeline h3 {
  margin-bottom: 4px;
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1rem;
}

.station-timeline-head p,
.station-meta {
  margin-bottom: 8px;
  color: var(--muted);
}

.station-activity-range {
  text-align: right;
}

.station-timeline canvas {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #081727;
  cursor: pointer;
}

.station-actions,
.station-alias-editor,
.station-detail-links {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 9px;
}

.station-actions {
  margin-top: 12px;
}

.station-alias-editor {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #284968;
  border-radius: 7px;
  background: #0b1b2f;
}

.station-alias-editor label {
  display: grid;
  gap: 4px;
  min-width: min(100%, 260px);
  color: var(--muted);
}

.station-alias-editor input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #071525;
  color: var(--text);
  font: inherit;
}

.station-alias-editor small {
  flex: 1 0 100%;
  color: var(--muted);
}

.station-detail-title {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.station-detail-title h2,
.station-detail-title p {
  margin-bottom: 4px;
}

.station-detail-title p {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.own-station-badge {
  padding: 5px 9px;
  border: 1px solid #ffd45a;
  border-radius: 999px;
  background: #493912;
  color: #fff4bc;
}

.station-detail-list,
.incident dl {
  display: grid;
  grid-template-columns: minmax(180px, max-content) minmax(0, 1fr);
  gap: 7px 18px;
  margin: 0;
}

.station-detail-list dt,
.incident dt {
  color: var(--muted);
  font-weight: 650;
}

.station-detail-list dd,
.incident dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.incident-list {
  display: grid;
  gap: 14px;
}

.incident {
  padding: 15px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--down);
  border-radius: 8px;
  background: #091728;
}

.incident.regional_or_changing {
  border-left-color: var(--mixed);
}

.incident.ongoing {
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 10%);
}

.incident h3 {
  margin: 0 0 12px;
}

.download-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

#history-download-status {
  grid-column: 1 / -1;
  min-height: 24px;
  margin: 0;
  color: var(--muted);
}

footer {
  padding: 20px 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

@media (max-width: 1050px) {
  .history-intro,
  .history-downloads {
    grid-template-columns: 1fr;
  }

  .download-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .header-sample {
    width: 100%;
    min-width: 0;
  }

  .layout,
  .layout.nav-collapsed {
    grid-template-columns: 1fr;
  }

  .nav {
    position: static;
  }

  .nav-links {
    display: flex;
    flex-wrap: wrap;
  }

  .station-activity-range {
    text-align: left;
  }

  .station-detail-list,
  .incident dl {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .station-detail-list dd,
  .incident dd {
    margin-bottom: 9px;
  }

  .nav a {
    padding: 6px 9px;
  }

  .nav.collapsed .nav-links {
    display: none;
  }

  .download-grid {
    grid-template-columns: 1fr;
  }

  .history-intro,
  .history-downloads {
    grid-template-columns: 1fr;
  }

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

  .download-actions {
    justify-content: flex-start;
  }
}
