/* =========================================================
   Бойовий шлях 24 ОШП «Айдар» — стилі
   ========================================================= */

:root {
  --bg: #000000;
  --panel: #0a0a0a;
  --panel-2: #111111;
  --panel-3: #161616;
  --border: #1c1c1c;
  --border-strong: #2a2a2a;
  --text: #e8e8e8;
  --text-dim: #8a8a8a;
  --text-muted: #5a5a5a;
  --accent: #2CC23B;
  --accent-soft: #0e1a10;
  --accent-glow: rgba(44, 194, 59, 0.35);

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);

  --sidebar-w: 400px;
  --radius: 4px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Geologica', sans-serif;
  font-weight: 400;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

h1, h2, h3, h4, .heading {
  font-family: 'Tektur', sans-serif;
  font-weight: 700;
  letter-spacing: 0.02em;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* =========================================================
   Layout
   ========================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  width: 100vw;
}

/* =========================================================
   Mobile top bar (hidden on desktop)
   ========================================================= */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1100;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: linear-gradient(180deg, rgba(0,0,0,0.92) 60%, rgba(0,0,0,0));
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.topbar-title {
  font-family: 'Tektur', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}
.topbar-title .accent { color: var(--accent); }

.topbar-count {
  font-family: 'Tektur', sans-serif;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--accent);
  background: rgba(44, 194, 59, 0.12);
  border: 1px solid rgba(44, 194, 59, 0.4);
  padding: 4px 8px;
  border-radius: 999px;
}

/* =========================================================
   Sidebar
   ========================================================= */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.sheet-handle { display: none; }

.sidebar-header {
  padding: 24px 22px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-bullet {
  width: 10px;
  height: 47px;
  flex-shrink: 0;
  fill: #999966;
  display: block;
}
.brand-title {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-family: 'Tektur', sans-serif;
  font-weight: 700;
  font-size: 18px;
  line-height: 1.05;
  text-transform: uppercase;
  letter-spacing: 0.01em;
}
.brand-line { color: var(--text); white-space: nowrap; }
.brand-line.accent { color: var(--accent); }

.sidebar-header p {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.stats {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-family: 'Tektur', sans-serif;
}
.stat {
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat .num {
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  display: block;
}
.stat .label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 4px;
}

/* =========================================================
   Filters
   ========================================================= */
.filters-wrap {
  position: relative;
  border-bottom: 1px solid var(--border);
}
.filters {
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-family: 'Tektur', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  border-radius: 2px;
  transition: all 0.15s ease;
  white-space: nowrap;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}
.chip:hover { color: var(--text); border-color: #404040; }
.chip.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* =========================================================
   Event list
   ========================================================= */
.events {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 12px calc(24px + var(--safe-bottom));
  scrollbar-gutter: stable;
  contain: content;
}
.events::-webkit-scrollbar { width: 6px; }
.events::-webkit-scrollbar-track { background: transparent; }
.events::-webkit-scrollbar-thumb { background: #1f1f1f; border-radius: 3px; }
.events::-webkit-scrollbar-thumb:hover { background: #333; }

.event-card {
  padding: 12px 14px;
  margin: 6px 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 2px solid var(--border-strong);
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .12s ease;
  border-radius: var(--radius);
  user-select: none;
  contain: content;
  content-visibility: auto;
  contain-intrinsic-size: 70px;
}
.event-card:hover {
  border-left-color: var(--accent);
  background: var(--panel-3);
}
.event-card:active { transform: scale(0.99); }
.event-card.active {
  border-color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(44, 194, 59, 0.15);
}

.event-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.event-date {
  font-family: 'Tektur', sans-serif;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.event-period {
  font-family: 'Tektur', sans-serif;
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 2px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
}
.event-place {
  font-family: 'Tektur', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 2px 0 5px;
}
.event-snippet {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* =========================================================
   Map
   ========================================================= */
.map-wrap {
  position: relative;
  overflow: hidden;
  background: #050505;
}
#map {
  width: 100%;
  height: 100%;
  background: #050505;
}

.leaflet-container {
  background: #050505;
  font-family: 'Geologica', sans-serif;
  outline: none;
}
.leaflet-control-attribution {
  background: rgba(0, 0, 0, 0.7) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
  font-family: 'Geologica', sans-serif;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-control-zoom {
  margin: 16px !important;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5) !important;
  border: none !important;
}
.leaflet-control-zoom a {
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--border-strong) !important;
  font-family: 'Tektur', sans-serif;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}
.leaflet-control-zoom a:hover {
  background: var(--accent) !important;
  color: #000 !important;
  border-color: var(--accent) !important;
}

/* Custom marker */
.pin {
  width: 9px; height: 9px;
  background: #1f9c2c;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000;
  position: relative;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}
.custom-pin:hover .pin {
  background: var(--accent);
  transform: scale(1.35);
  box-shadow: 0 0 0 1px #000, 0 0 12px var(--accent-glow);
}
.pin.dim {
  background: #2a2a2a;
  box-shadow: 0 0 0 1px #000;
  opacity: 0.5;
}
.custom-pin:hover .pin.dim {
  background: #2a2a2a;
  transform: none;
  box-shadow: 0 0 0 1px #000;
}
.pin.active {
  background: #fff;
  transform: scale(1.45);
  box-shadow: 0 0 0 1px #000, 0 0 12px #fff;
}
.custom-pin:hover .pin.active {
  background: #fff;
  box-shadow: 0 0 0 1px #000, 0 0 14px #fff;
}

/* tap target — increase hit area without visual change */
.custom-pin { padding: 8px; margin: -8px; }

/* Tooltip on hover */
.leaflet-tooltip.pin-tooltip {
  background: var(--panel) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--radius) !important;
  padding: 10px 14px !important;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6) !important;
  font-family: 'Geologica', sans-serif !important;
  color: var(--text) !important;
  white-space: nowrap;
}
.leaflet-tooltip.pin-tooltip::before { display: none !important; }

.pin-tooltip .tip-date {
  font-family: 'Tektur', sans-serif;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.pin-tooltip .tip-place {
  font-family: 'Tektur', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  line-height: 1.1;
}

/* Popup */
.leaflet-popup-content-wrapper {
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--accent) !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 6px 30px rgba(0,0,0,0.6), 0 0 18px rgba(44, 194, 59, 0.15) !important;
  padding: 0 !important;
}
.leaflet-popup-content {
  margin: 14px 16px !important;
  font-family: 'Geologica', sans-serif !important;
  line-height: 1.5;
  width: 280px !important;
  max-width: calc(100vw - 64px) !important;
}
.leaflet-popup-tip { background: var(--accent) !important; }
.leaflet-popup-close-button {
  color: var(--text-dim) !important;
  font-size: 22px !important;
  padding: 6px 10px 0 0 !important;
  width: 28px !important;
  height: 28px !important;
}
.leaflet-popup-close-button:hover { color: var(--accent) !important; }

.pop-date {
  font-family: 'Tektur', sans-serif;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--accent);
  text-transform: uppercase;
}
.pop-place {
  font-family: 'Tektur', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 4px 0 8px;
  text-transform: uppercase;
  line-height: 1.2;
}
.pop-stage {
  font-family: 'Tektur', sans-serif;
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.pop-desc {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.55;
}

/* Legend */
.legend {
  position: absolute;
  bottom: calc(18px + var(--safe-bottom));
  left: calc(18px + var(--safe-left));
  background: rgba(10, 10, 10, 0.92);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 10px 12px;
  z-index: 500;
  font-size: 11px;
  border-radius: var(--radius);
}
.legend-title {
  font-family: 'Tektur', sans-serif;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
}
.legend-dot {
  width: 10px; height: 10px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent-glow);
}

/* Map title */
.map-title {
  position: absolute;
  top: calc(18px + var(--safe-top));
  right: calc(18px + var(--safe-right));
  background: rgba(10, 10, 10, 0.92);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 10px 14px;
  z-index: 500;
  border-radius: var(--radius);
  font-family: 'Tektur', sans-serif;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.map-title .accent { color: var(--accent); }

/* Sheet backdrop */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* =========================================================
   TABLET (≤ 1100px)
   ========================================================= */
@media (max-width: 1100px) {
  :root { --sidebar-w: 340px; }
  .sidebar-header h1 { font-size: 19px; }
  .stat .num { font-size: 19px; }
}

/* =========================================================
   MOBILE (≤ 768px) — bottom sheet
   ========================================================= */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .map-wrap { grid-row: 1; grid-column: 1; }

  .topbar { display: none; }

  .map-title { display: none; }
  .legend {
    bottom: calc(110px + var(--safe-bottom));
    left: calc(12px + var(--safe-left));
    padding: 8px 10px;
  }

  .leaflet-control-zoom {
    margin: 12px !important;
    margin-bottom: calc(120px + var(--safe-bottom)) !important;
  }
  .leaflet-control-attribution { font-size: 9px !important; }

  /* sidebar becomes a bottom sheet */
  .sidebar {
    grid-row: 1;
    grid-column: 1;
    align-self: end;
    width: 100%;
    height: 85dvh;
    max-height: 85dvh;
    border-right: none;
    border-top: 1px solid var(--border-strong);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
    transform: translateY(calc(100% - 96px - var(--safe-bottom)));
    transition: transform 0.32s var(--ease);
    z-index: 1000;
    will-change: transform;
    touch-action: pan-y;
  }
  .sidebar.open { transform: translateY(0); }
  .sidebar.dragging { transition: none; }

  .sheet-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 14px 6px;
    gap: 6px;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
  }
  .sheet-handle:active { cursor: grabbing; }
  .sheet-handle .grabber {
    width: 40px; height: 4px;
    background: #2e2e2e;
    border-radius: 2px;
    transition: background 0.15s ease;
  }
  .sidebar.open .sheet-handle .grabber { background: var(--border-strong); }
  .sheet-handle-label {
    font-family: 'Tektur', sans-serif;
    font-size: 11px;
    letter-spacing: 0.14em;
    color: var(--text-dim);
    text-transform: uppercase;
  }
  .sheet-handle-label .accent { color: var(--accent); }

  .sidebar-header {
    padding: 4px 18px 14px;
  }
  .sidebar-header h1 { font-size: 18px; }
  .sidebar-header p { font-size: 12px; margin-top: 6px; }
  .stats { margin-top: 12px; gap: 8px; }
  .stat { padding: 8px 10px; }
  .stat .num { font-size: 18px; }

  .filters {
    padding: 10px 14px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  .filters::-webkit-scrollbar { display: none; }
  .chip { scroll-snap-align: start; flex-shrink: 0; min-height: 36px; }

  .events { padding: 6px 12px calc(20px + var(--safe-bottom)); }
  .event-card { padding: 14px; }

  .backdrop.show { display: block; opacity: 1; }
}

/* iPhone SE / very small */
@media (max-width: 380px) {
  .sidebar-header { padding: 4px 14px 12px; }
  .sidebar-header h1 { font-size: 16px; }
  .stat .num { font-size: 16px; }
  .stat .label { font-size: 8px; }
}

/* =========================================================
   Reduced motion
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
