/* The web map page (worker/map/page.ts). Light and dark follow the site's
   stored theme (data-theme, public/map/theme.js), else the system. The power
   colours are the app's (src/constants/colors.ts power.*), as in map.js. */

:root {
  --mp-ink: #0f172a;
  --mp-muted: #5b6475;
  --mp-bg: #ffffff;
  --mp-soft: #f1f4f9;
  --mp-line: #e3e7ef;
  --mp-card: rgba(255, 255, 255, 0.96);
  --mp-brand: #1147fc;
  --mp-on-brand: #ffffff;
  --mp-chip-on: #eaf0ff;
  --mp-shadow: 0 2px 10px rgba(15, 23, 42, 0.14);
  --mp-available-bg: #dcfce7;
  --mp-available-ink: #166534;
  --mp-busy-bg: #fee2e2;
  --mp-busy-ink: #991b1b;
  --mp-closed-bg: #fef3c7;
  --mp-closed-ink: #92400e;
  --mp-ac: #ef4444;
  --mp-dc: #facc15;
  --mp-hpc: #16a34a;
  --mp-unknown: #9ca3af;
  color-scheme: light;
}

html[data-theme='dark'] {
  --mp-ink: #e8eefb;
  --mp-muted: #9fb0c8;
  --mp-bg: #0e1a2e;
  --mp-soft: #16243c;
  --mp-line: #26354f;
  --mp-card: rgba(14, 26, 46, 0.94);
  --mp-brand: #5b8cff;
  --mp-on-brand: #06122b;
  --mp-chip-on: #16264a;
  --mp-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  --mp-available-bg: #14532d;
  --mp-available-ink: #bbf7d0;
  --mp-busy-bg: #7f1d1d;
  --mp-busy-ink: #fecaca;
  --mp-closed-bg: #78350f;
  --mp-closed-ink: #fde68a;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme='light']) {
    --mp-ink: #e8eefb;
    --mp-muted: #9fb0c8;
    --mp-bg: #0e1a2e;
    --mp-soft: #16243c;
    --mp-line: #26354f;
    --mp-card: rgba(14, 26, 46, 0.94);
    --mp-brand: #5b8cff;
    --mp-on-brand: #06122b;
    --mp-chip-on: #16264a;
    --mp-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
    --mp-available-bg: #14532d;
    --mp-available-ink: #bbf7d0;
    --mp-busy-bg: #7f1d1d;
    --mp-busy-ink: #fecaca;
    --mp-closed-bg: #78350f;
    --mp-closed-ink: #fde68a;
    color-scheme: dark;
  }
}

[hidden] {
  display: none !important;
}

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

body.mp {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
  color: var(--mp-ink);
  background: var(--mp-bg);
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--mp-brand);
}

:focus-visible {
  outline: 3px solid var(--mp-brand);
  outline-offset: 2px;
}

/* ── header ─────────────────────────────────────────────────────────────── */
.mp-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 6px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--mp-line);
  background: var(--mp-bg);
  box-sizing: border-box;
}

.mp-home {
  display: flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  flex: 0 0 auto;
}

.mp-home img {
  display: block;
  width: 28px;
  height: 34px;
  object-fit: contain;
}

.mp-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mp-langs {
  position: relative;
  flex: 0 0 auto;
}

.mp-langs summary {
  list-style: none;
  cursor: pointer;
  padding: 7px 10px;
  border: 1px solid var(--mp-line);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  user-select: none;
}

.mp-langs summary::-webkit-details-marker {
  display: none;
}

.mp-langs ul {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  z-index: 10;
  min-width: 170px;
  max-height: 60vh;
  overflow: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--mp-bg);
  border: 1px solid var(--mp-line);
  border-radius: 12px;
  box-shadow: var(--mp-shadow);
}

.mp-langs li a,
.mp-langs li span {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  font-size: 14px;
}

.mp-langs li a:hover {
  background: var(--mp-soft);
}

.mp-langs li [aria-current] {
  font-weight: 700;
}

.mp-cta {
  flex: 0 0 auto;
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--mp-brand);
  color: var(--mp-on-brand);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

@media (max-width: 560px) {
  .mp-name {
    display: none;
  }
  .mp-title {
    font-size: 15px;
  }
  .mp-cta {
    padding: 8px 10px;
    font-size: 13px;
  }
}

/* ── map and its overlays ───────────────────────────────────────────────── */
.mp-main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.mp-map {
  position: absolute;
  inset: 0;
}

.mp-chips {
  position: absolute;
  top: 10px;
  inset-inline-start: 10px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: calc(100% - 72px);
}

.mp-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mp-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--mp-line);
  border-radius: 19px;
  background: var(--mp-card);
  color: inherit;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--mp-shadow);
  cursor: pointer;
}

.mp-chip[aria-pressed='true'] {
  border-color: var(--mp-brand);
  background: var(--mp-chip-on);
  box-shadow: inset 0 0 0 1px var(--mp-brand), var(--mp-shadow);
}

.mp-key {
  cursor: default;
  font-weight: 500;
}

.mp-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.18);
  flex: 0 0 auto;
}

.mp-ac {
  background: var(--mp-ac);
}

.mp-dc {
  background: var(--mp-dc);
}

.mp-hpc {
  background: var(--mp-hpc);
}

.mp-unknown {
  background: var(--mp-unknown);
}

.mp-hint {
  margin: 0;
  max-width: 100%;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--mp-card);
  box-shadow: var(--mp-shadow);
  color: var(--mp-muted);
  font-size: 12px;
  box-sizing: border-box;
}

.mp-status {
  position: absolute;
  bottom: 36px;
  left: 50%;
  z-index: 4;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--mp-ink);
  color: var(--mp-bg);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  box-sizing: border-box;
}

.mp-status.mp-on {
  opacity: 1;
}

/* ── station panel ──────────────────────────────────────────────────────── */
.mp-panel {
  position: absolute;
  top: 96px;
  inset-inline-start: 10px;
  z-index: 3;
  width: 340px;
  max-height: calc(100% - 140px);
  overflow: auto;
  padding: 16px 16px 18px;
  border-radius: 16px;
  background: var(--mp-bg);
  box-shadow: var(--mp-shadow);
  box-sizing: border-box;
}

@media (max-width: 640px) {
  .mp-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 58%;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
  }
}

.mp-close {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.mp-close:hover {
  background: var(--mp-soft);
}

.mp-panel h2 {
  margin: 2px 0 4px;
  margin-inline-end: 40px;
  font-size: 18px;
  line-height: 1.3;
}

.mp-panel h2:focus {
  outline: none;
}

.mp-operator {
  margin: 0 0 6px;
  color: var(--mp-muted);
  font-size: 14px;
}

.mp-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 8px;
}

.mp-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
}

.mp-pill.mp-available {
  background: var(--mp-available-bg);
  color: var(--mp-available-ink);
}

.mp-pill.mp-busy {
  background: var(--mp-busy-bg);
  color: var(--mp-busy-ink);
}

.mp-pill.mp-closed {
  background: var(--mp-closed-bg);
  color: var(--mp-closed-ink);
}

.mp-pill.mp-muted {
  background: var(--mp-soft);
  color: var(--mp-muted);
  font-weight: 600;
}

.mp-class {
  margin: 8px 0 2px;
  font-size: 15px;
  font-weight: 700;
}

p.mp-muted {
  margin: 6px 0;
  color: var(--mp-muted);
  font-size: 14px;
}

.mp-rating {
  margin: 8px 0;
  font-size: 14px;
}

.mp-note {
  margin: 8px 0;
  color: var(--mp-muted);
  font-size: 13px;
  line-height: 1.45;
}

.mp-credit {
  margin: 12px 0 4px;
  font-size: 12px;
  line-height: 1.4;
}

.mp-credit a {
  color: var(--mp-muted);
}

/* The base map's credit in the panel: only where the panel, a bottom sheet,
   covers the map's own attribution. */
.mp-basemap-credit {
  display: none;
  color: var(--mp-muted);
}

@media (max-width: 640px) {
  .mp-basemap-credit {
    display: block;
  }
}

.mp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.mp-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--mp-brand);
  color: var(--mp-on-brand);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.mp-secondary {
  background: transparent;
  color: var(--mp-brand);
  box-shadow: inset 0 0 0 1.5px var(--mp-brand);
}

/* ── no map, and the data sources dialog ────────────────────────────────── */
.mp-fallback {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--mp-bg);
  font-size: 16px;
  line-height: 1.5;
}

.mp-sources {
  /* border-box: the 16 px side margins hold on a phone, padding included. */
  box-sizing: border-box;
  max-width: min(520px, calc(100% - 32px));
  max-height: calc(100% - 48px);
  padding: 20px 22px;
  border: 0;
  border-radius: 16px;
  background: var(--mp-bg);
  color: var(--mp-ink);
  box-shadow: var(--mp-shadow);
  font-size: 14px;
  line-height: 1.5;
}

.mp-sources::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.mp-sources h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.mp-sources h3 {
  margin: 16px 0 4px;
  font-size: 15px;
}

.mp-credits {
  margin: 8px 0;
  padding-inline-start: 18px;
}

.mp-credits li {
  margin: 6px 0;
  font-size: 13px;
}

.mp-privacy {
  margin-top: 16px;
  color: var(--mp-muted);
  font-size: 13px;
}

.mp-sources form {
  margin-top: 16px;
}
