:root {
  --bg-primary: #0f1419;
  --bg-secondary: #1a2028;
  --bg-tertiary: #232b36;
  --bg-hover: #2a3441;
  --border: #2d3845;
  --accent-blue: #00a8ff;
  --accent-blue-hover: #1fb4ff;
  --accent-orange: #ff6b35;
  --text-primary: #e4e6eb;
  --text-secondary: #8a95a5;
  --text-muted: #5a6573;
  --success: #4ade80;
  --danger: #ef4444;
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

body {
  display: grid;
  grid-template-rows: 56px 1fr 32px;
  overflow: hidden;
}

.mono {
  font-family: "JetBrains Mono", monospace;
}

.topbar,
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border-color: var(--border);
}

.topbar {
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.statusbar {
  padding: 0 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

.status-left,
.status-right,
.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-center {
  flex: 1;
  max-width: 480px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.logo-accent {
  color: var(--success);
}

.nav-links {
  display: flex;
  gap: 6px;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 6px;
}

.nav-link.active,
.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.search-box input {
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  outline: none;
}

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-icon,
.map-ctrl-btn,
.icon-btn,
.filter-chip {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent-blue);
  color: #001018;
  padding: 8px 12px;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-blue-hover);
}

.btn-secondary,
.btn-icon,
.map-ctrl-btn,
.icon-btn,
.filter-chip {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--danger);
}

.btn-icon {
  width: 34px;
  height: 34px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-orange));
  font-weight: 600;
}

.main {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 0;
}

.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.sidebar-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.badge {
  background: var(--success);
  color: #062414;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}

.sidebar-filters {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.filter-chip.active {
  border-color: var(--success);
  color: var(--success);
  background: rgba(74, 222, 128, 0.12);
}

#watchStreamBtn {
  background: var(--success);
  color: #062414;
}

#watchStreamBtn:hover {
  background: #66e59a;
}

.marker-list {
  overflow: auto;
  padding: 8px;
}

.marker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}

.marker-item.enter {
  animation: markerItemEnter 220ms ease both;
  animation-delay: var(--enter-delay, 0ms);
}

@keyframes markerItemEnter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.marker-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.marker-item:hover,
.marker-item.active {
  background: var(--bg-tertiary);
}

.marker-item-info {
  min-width: 0;
  flex: 1;
}

/* Без Title — компактная строка; с Title — на всю ширину списка */
.marker-item:not(.has-share-title) .marker-item-info {
  flex: 0 1 auto;
}

.marker-item-viewers {
  margin-left: auto;
  min-width: 28px;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}

.marker-item-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stream-lock-icon {
  flex: 0 0 auto;
  font-size: 13px;
  line-height: 1;
  opacity: 0.92;
}

.sidebar-filters-access {
  margin-top: 4px;
}

.marker-item-subtitle {
  color: var(--text-secondary);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.marker-item-coords {
  color: var(--text-muted);
  font-size: 12px;
}

.marker-item-delete {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 10px;
}

.map-wrapper {
  position: relative;
  min-height: 0;
}

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

.custom-marker {
  background: transparent !important;
  border: none !important;
}

.custom-marker-inner {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.6));
}

.custom-marker-pin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px rgba(15, 20, 25, 0.35);
}

.leaflet-control-attribution,
.leaflet-control-zoom {
  display: none !important;
}

.icon-selector,
.map-controls,
.detail-panel {
  position: absolute;
  z-index: 500;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.icon-selector {
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px;
}

.icon-selector-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-right: 6px;
}

.icon-btn {
  width: 34px;
  height: 34px;
}

.icon-btn.active {
  border-color: var(--accent-blue);
}

.map-controls {
  top: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
}

.mobile-list-btn {
  display: none;
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 600;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.floating-store-badges {
  position: fixed;
  right: 14px;
  bottom: 46px;
  z-index: 2600;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  max-width: calc(100vw - 28px);
}

/* Якоря внутри колонки не должны быть position:fixed — иначе оба «прилипают»
   к одному углу и нижняя ссылка перекрывает клики по App Store. */
.floating-store-badges > .floating-store-badge {
  position: relative !important;
  right: auto !important;
  bottom: auto !important;
  z-index: auto !important;
}

.floating-store-badge {
  position: fixed;
  right: 14px;
  bottom: 46px;
  z-index: 2600;
  display: inline-block;
  box-shadow: var(--shadow);
}

.floating-store-badge img {
  display: block;
  height: 42px;
  width: auto;
}

.floating-store-fallback {
  display: none;
  height: 42px;
  line-height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid #66e59a;
  background: var(--success);
  color: #062414;
  font-size: 13px;
  font-weight: 700;
}

.floating-store-badge:hover {
  filter: brightness(1.04);
}

.floating-store-badge.hidden {
  opacity: 0;
  pointer-events: none;
}

.floating-store-badges.hidden {
  opacity: 0;
  pointer-events: none;
}

.map-ctrl-btn {
  width: 34px;
  height: 34px;
}

.map-basemap-btn {
  font-size: 16px;
  line-height: 1;
}

.detail-panel {
  right: 14px;
  bottom: 14px;
  width: 320px;
}

.detail-panel.hidden,
.modal-backdrop.hidden {
  display: none;
}

.detail-header,
.detail-body,
.detail-footer {
  padding: 12px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.detail-title-wrap {
  display: flex;
  gap: 10px;
  align-items: center;
}

.detail-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.detail-title-wrap h3 {
  margin: 0;
  line-height: 1.2;
}

.btn-close {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
  border-bottom: 0;
}

.detail-label {
  color: var(--text-muted);
  font-size: 12px;
}

.detail-value-marquee {
  display: inline-block;
  max-width: 170px;
  white-space: nowrap;
  overflow: hidden;
  vertical-align: bottom;
}

.detail-value-marquee .marquee-track {
  display: inline-block;
  white-space: nowrap;
  transform: translateX(0);
}

.detail-value-marquee.marquee .marquee-track {
  padding-right: 26px;
  animation: detailMarquee 7s linear infinite;
}

@keyframes detailMarquee {
  0% { transform: translateX(0); }
  12% { transform: translateX(0); }
  88% { transform: translateX(calc(-1 * var(--marquee-shift, 0px))); }
  100% { transform: translateX(calc(-1 * var(--marquee-shift, 0px))); }
}

.detail-footer {
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border);
}

.detail-footer button {
  flex: 1;
}

.detail-stream-wrap {
  margin-top: 10px;
  position: relative;
}

.detail-stream-preview,
video.detail-stream-preview {
  width: 100%;
  height: 150px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1419;
}

video.fullscreen-img {
  width: auto;
  height: auto;
  max-width: 95vw;
  max-height: 90vh;
  background: #000;
}

.fullscreen-player {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 95vw;
  max-height: 90vh;
  background: #000;
  border-radius: 10px;
}

.fullscreen-player video.fullscreen-img {
  position: relative;
  z-index: 1;
}

video.fullscreen-img.is-buffering {
  /* Keep last decoded frame visible under overlay (no opacity flash). */
}

.stream-buffering-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.28);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.stream-buffering-overlay.visible {
  opacity: 1;
}

.stream-buffering-overlay::before {
  content: "";
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  animation: sc-stream-spin 0.95s linear infinite;
}

.stream-buffering-overlay::after {
  content: attr(data-label);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

@keyframes sc-stream-spin {
  to {
    transform: rotate(360deg);
  }
}

.fullscreen-player:fullscreen,
.fullscreen-player:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border-radius: 0;
}

.fullscreen-player:fullscreen video.fullscreen-img,
.fullscreen-player:-webkit-full-screen video.fullscreen-img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Live player: custom play, mute, fullscreen (no native seek/PiP bar) */
video.stream-live-video {
  pointer-events: none;
}

.stream-player-controls {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 4;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.stream-ctrl-btn {
  min-width: 44px;
  height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.stream-ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.stream-ctrl-btn:focus-visible {
  outline: 2px solid #00a8ff;
  outline-offset: 2px;
}

#streamModal.stream-fs-active.controls-hidden .stream-player-controls,
#streamModal.stream-fs-active.controls-hidden .fullscreen-close,
#streamModal.stream-fs-active.controls-hidden .fullscreen-info {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

#streamModal.stream-fs-active .stream-player-controls,
#streamModal.stream-fs-active .fullscreen-close,
#streamModal.stream-fs-active .fullscreen-info {
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Leaflet popup: HLS or JPEG preview on map pin */
.leaflet-popup-content .popup-stream-wrap {
  margin-top: 8px;
  position: relative;
  width: 220px;
  max-width: 100%;
}

.leaflet-popup-content .popup-stream-video,
.leaflet-popup-content .popup-stream-img {
  width: 100%;
  height: 124px;
  object-fit: cover;
  border-radius: 6px;
  background: #0f1419;
  display: block;
}

.leaflet-popup-content .popup-stream-video.hidden,
.leaflet-popup-content .popup-stream-img.hidden {
  display: none;
}

.leaflet-popup-content .popup-stream-hint {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-secondary, #8b95a5);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  z-index: 1000;
}

.modal {
  width: min(380px, calc(100vw - 24px));
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.modal-sub {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 6px 0 12px;
}

.pin-modal-input {
  width: 100%;
  box-sizing: border-box;
  margin: 8px 0 4px;
  padding: 12px 14px;
  font-size: 20px;
  letter-spacing: 0.2em;
  text-align: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
}

.pin-modal-error {
  color: #f87171;
  font-size: 13px;
  margin: 0 0 10px;
}

.pin-modal-error.hidden {
  display: none;
}

.modal a {
  color: var(--accent-blue);
  text-decoration: none;
}

.modal a:hover {
  color: var(--accent-blue-hover);
  text-decoration: underline;
}

.modal-field {
  display: block;
}

.modal-field input {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 10px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.modal-coords {
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

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

.fullscreen-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.fullscreen-img {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.fullscreen-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
}

.fullscreen-info {
  position: absolute;
  left: 20px;
  top: 20px;
  z-index: 2;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(4px);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.status-separator {
  color: var(--text-muted);
}

@media (max-width: 1000px) {
  .nav-links {
    display: none;
  }
}

@media (max-width: 760px) {
  .main {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: flex;
    position: fixed;
    left: 0;
    top: 56px;
    bottom: 32px;
    width: min(88vw, 340px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 1200;
    box-shadow: 10px 0 24px rgba(0, 0, 0, 0.45);
  }

  .topbar-center {
    display: none;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .mobile-list-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .floating-store-badges {
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(32px + env(safe-area-inset-bottom) + 12px);
    z-index: 3000;
    display: flex !important;
  }

  .floating-store-badge--solo {
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(32px + env(safe-area-inset-bottom) + 12px);
    z-index: 3000;
    display: inline-block !important;
  }

  .floating-store-badges > .floating-store-badge {
    display: inline-block !important;
  }

  .floating-store-badge img {
    height: 40px;
    display: block !important;
  }

  .floating-store-fallback {
    height: 38px;
    line-height: 38px;
    font-size: 12px;
    padding: 0 12px;
  }

  .status-right {
    display: none;
  }

  .statusbar {
    justify-content: center;
    padding: 0 10px;
  }

  .status-left {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .detail-panel {
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    max-height: 62vh;
    overflow: auto;
  }
}

/* Live stream marker clusters (Leaflet.markercluster) — match app MapLibre green clusters */
.marker-cluster.sc-live-cluster {
  background-color: rgba(46, 125, 50, 0.35);
}

.marker-cluster.sc-live-cluster div {
  background-color: #2e7d32;
  color: #fff;
  font-weight: 700;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
