.sar-app .skip:focus,
.sar-app .skip:focus-visible {
  position: static;
  transform: none;
  display: inline-block;
  width: fit-content;
  max-width: calc(100% - 1rem);
  margin: 0.35rem 0.5rem 0;
}

.sar-app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sar-app .wrap {
  width: min(1440px, calc(100% - 1rem));
  padding: 0.45rem 0 0.4rem;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sar-app .top {
  margin-bottom: 0.35rem;
}

.sar-app h1 {
  font-size: clamp(1.25rem, 2vw, 1.7rem);
}

.sar-app .disclaimer,
.sar-app .foot {
  font-size: 0.82rem;
  line-height: 1.35;
}

.sar-app .disclaimer {
  color: var(--text);
  margin-bottom: 0.45rem;
}

.sar-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 400px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "map feeds"
    "map sheet"
    "time sheet";
  gap: 0.55rem;
}

.map-panel {
  grid-area: map;
  position: relative;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.map-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #021428;
}

.leaflet-host {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #0b3a52;
}

.map-stage.tiles #map {
  background: transparent;
  pointer-events: none;
}

.map-stage.canvas .leaflet-host {
  display: none;
}

.map-overlay {
  z-index: 2;
}

.leaflet-control-zoom {
  margin-top: 42px !important;
  margin-right: 8px !important;
}

.leaflet-container img.leaflet-tile {
  mix-blend-mode: normal;
}

.leaflet-bar a {
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  min-height: 0 !important;
  color: #102033;
  background: #f4f7fb;
  text-decoration: none;
}

.map-stage > .leaflet-bottom.leaflet-right {
  left: 8px;
  right: 0;
  z-index: 5;
  width: auto;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
}

.leaflet-control-attribution {
  pointer-events: auto;
  box-sizing: border-box;
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  line-height: 1.25;
  padding: 2px 4px;
  background: rgba(2, 8, 24, 0.82);
  color: #d5def8;
  white-space: normal;
}

.leaflet-control-attribution a {
  color: #9ecbff;
}

.leaflet-control-attribution .attrib-toggle {
  flex: 0 0 auto;
  min-height: 0;
  height: 28px;
  margin: 0;
  padding: 0 0.45rem;
  border-radius: 6px;
  font: 11px/1 "IBM Plex Mono", ui-monospace, monospace;
  white-space: nowrap;
}

.leaflet-control-attribution.is-collapsed {
  width: auto;
  padding: 0;
  background: transparent;
}

.leaflet-control-attribution.is-collapsed .attrib-full {
  display: none;
}

.leaflet-control-attribution.is-open .attrib-full {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
}

html[data-theme="night"] .leaflet-tile-pane {
  filter: brightness(0.55) saturate(0.75) hue-rotate(330deg);
}

html[data-theme="contrast"] .leaflet-tile-pane {
  filter: grayscale(1) contrast(1.35);
}

.map-stage.placing .leaflet-host,
.map-stage.placing #map {
  cursor: crosshair;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  display: block;
  touch-action: none;
  background: #021428;
  cursor: grab;
}

#map:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: -3px;
}

.map-overlay {
  position: absolute;
  left: 0.4rem;
  right: 0.4rem;
  top: 0.35rem;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.25rem;
  pointer-events: none;
  max-height: 1.7rem;
  overflow: hidden;
}

.map-overlay .pill {
  pointer-events: none;
  background: rgba(2, 8, 24, 0.78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  max-width: 42%;
  font-size: 0.68rem;
  line-height: 1.2;
  padding: 0.12rem 0.4rem;
}

.nav-readout {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.4rem;
  padding: 0.12rem 0.55rem 0.16rem;
  border-top: 1px solid var(--line);
  background: rgba(2, 8, 24, 0.94);
  min-width: 0;
}

.nav-line {
  flex: 1 1 8rem;
  margin: 0;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-tools {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
}

.nav-speed {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin: 0;
  font-family: var(--mono);
  font-size: 0.68rem;
}

.nav-speed input {
  width: 3.4rem;
  min-height: 0;
  height: 26px;
  padding: 0 0.3rem;
  border-radius: 6px;
}

.nav-readout button {
  min-height: 0;
  height: 26px;
  padding: 0 0.45rem;
  border-radius: 6px;
  font-size: 0.68rem;
}

.legend-box {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: rgba(2, 8, 24, 0.94);
}

.legend-box summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 0.7rem;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--neon);
}

.legend-box summary::marker {
  color: var(--neon);
}

.legend {
  position: static;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.7rem;
  padding: 0 0.7rem 0.55rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-family: var(--mono);
  font-size: 0.72rem;
  max-width: none;
}

.swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.25rem;
  vertical-align: -1px;
  border: 1px solid #fff;
}

.swatch.right { background: #5ec962; border-color: #5ec962; border-radius: 50%; }
.swatch.left { background: transparent; border-color: #3b528b; }
.swatch.strand { background: #fde725; border-color: #fde725; }
.swatch.lkp {
  width: 0.5rem;
  height: 0.5rem;
  background: transparent;
  border-color: #fff;
  transform: rotate(45deg);
}
.swatch.track {
  width: 0.95rem;
  height: 0;
  border: 0;
  border-top: 2px solid #fff;
  background: transparent;
  vertical-align: 3px;
}
.swatch.hull { background: rgba(126, 200, 227, 0.7); }

.caption-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  padding: 0.15rem 0.55rem 0.05rem 0.7rem;
}

.map-caption {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-dot {
  flex: 0 0 auto;
  width: 1.35rem;
  height: 1.35rem;
  min-width: 1.35rem;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-style: italic;
  font-weight: 650;
  line-height: 1;
}

.count-field .field-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.info-note {
  margin: 0.15rem 0 0;
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1.35;
  letter-spacing: 0;
  text-transform: none;
  white-space: normal;
  overflow-wrap: anywhere;
}

.legend-note {
  flex: 1 0 100%;
  margin: 0.1rem 0 0;
  font-size: 0.68rem;
  line-height: 1.3;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  overflow-wrap: anywhere;
}

.live-status {
  grid-area: feeds;
  align-self: start;
  min-width: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0.35rem 0.7rem 0.45rem;
}

.feed-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.28rem;
  margin-bottom: 0.15rem;
}

.live-status h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--neon);
}

.feed-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.feed-toggle-opt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  margin: 0;
  min-height: 32px;
  padding: 0.2rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.feed-toggle-opt input {
  width: 0.95rem;
  height: 0.95rem;
  min-height: 0;
  margin: 0;
  accent-color: var(--neon);
}

.feed-toggle-opt:has(input:checked) {
  background: #5ec962;
  color: #062033;
}

.obs-pack { display: contents; }

.feed-note {
  grid-column: 1 / -1;
  margin: 0.12rem 0 0;
  color: var(--muted);
  font-size: 0.6rem;
  line-height: 1.3;
}

.feed-rows {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 0.8rem;
}

.feed-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name badge" "meta meta";
  gap: 0 0.35rem;
  align-items: center;
  min-width: 0;
  padding: 0.12rem 0;
  border-top: 1px solid rgba(158, 203, 255, 0.14);
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.25;
}

.feed-row[data-feed="chart"] { grid-column: 1 / -1; }

.feed-name {
  grid-area: name;
  font-weight: 600;
  min-width: 0;
}

.feed-meta {
  grid-area: meta;
  min-width: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.feed-meta a { color: var(--link); }

.feed-badge {
  grid-area: badge;
  justify-self: end;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  padding: 0.05rem 0.32rem;
  border-radius: 999px;
  white-space: nowrap;
}

.feed-row[data-kind="obs"] {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "name meta badge";
  padding: 0.02rem 0;
}

.feed-row[data-kind="obs"] .feed-meta {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feed-row[data-feed="sst"] .feed-meta {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

.feed-badge[data-state="live"] { color: #062033; background: #5ec962; }
.feed-badge[data-state="sim"] { color: #e8edff; background: #5c6578; }
.feed-badge[data-state="error"] { color: #2a0a10; background: #ff8a7a; }

.time-bar {
  grid-area: time;
  display: grid;
  gap: 0.35rem;
}

.time-row,
.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.time-row label,
.tool-row label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 5.5rem;
  flex: 1;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--neon);
  min-height: 44px;
}

input[type="range"]::-webkit-slider-thumb {
  width: 44px;
  height: 44px;
}

.sheet {
  grid-area: sheet;
  min-height: 0;
  overflow: auto;
  padding: 0.55rem 0.7rem 0.8rem;
}

.tabs {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  padding-bottom: 0.35rem;
}

.tabs button {
  white-space: nowrap;
  padding: 0.35rem 0.6rem;
}

.tabs button[aria-selected="true"] {
  background: var(--brand);
  color: #fff;
  border-color: transparent;
}

.panel-block { display: grid; gap: 0.45rem; }
.panel-block[hidden] { display: none; }

.field {
  display: grid;
  gap: 0.15rem;
}

.banner {
  border: 1px solid var(--warn);
  color: var(--text);
  background: rgba(255, 210, 122, 0.08);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
}

.banner[data-kind="bad"] { border-color: var(--danger); }
.banner[data-kind="ok"] { border-color: var(--ok); }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
}

#feedback {
  min-height: 0;
}

#alt-table {
  margin-top: 0.4rem;
}

html[data-theme="night"] {
  --bg: #140206;
  --bg-elev: #1c060a;
  --panel: #24080d;
  --panel-2: #2c0c12;
  --text: #ffe8ea;
  --muted: #ffd0d4;
  --line: rgba(255, 120, 120, 0.45);
  --line-strong: rgba(255, 160, 150, 0.8);
  --brand: #8d1d32;
  --neon: #ff8a7a;
  --link: #ffd0c8;
}

html[data-theme="night"] body {
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(120, 0, 20, 0.45), transparent 55%),
    var(--bg);
}

html[data-theme="contrast"] {
  --bg: #000;
  --panel: #000;
  --panel-2: #000;
  --text: #fff;
  --muted: #fff;
  --line: #fff;
  --line-strong: #fff;
  --brand: #000;
  --neon: #ff0;
  --link: #ff0;
  --ok: #ff0;
  --warn: #ff0;
  --danger: #fff;
}

html[data-theme="contrast"] body {
  background: #000;
}

html[data-theme="contrast"] button.primary {
  background: #fff;
  color: #000;
}

@media (max-width: 800px), (max-height: 500px) {
  .sar-app {
    height: auto;
    min-height: 100svh;
    overflow: visible;
  }

  .sar-app .wrap {
    width: min(1440px, calc(100% - 0.6rem));
    flex: none;
    overflow: visible;
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
  }

  .sar-app .top {
    align-items: center;
    gap: 0.35rem 0.6rem;
    margin-bottom: 0.2rem;
  }

  .sar-app .sub {
    display: none;
  }

  .sar-app h1 {
    font-size: 1.15rem;
  }

  .sar-app .lang {
    min-width: 0;
    width: auto;
    flex: 0 0 8.5rem;
  }

  .sar-app .disclaimer,
  .sar-app .foot {
    font-size: 0.68rem;
    line-height: 1.25;
    padding: 0.28rem 0.45rem;
    margin-bottom: 0.28rem;
  }

  .sar-app .foot {
    margin-top: 0.35rem;
    padding: 0;
  }

  .sar-layout {
    display: flex;
    flex-direction: column;
    flex: none;
    min-height: 0;
    overflow: visible;
  }

  .map-panel {
    flex: none;
    overflow: visible;
    min-height: 0;
  }

  .map-stage {
    flex: none;
    height: 60vh;
    min-height: 60vh;
  }

  .leaflet-control-zoom {
    margin-top: 34px !important;
    margin-right: 6px !important;
  }

  .leaflet-bar a {
    width: 44px !important;
    height: 44px !important;
    line-height: 44px !important;
  }

  .leaflet-control-attribution.is-open .attrib-full {
    flex: 1 0 100%;
    font-size: 10px;
  }

  .sheet {
    border-radius: 16px 16px 0 0;
    overflow: visible;
    min-height: 12rem;
    padding-top: 0.55rem;
  }

  .live-status {
    position: static;
    z-index: auto;
    border-bottom: 0;
    border-top: 1px solid var(--line);
    padding: 0.28rem 0.55rem 0.35rem;
  }

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

  .feed-rows { display: block; }
  .obs-pack {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 0.4rem;
  }
  .obs-pack .feed-row[data-feed="sst"] { grid-column: 1 / -1; }
  .feed-note {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .map-caption { font-size: 0.68rem; }
  .legend-note { font-size: 0.64rem; line-height: 1.28; }

  .nav-readout { flex-wrap: wrap; padding: 0.08rem 0.45rem 0.1rem; }
  .nav-line { flex: 1 1 100%; font-size: 0.64rem; }
  .nav-tools { width: 100%; }
}

@media (min-width: 801px) and (min-height: 501px) {
  .legend-box summary { min-height: 28px; }
  .legend { padding-bottom: 0.2rem; }
  .legend-note { margin-top: 0; font-size: 0.64rem; line-height: 1.2; }
  .caption-row { padding-top: 0.05rem; padding-bottom: 0; }
  .live-status { padding: 0.28rem 0.7rem 0.3rem; }
  .live-status h2 { margin: 0; font-size: 0.62rem; }
  .feed-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "name meta badge";
    padding: 0.04rem 0;
  }
  .feed-meta {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .feed-row[data-feed="sst"] .feed-meta {
    white-space: normal;
    overflow: visible;
  }
}

@media (max-height: 860px) and (min-width: 801px) {
  .sar-app .wrap { padding-top: 0.2rem; }
  .sar-app .top { margin-bottom: 0.15rem; align-items: center; }
  .sar-app .kicker,
  .sar-app .sub { display: none; }
  .sar-app h1 { font-size: 1.25rem; }
  .sar-app .lang span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .sar-app .disclaimer,
  .sar-app .foot {
    font-size: 0.72rem;
    line-height: 1.25;
    padding: 0.28rem 0.5rem;
    margin-bottom: 0.25rem;
  }
  .sar-app .foot { margin-top: 0.2rem; padding: 0; }
  .sar-app .time-bar { padding: 0.35rem 0.55rem; gap: 0.2rem; }
  .map-stage { min-height: 280px; }
}

@media (max-height: 680px) and (min-width: 801px) {
  .sar-app .time-bar button,
  .sar-app .time-bar select,
  .sar-app .time-bar input:not([type="range"]) {
    min-height: 0;
    height: 32px;
    padding: 0 0.45rem;
  }
  .sar-app .tool-row,
  .sar-app .time-row { flex-wrap: nowrap; }
  .sar-app .time-bar .hint {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .map-stage { min-height: 220px; }
  .legend-box { max-height: 4.2rem; overflow: auto; }
  .live-status { max-height: 168px; overflow: auto; }
  .feed-head { position: sticky; top: 0; z-index: 1; background: var(--panel); }
}

@media print {
  body { background: #fff; color: #000; }
  .sar-app { height: auto; overflow: visible; }
  .map-panel, .time-bar, .tabs, .no-print { display: none !important; }
  .sar-layout { display: block; }
  .sheet { overflow: visible; border: 0; }
  #print-sheet { display: block !important; }
}

#print-sheet { display: none; }

.mono { font-family: var(--mono); }
