:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14181e;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f2f4f6;
  --muted: #9aa3ad;
  --accent: #7ec8ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

.public-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: 56px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.public-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #10141a;
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: #222;
  border: 1px solid #3a3a3a;
  font-weight: 900;
  overflow: hidden;
  background: #0b141a;
}

.brand-mark img { width: 100%; height: 100%; object-fit: cover; }

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.public-header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.field-inline select {
  max-width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.75rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.ops-link {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.04);
}

.ops-link:hover {
  border-color: rgba(255, 255, 255, 0.25);
}

.alert-rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  z-index: 1;
}

.public-key { display: grid; gap: 7px; margin-top: 12px; color: #b8c7d1; font-size: .69rem; }
.public-key span { display: flex; align-items: center; gap: 7px; }
.public-key i { width: 13px; height: 10px; border-radius: 2px; display: inline-block; }
.key-watch { background: #f3c34f; opacity: .72; border: 1px solid #ffe19a; }.key-warning { background: transparent; border: 2px solid #ff7767; }

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
}

.rail-head h2 {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.count-pill {
  border-radius: 999px;
  padding: 2px 8px;
  background: rgba(126, 200, 255, 0.14);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
}

.alert-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 8px 12px;
}

.alert-list .empty {
  margin: 12px 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.alert-card {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  font: inherit;
}

.alert-card:hover,
.alert-card.is-selected {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}

.alert-card .product {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.alert-card .meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.rail-foot {
  border-top: 1px solid var(--line);
  padding: 10px 12px 12px;
}

.hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
}

.placefile-hint code {
  display: block;
  margin: 4px 0;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: #d7e6f5;
  font-size: 0.68rem;
  word-break: break-all;
}

.copy-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.72rem;
  cursor: pointer;
}

.copy-btn:hover {
  border-color: rgba(255, 255, 255, 0.28);
}

.public-map {
  min-width: 0;
  min-height: 0;
}

/* National outlook-style public map: map first, current product key second. */
@media (min-width: 761px) {
  .public-shell { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: 72px minmax(0, 1fr); }
  .public-header { min-height: 72px; padding: 0 20px; background: linear-gradient(180deg, #101a21 0%, #091015 100%); }
  .public-header h1 { font-size: 1.22rem; letter-spacing: -.02em; }
  .brand-mark { width: 46px; height: 46px; border-radius: 10px; }
  .alert-rail { grid-column: 2; grid-row: 2; border-right: 0; border-left: 1px solid var(--line); background: linear-gradient(180deg, #121b22, #0d141a); }
  .public-map { grid-column: 1; grid-row: 2; }
  .rail-head { padding: 17px 16px 10px; border-bottom: 1px solid rgba(255,255,255,.06); }
  .rail-head h2 { color: #d7e4eb; font-size: .72rem; }
  .alert-list { padding: 10px 12px; }
  .alert-card { padding: 12px; border-radius: 8px; background: rgba(255,255,255,.045); }
  .alert-card:hover,.alert-card.is-selected { border-color: rgba(126,200,255,.55); background: rgba(126,200,255,.09); }
  .rail-foot { padding: 13px 16px 16px; background: rgba(0,0,0,.12); }
  .radar-chrome { display: none; }
}

.radar-chrome {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(520px, calc(100vw - 320px));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 12px;
  background: rgba(12, 14, 18, 0.92);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  color: var(--muted);
  font-size: 0.72rem;
}

.radar-play {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  font-size: 0.75rem;
}

.radar-play:hover:not(:disabled) {
  border-color: rgba(126, 200, 255, 0.45);
  background: rgba(126, 200, 255, 0.12);
}

.radar-play:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.radar-chrome-main {
  flex: 1;
  min-width: 0;
}

.radar-time {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.opacity-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.68rem;
}

.opacity-row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}

.radar-legend-inline {
  width: 110px;
  flex-shrink: 0;
}

.radar-bar {
  height: 8px;
  margin: 0 0 4px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    #00ecec,
    #01a0f6,
    #00e833,
    #fff000,
    #ff9000,
    #ff0000,
    #ff00f0
  );
}

.radar-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.62rem;
}

.product-dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  max-width: min(720px, 94vw);
  width: 720px;
  background: #12161c;
  color: var(--text);
}

.product-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.product-dialog-inner {
  margin: 0;
}

.product-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.product-dialog h3 {
  margin: 0;
  font-size: 0.95rem;
}

.dialog-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.product-text {
  margin: 0;
  max-height: min(60vh, 520px);
  overflow: auto;
  padding: 12px 14px 16px;
  white-space: pre;
  tab-size: 8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  color: #e4e9ee;
}

.maplibregl-popup-content {
  background: #151a21;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  max-width: 260px;
}

.maplibregl-popup-tip {
  border-top-color: #151a21 !important;
}

.maplibregl-popup-close-button {
  color: var(--muted);
}

@media (max-width: 760px) {
  body {
    overscroll-behavior: none;
  }

  .public-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 128px minmax(0, 1fr);
    min-height: 0;
    padding-top: env(safe-area-inset-top);
  }

  .public-header {
    min-height: 58px;
    padding: 7px 10px;
    gap: 8px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .eyebrow {
    font-size: 0.55rem;
  }

  .public-header h1 {
    font-size: 0.92rem;
  }

  .header-meta {
    gap: 6px;
    flex-wrap: nowrap;
  }

  .header-meta .status {
    display: none;
  }

  .field-inline select {
    width: min(38vw, 165px);
    min-height: 38px;
    padding: 6px;
  }

  .toggle,
  .ops-link {
    min-height: 38px;
  }

  .alert-rail {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .rail-head {
    flex: 0 0 auto;
    padding: 7px 10px 2px;
  }

  .alert-list {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 10px 8px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .alert-card {
    flex: 0 0 min(72vw, 270px);
    min-height: 74px;
    margin: 0;
    padding: 9px 10px;
    scroll-snap-align: start;
  }

  .rail-foot {
    display: none;
  }

  .public-map {
    touch-action: pan-x pan-y;
  }

  .radar-chrome {
    left: 10px;
    right: 10px;
    width: auto;
    transform: none;
    bottom: calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
    padding: 7px 9px;
  }

  .radar-play {
    width: 42px;
    height: 42px;
  }

  .radar-legend-inline {
    display: none;
  }

  .opacity-row span {
    display: none;
  }

  .opacity-row input[type="range"] {
    height: 24px;
  }

  .maplibregl-ctrl-top-right {
    top: 4px;
    right: 4px;
  }

  .maplibregl-ctrl-group button {
    width: 38px;
    height: 38px;
  }

  .maplibregl-popup {
    max-width: calc(100vw - 24px) !important;
  }

  .maplibregl-popup-content {
    max-width: calc(100vw - 24px);
    min-width: min(280px, calc(100vw - 24px));
    padding: 12px 14px;
    font-size: 0.88rem;
  }

  .maplibregl-popup-content button {
    min-width: 44px;
    min-height: 40px;
  }

  .maplibregl-popup-close-button {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }

  .product-dialog {
    width: calc(100vw - 16px);
    max-width: none;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    margin: auto;
  }

  .dialog-close {
    width: 44px;
    height: 44px;
  }

  .product-text {
    max-height: calc(100dvh - 96px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 0.7rem;
  }
}

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

  .brand {
    flex: 1 1 auto;
  }

  .header-meta {
    flex: 1 0 100%;
    justify-content: stretch;
  }

  .field-inline {
    flex: 1;
  }

  .field-inline select {
    width: 100%;
    max-width: none;
  }

  .toggle,
  .ops-link {
    justify-content: center;
  }
}

@media (max-width: 760px) and (orientation: landscape) {
  .public-shell {
    grid-template-columns: 210px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .public-header {
    grid-column: 1 / -1;
  }

  .alert-rail {
    border-right: 1px solid var(--line);
    border-bottom: none;
  }

  .alert-list {
    display: block;
    overflow: auto;
    padding: 4px 7px 10px;
  }

  .alert-card {
    width: 100%;
    min-height: 0;
    margin-bottom: 6px;
  }

  .radar-chrome {
    left: 220px;
  }
}
