@font-face {
  font-family: 'Wanted Sans';
  src: url('/fonts/WantedSansVariable.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-warm: #f2f1ec;
  --bg-panel: #ffffff;
  --text-main: #101010;
  --text-muted: #6b6b6b;
  --border-rule: #101010;
  --border-light: #d1d0cb;
  --route-accent: #0877ff;
  --signal-live: #101010;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  font-family: 'Wanted Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-warm);
  color: var(--text-main);
}

button, input, select {
  font: inherit;
}

.dashboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  min-width: 0;
}

body.is-admin .dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
  grid-template-rows: minmax(0, 1fr) 118px;
}

body.is-admin .map-container {
  grid-column: 1;
  grid-row: 1;
  border-right: 2px solid var(--border-rule);
  border-bottom: 1px solid var(--border-rule);
}

body.is-admin .hud {
  grid-column: 1;
  grid-row: 2;
  height: auto;
  min-height: 118px;
}

body.is-admin .map-status-card {
  top: 16px;
  left: 16px;
  width: min(300px, calc(100% - 32px));
  gap: 6px;
  padding: 12px 14px;
  box-shadow: 0 8px 16px rgba(16, 16, 16, 0.1);
}

body.is-admin .map-status-card strong {
  font-size: 22px;
}

body.is-admin .map-status-card small {
  font-size: 12px;
}

body.is-admin .reading {
  padding: 12px 16px;
}

body.is-admin .reading strong {
  font-size: 24px;
}

body.is-viewer .map-status-card {
  display: none;
}

body.is-viewer .locate-control {
  display: grid;
}

body.is-viewer .signal-dot {
  display: none;
}

body.is-viewer #status {
  color: var(--text-main);
}

.map-container {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  border-bottom: 2px solid var(--border-rule);
  background: #eaebe6;
}

#map {
  width: 100%;
  height: 100%;
  background: #eaebe6;
}

.map-container::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  content: "";
  pointer-events: none;
  background: linear-gradient(180deg, rgba(250, 251, 246, 0.03), rgba(74, 79, 82, 0.018));
}

.map-status-card {
  position: absolute;
  top: 24px;
  left: 24px;
  z-index: 4;
  width: min(520px, calc(100% - 48px));
  display: grid;
  gap: 8px;
  padding: 18px 22px;
  border-radius: 8px;
  border: 1px solid var(--border-rule);
  background: rgba(242, 241, 236, 0.94);
  color: var(--text-main);
  box-shadow: 0 10px 22px rgba(16, 16, 16, 0.14);
  backdrop-filter: blur(8px);
}

.map-status-card span,
.map-status-card small {
  font-weight: 800;
  letter-spacing: 0;
  opacity: 0.86;
}

.map-status-card span {
  font-size: 12px;
  text-transform: uppercase;
}

.map-status-card strong {
  font-size: 36px;
  font-weight: 900;
  line-height: 1;
}

.map-status-card small {
  font-size: 14px;
}

.locate-control {
  position: absolute;
  right: 10px;
  bottom: 152px;
  z-index: 5;
  width: 44px;
  height: 44px;
  display: none;
  place-items: center;
  border: 1px solid rgba(16, 16, 16, 0.72);
  border-radius: 13px;
  background: #df8846;
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(16, 16, 16, 0.16);
  cursor: pointer;
  transition:
    background 140ms ease,
    color 140ms ease,
    opacity 140ms ease,
    transform 140ms ease;
}

.locate-control:hover {
  background: #ea9450;
  transform: translateY(-1px);
}

.locate-control:active {
  transform: translateY(0) scale(0.97);
}

.locate-control:disabled {
  cursor: default;
  opacity: 0.46;
  color: #ffffff;
  transform: none;
}

.locate-control-icon {
  position: relative;
  width: 28px;
  height: 28px;
  display: block;
  background:
    linear-gradient(currentColor, currentColor) center / 3px 100% no-repeat,
    linear-gradient(90deg, currentColor, currentColor) center / 100% 3px no-repeat;
}

.locate-control-icon::before {
  position: absolute;
  inset: 6px;
  content: "";
  border: 3px solid currentColor;
  border-radius: 50%;
}

.locate-control-icon::after {
  position: absolute;
  inset: 11px;
  content: "";
  border-radius: 50%;
  background: currentColor;
}

/* Horizontal HUD */
.hud {
  display: flex;
  flex-direction: row;
  height: 140px; /* Shallow horizontal */
  background: var(--bg-warm);
}

/* Vertical brand rail */
.brand-rail {
  display: flex;
  flex-direction: column;
  flex: 0 0 220px;
  justify-content: space-between;
  width: 220px;
  padding: 16px 24px;
  border-right: 1px solid var(--border-rule);
  background: var(--bg-panel);
}

.brand-rail h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  line-height: 1;
}

.mode-label {
  margin: 8px 0 0;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.brand-rail .status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.signal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.signal-dot.live {
  background: var(--signal-live);
}

#status {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#status.warning {
  color: var(--text-main);
}

.readings {
  display: flex;
  flex: 1;
  min-width: 0;
  border-right: 1px solid var(--border-rule);
}

.reading {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 24px;
  border-right: 1px solid var(--border-light);
}
.reading:last-child {
  border-right: none;
}

.reading span {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.reading-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.location-state-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #9a9a9a;
}

.location-state-dot.is-on {
  background: #20a464;
}

.reading strong {
  font-size: 32px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.1;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-panel {
  grid-column: 2;
  grid-row: 1 / 3;
  width: auto;
  min-width: 0;
  padding: 18px 20px;
  border-left: 2px solid var(--border-rule);
  overflow-y: auto;
  background: var(--bg-panel);
}

.admin-panel[hidden] {
  display: none;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border-rule);
}

.admin-header span,
.admin-section {
  display: grid;
}

.admin-header span,
.admin-section > span,
.pin-card span {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.admin-header h2 {
  margin: 4px 0 0;
  font-size: 28px;
  line-height: 0.95;
  letter-spacing: 0;
  text-transform: uppercase;
}

.admin-header button {
  min-width: 78px;
  height: 38px;
  border: 1px solid var(--border-rule);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding-top: 16px;
}

.admin-section {
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 8px;
  align-content: start;
  padding: 12px;
  border: 1px solid var(--border-rule);
  border-radius: 8px;
  background: #fbfaf6;
}

.admin-section-wide {
  grid-column: auto;
  grid-template-columns: minmax(0, 1fr) 78px;
}

.admin-section > span,
.admin-section-note {
  grid-column: 1 / -1;
}

.admin-section-note {
  margin: -2px 0 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.admin-section input,
.admin-section select,
.admin-section button {
  min-width: 0;
  height: 38px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: transparent;
  padding: 0 10px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  outline: none;
}

.admin-section .token-input {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.admin-section button {
  cursor: pointer;
  border-color: var(--border-rule);
  font-weight: 800;
  text-transform: uppercase;
}

.admin-section button:hover {
  background: var(--bg-warm);
}

.admin-section button:disabled {
  cursor: default;
  opacity: 0.45;
  background: transparent;
}

.checkbox-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.admin-feedback {
  min-height: 18px;
  margin: 16px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.pin-lock {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(242, 241, 236, 0.9);
  backdrop-filter: blur(6px);
}

.pin-lock[hidden] {
  display: none;
}

.pin-card {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 28px;
  border: 2px solid var(--border-rule);
  border-radius: 8px;
  background: var(--bg-panel);
  box-shadow: 0 18px 40px rgba(16, 16, 16, 0.16);
}

.pin-card.pin-error {
  animation: pinShake 180ms ease-in-out 2;
}

.pin-card h2 {
  margin: 0;
  font-size: 42px;
  line-height: 1;
  text-transform: uppercase;
}

.pin-note {
  margin: -2px 0 2px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.pin-card input,
.pin-card button {
  width: 100%;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--border-rule);
  border-radius: 6px;
  background: transparent;
  padding: 0 12px;
  font-size: 16px;
  font-weight: 800;
}

.pin-card input {
  text-align: center;
  font-size: 22px;
  letter-spacing: 0.08em;
}

.pin-card button {
  cursor: pointer;
  text-transform: uppercase;
}

.pin-feedback {
  margin-top: 0;
}

.pin-feedback.is-error {
  color: #b42318;
}

.pin-feedback.is-success {
  color: #137a44;
}

@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.currentMarker {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--route-accent);
  border: 5px solid #ffffff;
  box-shadow: 0 8px 18px rgba(16, 16, 16, 0.26);
}

.currentMarker::before {
  position: absolute;
  inset: 8px;
  content: "";
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.26);
}

.currentMarker::after {
  position: absolute;
  inset: -12px;
  content: "";
  border: 2px solid var(--route-accent);
  border-radius: 50%;
  animation: markerPulse 1.5s ease-out infinite;
}

@keyframes markerPulse {
  0% { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(2); opacity: 0; }
}

.maplibregl-ctrl-group {
  border: 1px solid var(--border-rule) !important;
  border-radius: 8px !important;
  overflow: hidden;
  background: rgba(242, 241, 236, 0.95) !important;
  box-shadow: 0 10px 22px rgba(16, 16, 16, 0.14) !important;
}

.maplibregl-ctrl button {
  width: 29px !important;
  height: 29px !important;
  overflow: hidden;
  border: 0;
  border-bottom: 1px solid var(--border-light);
  background: transparent !important;
}

.maplibregl-ctrl button span,
.maplibregl-ctrl-icon {
  width: 29px !important;
  height: 29px !important;
  min-width: 29px !important;
  max-width: 29px !important;
  display: block !important;
  filter: none;
}

.maplibregl-ctrl-attrib {
  background: rgba(242, 241, 236, 0.75) !important;
  color: #111 !important;
  font-size: 10px;
  font-weight: 600;
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  body.is-admin .dashboard {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 44dvh auto auto;
    min-height: 100dvh;
    height: auto;
  }

  body.is-admin .map-container {
    grid-column: 1;
    grid-row: 1;
    min-height: 0;
    height: 44dvh;
    border-right: none;
    border-bottom: 2px solid var(--border-rule);
  }

  body.is-admin .hud {
    grid-column: 1;
    grid-row: 2;
    max-height: none;
    overflow: visible;
    border-bottom: 2px solid var(--border-rule);
  }

  body.is-admin .brand-rail {
    min-height: 62px;
    padding: 12px 16px;
  }

  body.is-admin .brand-rail h1 {
    font-size: 19px;
  }

  body.is-admin .mode-label {
    margin: 0;
    font-size: 10px;
  }

  body.is-admin .readings {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  body.is-admin .reading {
    min-height: 58px;
    padding: 10px 16px;
  }

  body.is-admin .reading:nth-child(2) {
    grid-column: 1 / -1;
  }

  body.is-admin .reading strong {
    font-size: clamp(19px, 6vw, 25px);
  }

  body.is-admin .map-status-card {
    top: 12px;
    left: 12px;
    width: min(270px, calc(100% - 24px));
    padding: 10px 12px;
  }

  body.is-admin .map-status-card strong {
    font-size: 20px;
  }

  .hud {
    flex-direction: column;
    height: auto;
    max-height: 50vh;
    overflow-y: auto;
  }
  .brand-rail {
    width: 100%;
    flex-basis: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-rule);
    flex-direction: row;
    align-items: center;
  }
  .readings {
    flex-direction: column;
    border-right: none;
  }
  .reading {
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }
  .admin-panel {
    grid-column: 1;
    grid-row: 3;
    width: 100%;
    flex-basis: auto;
    border-left: none;
    border-top: none;
    padding: 16px;
  }

  .admin-header h2,
  .pin-card h2 {
    font-size: 30px;
  }

  .admin-header {
    align-items: center;
    padding-bottom: 12px;
  }

  .admin-header button {
    min-width: 68px;
    height: 36px;
  }

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

  .admin-section {
    grid-template-columns: 1fr;
  }

  .admin-section-wide {
    grid-column: auto;
    grid-template-columns: 1fr;
  }

  .admin-section {
    padding: 12px;
  }

  .admin-section-note {
    font-size: 11px;
  }

  .pin-lock {
    display: block;
    align-items: start;
    padding: 18px;
    overflow-y: auto;
  }

  .pin-card {
    position: fixed;
    top: 8dvh;
    left: 18px;
    right: 18px;
    width: auto;
    max-width: none;
    max-height: calc(100dvh - 36px);
    margin: 0;
    overflow-y: auto;
    padding: 22px;
    gap: 10px;
  }

  .pin-card input,
  .pin-card button {
    height: 52px;
  }

  .map-status-card {
    top: 16px;
    left: 16px;
    width: calc(100% - 32px);
    border-radius: 8px;
    padding: 16px 18px;
  }

  .map-status-card strong {
    font-size: 30px;
  }

  .locate-control {
    right: 10px;
    bottom: 152px;
    width: 42px;
    height: 42px;
  }

  body.is-viewer {
    height: 100dvh;
    overflow: hidden;
  }

  body.is-viewer .dashboard {
    height: 100dvh;
    overflow: hidden;
  }

  body.is-viewer .map-container {
    flex: 1 1 auto;
    min-height: 0;
  }

  body.is-viewer .hud {
    flex: 0 0 auto;
    max-height: none;
    overflow: visible;
    border-top: 2px solid var(--border-rule);
  }

  body.is-viewer .brand-rail {
    min-height: 68px;
    padding: 12px 18px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 14px;
  }

  body.is-viewer .brand-rail h1 {
    font-size: 20px;
    line-height: 0.95;
  }

  body.is-viewer .mode-label {
    display: block;
    margin: 0;
    font-size: 10px;
    white-space: nowrap;
  }

  body.is-viewer .brand-rail .status-wrap {
    margin-left: auto;
  }

  body.is-viewer #status {
    font-size: 12px;
    letter-spacing: 0.4px;
  }

  body.is-viewer .readings {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-right: none;
    border-top: 1px solid var(--border-rule);
  }

  body.is-viewer .reading {
    min-height: 56px;
    padding: 9px 16px 10px;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
  }

  body.is-viewer .reading:nth-child(1) {
    order: 1;
  }

  body.is-viewer .reading:nth-child(2) {
    order: 3;
    grid-column: 1 / -1;
    border-right: none;
    border-bottom: none;
  }

  body.is-viewer .reading:nth-child(3) {
    order: 2;
    border-right: none;
  }

  body.is-viewer .reading span {
    margin-bottom: 2px;
    font-size: 9px;
    letter-spacing: 1px;
  }

  body.is-viewer .reading strong {
    font-size: clamp(18px, 6.6vw, 27px);
    line-height: 1.02;
  }

  body.is-viewer .reading:nth-child(2) strong {
    font-size: clamp(16px, 5.7vw, 23px);
  }
}
