:root {
  color-scheme: dark;
  --panel: #101010;
  --panel-2: #181818;
  --text: #f2f5f8;
  --muted: #a8b0b8;
  --line: rgba(255, 255, 255, 0.14);
  --blue: #2f86ff;
  --video: #26b96f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  background: #05070a;
  color: var(--text);
}

.app-shell,
#map {
  position: fixed;
  inset: 0;
}

.topbar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.topbar > *,
.stats,
.camera-window {
  pointer-events: auto;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  text-shadow: 0 1px 4px #000;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-shadow: 0 1px 4px #000;
}

.right-controls {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  max-width: min(700px, calc(100vw - 300px));
}

.map-controls {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
}

.menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  min-width: 170px;
  background: rgba(16, 16, 16, 0.97);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}

.menu-dropdown.hidden {
  display: none;
}

.menu-dropdown button,
.menu-dropdown select {
  width: 100%;
  height: 34px;
  text-align: left;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-box {
  background: #181818;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 28px 28px 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

.modal-box--wide {
  max-width: 520px;
  max-height: 88vh;
  max-height: 88svh;
  display: flex;
  flex-direction: column;
}

.privacy-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
  margin-bottom: 20px;
  padding-right: 4px;
}

.privacy-body p {
  margin: 0 0 14px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text);
  text-shadow: none;
}

.privacy-body p:last-child {
  margin-bottom: 0;
}

.btn-primary:disabled {
  background: #2a4a7a;
  color: rgba(255, 255, 255, 0.45);
  cursor: not-allowed;
}

.modal-box h2 {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 700;
}

.modal-body {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  text-shadow: none;
}

.modal-note {
  margin: 0 0 22px;
  font-size: 12px;
  color: var(--muted);
  text-shadow: none;
}

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

.btn-primary {
  padding: 0 16px;
  height: 38px;
  background: var(--blue);
  border: none;
  border-radius: 8px;
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.btn-primary:hover {
  background: #4a9bff;
}

.btn-secondary {
  padding: 0 14px;
  height: 38px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.btn-secondary:hover {
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--text);
}

button,
input,
select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(16, 16, 16, 0.94);
  color: var(--text);
  font: inherit;
}

button {
  padding: 0 12px;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  border-color: rgba(47, 134, 255, 0.9);
}

input,
select {
  min-width: 0;
  padding: 0 10px;
}

input {
  width: 260px;
}

.city-search-wrap {
  position: relative;
  width: 260px;
}

.city-search-wrap input {
  width: 100%;
}

.city-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  list-style: none;
  margin: 0;
  padding: 4px 0;
  background: rgba(16, 16, 16, 0.97);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
  max-height: 280px;
  overflow-y: auto;
}

.city-results.hidden {
  display: none;
}

.city-results li {
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  line-height: 1.3;
}

.city-results li:hover,
.city-results li.active {
  background: rgba(47, 134, 255, 0.25);
  color: #fff;
}

select {
  width: 128px;
}

.stats {
  position: absolute;
  left: 14px;
  bottom: 8px;
  z-index: 5;
  display: flex;
  gap: 8px;
}

.stats span,
.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: rgba(16, 16, 16, 0.9);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 12px;
  white-space: nowrap;
}

.badge.video {
  color: #07120d;
  background: var(--video);
  border-color: rgba(255, 255, 255, 0.4);
}

.badge.dir {
  color: var(--text);
  background: #2a2a40;
  border-color: rgba(255, 255, 255, 0.25);
}

.direction-row {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  flex-wrap: wrap;
  align-items: center;
}

.direction-row-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 600;
  margin-right: 2px;
}

.dir-btn {
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 5px;
}

.dir-btn.active {
  background: var(--blue);
  border-color: transparent;
  color: #fff;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #05070a;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-overlay.hidden {
  display: none;
}
.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 44px 36px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(340px, 90vw);
  text-align: center;
}
.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 12px;
}
.login-box h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--fg);
  margin: 0;
}
.login-subtitle {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0;
}
.login-error {
  color: #e55;
  font-size: 0.83rem;
  margin: 0;
  max-width: 260px;
}

.offline-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0d0d0d;
}

.camera-window {
  position: absolute;
  z-index: 10;
  right: 14px;
  bottom: 14px;
  width: min(760px, calc(100vw - 40px));
  min-width: 320px;
  max-height: calc(100vh - 90px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.camera-window.hidden {
  display: none;
}

.camera-window-head {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 16, 16, 0.98);
  cursor: move;
  user-select: none;
}

.camera-window-head h2 {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}

.window-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.window-actions button {
  height: 30px;
  padding: 0 9px;
}

.window-actions .icon-btn {
  width: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

button.active {
  background: var(--blue);
  border-color: transparent;
  color: #fff;
}

.details {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.meta-row {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.viewer {
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: min(540px, calc(100vh - 240px));
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
}

.viewer video,
.viewer img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.viewer-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.camera-log {
  min-height: 24px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.025);
  font-size: 12px;
}

.mapboxgl-ctrl-logo,
.mapboxgl-ctrl-attrib {
  display: none !important;
}

.mapboxgl-popup-content {
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}

.mapboxgl-popup-tip {
  border-top-color: var(--panel) !important;
}

@media (max-width: 820px) {
  .topbar {
    flex-direction: column;
    gap: 6px;
  }

  .topbar > div:first-child {
    display: flex;
    align-items: baseline;
    gap: 10px;
  }

  h1 {
    font-size: 16px;
    white-space: nowrap;
  }

  .topbar p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 55vw;
  }

  .right-controls {
    max-width: calc(100vw - 28px);
    width: 100%;
  }

  .map-controls {
    flex: 1 1 auto;
    min-width: 0;
  }

  input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 130px;
  }

  .city-search-wrap {
    flex: 1 1 auto;
    width: 100%;
    min-width: 130px;
  }

  select {
    width: 92px;
    flex-shrink: 0;
  }

  button,
  input,
  select {
    height: 42px;
  }

  /* Bottom sheet on mobile */
  .camera-window {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    min-width: unset;
    top: auto !important;
    bottom: 0;
    max-height: 75vh;
    border-radius: 14px 14px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  .camera-window-head {
    height: 52px;
    cursor: default;
    position: relative;
  }

  /* Drag indicator pill */
  .camera-window-head::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
  }

  .details {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* Privacy modal — full-screen sheet on mobile */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .modal-box {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 24px 20px 28px;
  }

  .modal-box--wide {
    max-height: 92vh;
    max-height: 92svh;
    width: 100%;
    border-radius: 20px 20px 0 0;
  }

  .privacy-body p {
    font-size: 15px;
    line-height: 1.7;
  }

  .modal-body {
    font-size: 15px;
  }

  .modal-actions {
    justify-content: stretch;
  }

  .modal-actions .btn-primary,
  .modal-actions .btn-secondary {
    flex: 1;
    height: 50px;
    font-size: 15px;
    justify-content: center;
    display: flex;
    align-items: center;
  }
}
