/* ===== IA KLEN — карта повітряних загроз ===== */
:root {
  --bg: #090a0c;
  --panel: rgba(14, 15, 17, .96);
  --panel-2: #181a1e;
  --border: rgba(126, 132, 142, .34);
  --text: #f2f3f5;
  --text-dim: #8c9098;
  --accent: #ff453a;
  --radius: 12px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

#map { position: absolute; inset: 0; background: var(--bg); }

/* Темна карта без прив'язки до API-ключа: світлі плитки OSM інвертуємо до чорної основи. */
.leaflet-tile-pane { filter: grayscale(1) invert(1) brightness(.43) contrast(1.18); }
.leaflet-container { background: var(--bg); font: inherit; }
.leaflet-control-attribution {
  background: rgba(14,15,17,.7) !important; color: var(--text-dim) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.leaflet-popup-content { margin: 12px 16px; font-size: 13px; line-height: 1.5; }
.leaflet-popup-close-button { color: var(--text-dim) !important; }

/* ===== Верхня панель ===== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; align-items: flex-start;
  padding: 12px 32px; gap: 12px; pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.logo {
  height: 42px; display: flex; align-items: center;
  background: rgba(9,10,12,.94); border: 1px solid var(--border); color: #fff;
  font-weight: 700; font-size: 15px; padding: 0 14px; border-radius: 8px; letter-spacing: .3px;
  user-select: none;
}

/* Пошук */
.search { position: absolute; left: 50%; transform: translateX(-50%); width: 280px; }
.search__box {
  display: flex; align-items: center; gap: 10px;
  background: rgba(23,24,27,.96); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 13px; height: 42px;
  box-shadow: 0 9px 28px rgba(0,0,0,.4);
}
.search__box:focus-within { border-color: #4a4e55; }
.search__icon { width: 24px; height: 24px; color: var(--text-dim); flex: none; }
.search__box input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 15px; min-width: 0;
}
.search__box input::placeholder { color: var(--text-dim); }
.search__clear { background: none; border: none; cursor: pointer; color: var(--text-dim); padding: 4px; display: flex; }
.search__clear svg { width: 24px; height: 24px; }
.search__clear:hover { color: var(--text); }

.search__dropdown {
  margin-top: 8px; background: rgba(23,24,27,.97);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: 0 10px 34px rgba(0,0,0,.55);
}
.search__item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; cursor: pointer; font-size: 14.5px;
}
.search__item:hover, .search__item--active { background: rgba(255,255,255,.06); }
.search__item .chev { color: var(--text-dim); flex: none; font-size: 12px; }
.search__item .name { color: var(--text); white-space: nowrap; }
.search__item .region { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search__empty { padding: 12px 14px; color: var(--text-dim); font-size: 13.5px; }


/* Правий блок */
.topbar__right { margin-left: auto; display: flex; gap: 0; align-items: center; }
.clock {
  width: 194px; height: 40px; display: flex; align-items: center; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: rgba(9,10,12,.92); font-size: 13px; letter-spacing: .25px;
  font-variant-numeric: tabular-nums; white-space: nowrap; margin-right: 10px;
}
.iconbtn {
  position: relative; width: 70px; height: 40px; flex: none;
  background: rgba(9,10,12,.92); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.iconbtn svg { width: 24px; height: 24px; }
.iconbtn:hover { background: var(--panel-2); }
#btn-bell {
  border-radius: 8px 0 0 8px;
  border-right: 0;
}
#btn-menu {
  margin-left: -1px;
  border-radius: 0 8px 8px 0;
}
#btn-bell svg { fill: var(--text); stroke: none; }
#btn-menu svg { stroke-linecap: round; }
.badge {
  position: absolute; top: 4px; right: 16px; min-width: 18px; height: 18px;
  background: var(--accent); color: #fff; border-radius: 9px;
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  padding: 0 5px; border: 2px solid var(--bg);
}

/* ===== Панелі меню і сповіщень ===== */
.menu-panel, .notif-panel {
  position: fixed; top: 64px; z-index: 1100; width: 342px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0,0,0,.58); padding: 10px;
}
.menu-panel { right: 32px; }
.notif-panel {
  top: 58px;
  right: 104px;
  width: 272px;
  height: 400px;
  max-height: calc(100vh - 68px);
  display: flex;
  flex-direction: column;
}
.menu-panel[hidden], .notif-panel[hidden] { display: none; }

.menu-panel__title, .notif-panel__head {
  font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px;
  padding: 6px 8px 10px; display: flex; justify-content: space-between; align-items: center;
}
.notif-panel { padding: 0; overflow: hidden; }
.notif-panel__head {
  min-height: 42px;
  padding: 0 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  border-bottom: 1px solid var(--border);
}
.notif-panel__head button {
  width: 34px; height: 34px; margin-right: -5px;
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 28px; font-weight: 200; line-height: 1;
}
.notif-panel__head button:hover { color: var(--text); background: rgba(255,255,255,.05); border-radius: 6px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 8px;
  font-size: 13px; border-radius: 6px; cursor: pointer; color: var(--text);
}
.menu-item:hover { background: rgba(255,255,255,.05); }
.menu-item input { accent-color: var(--accent); }
.menu-panel__sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu-item--btn { background: none; border: none; width: 100%; text-align: left; font: inherit; color: var(--text-dim); }
.menu-item--btn:hover { color: var(--text); }

#notif-list { list-style: none; overflow-y: auto; }
#notif-list li {
  position: relative;
  min-height: 78px;
  padding: 11px 10px 12px;
  border-bottom: 1px solid rgba(126,132,142,.25);
  cursor: pointer;
  font-size: 12px;
}
#notif-list li:hover { background: rgba(255,255,255,.045); }
.notif-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 14px;
  color: var(--text-dim);
  font-size: 10.5px;
  line-height: 1.2;
}
.notif-meta .region {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: uppercase;
}
#notif-list li .msg {
  min-height: 16px;
  margin-top: 5px;
  color: #43baff;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.3;
  text-transform: uppercase;
}
#notif-list li .t {
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#notif-list li .details { color: #d6d8dc; font-size: 11.5px; line-height: 1.4; margin-top: 5px; }
#notif-list li .details:empty { display: none; }
#notif-list li.unread { border-left: 2px solid #43baff; padding-left: 8px; }
#notif-list .empty { color: var(--text-dim); padding: 14px 10px; border: none; cursor: default; }

/* ===== Кнопки керування ===== */
.controls {
  position: fixed; right: 32px; bottom: 32px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
}
.controls button {
  width: 42px; height: 42px; background: rgba(9,10,12,.94);
  border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.controls button:hover { background: var(--panel-2); }
.controls button svg { width: 24px; height: 24px; }
.controls #zoom-in { border-radius: 7px 7px 3px 3px; margin-bottom: -10px; }
.controls #zoom-out { border-radius: 3px 3px 7px 7px; }

#btn-info {
  position: fixed; left: 32px; bottom: 32px; z-index: 1000;
  width: 42px; height: 42px; border-radius: 7px;
  background: rgba(9,10,12,.94); border: 1px solid var(--border); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#btn-info:hover { background: var(--panel-2); }
#btn-info svg { width: 24px; height: 24px; }

/* ===== Загрози на карті ===== */
.threat { position: relative; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; }
.threat .threat-icon {
  font-size: 18px;
  line-height: 1;
  filter: drop-shadow(0 0 4px currentColor);
  z-index: 2;
  position: relative;
}
.threat .threat-icon--image {
  display: block;
  object-fit: contain;
  max-width: 100%;
  max-height: 100%;
  filter: drop-shadow(0 0 4px currentColor);
}
.threat .ring {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid currentColor; opacity: 0;
  animation: threatPulse 1.7s ease-out infinite;
}
@keyframes threatPulse {
  0%   { transform: scale(.4); opacity: .9; }
  70%  { transform: scale(1.3); opacity: 0; }
  100% { transform: scale(1.3); opacity: 0; }
}
.threat .dot {
  position: absolute; inset: 1px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 8px currentColor;
}
.threat--missile  { color: #ff453a; }
.threat--drone    { color: #ff9f0a; }
.threat--aircraft { color: #5ac8fa; }
.threat--impact   { color: #ff2d55; }

/* маркер цілі */
.target-mark { color: #ff453a; }
.target-mark svg { width: 16px; height: 16px; filter: drop-shadow(0 0 4px rgba(255,69,58,.8)); }

/* літак ADS-B */
.plane-icon { color: #5ac8fa; width: 22px; height: 22px; }
.plane-icon svg { width: 100%; height: 100%; filter: drop-shadow(0 0 3px rgba(90,200,250,.6)); }

/* маркер пошуку */
.search-pulse { color: #ffd60a; width: 14px; height: 14px; position: relative; }
.search-pulse .dot { position: absolute; inset: 3px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }
.search-pulse .ring { position: absolute; inset: -8px; border-radius: 50%; border: 2px solid currentColor; animation: threatPulse 1.2s ease-out infinite; }

/* мій гео-маркер */
.me-dot { color: #30d158; width: 16px; height: 16px; position: relative; }
.me-dot .dot { position: absolute; inset: 4px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }
.me-dot .ring { position: absolute; inset: -6px; border-radius: 50%; border: 2px solid currentColor; animation: threatPulse 2s ease-out infinite; }

/* ===== Легенда ===== */
.legend {
  position: fixed;
  left: 32px;
  bottom: 92px;
  z-index: 1000;
  background: rgba(9, 10, 12, 0.96);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 223px;
  height: 328px;
  padding: 16px;
  user-select: none;
}
.legend__title {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  height: 24px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.legend__toggle {
  width: 26px;
  height: 26px;
  margin: -6px -6px -6px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 23px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
}
.legend__toggle:hover { background: rgba(255,255,255,.08); color: var(--text); }
.legend[hidden] { display: none; }
.legend__item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 29px;
  font-size: 13.5px;
  color: var(--text);
  padding: 0;
}
.legend__icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  flex: 0 0 24px;
}
.legend__icon--unknown { transform: rotate(-90deg); }
.legend__alert-icon {
  width: 24px;
  height: 24px;
  border-radius: 0;
  border: 1px solid #ff453a;
  background: rgba(159, 43, 43, .48);
  color: transparent;
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  box-shadow: none;
}

/* адаптивність */
@media (max-width: 900px) {
  .clock { display: none; }
  .search { width: min(272px, calc(100vw - 220px)); }
}

@media (max-width: 600px) {
  .topbar { padding: max(10px, env(safe-area-inset-top)) 12px 10px; align-items: center; }
  .logo { font-size: 15px; padding: 10px 13px; border-radius: 9px; }
  .topbar__right { gap: 8px; }
  .iconbtn { width: 42px; height: 42px; border-radius: 10px; }
  .search { top: 62px; left: 12px; transform: none; width: calc(100vw - 24px); }
  .search__box { height: 44px; }
  .search__dropdown { max-height: 42vh; overflow-y: auto; }
  .search__item { padding: 10px 12px; }

  .menu-panel, .notif-panel {
    top: 116px; right: 12px; left: 12px; width: auto;
    height: auto; max-height: calc(100vh - 132px); max-height: calc(100dvh - 132px);
  }
  .menu-item { min-height: 42px; padding: 9px 8px; }
  .notif-panel { max-height: calc(100vh - 132px); max-height: calc(100dvh - 132px); }

  .controls { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); gap: 8px; }
  .controls button { width: 42px; height: 42px; }
  #btn-info { left: 12px; bottom: max(12px, env(safe-area-inset-bottom)); width: 42px; height: 42px; }
  .legend {
    left: 12px; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 54px);
    min-width: 0; width: min(208px, calc(100vw - 78px));
    max-height: 44vh; max-height: 44dvh; overflow-y: auto; padding: 10px 12px;
  }
  .legend__item { font-size: 12.5px; padding: 3px 0; gap: 8px; }
  .legend__icon { width: 24px; height: 24px; flex-basis: 24px; }
}

@media (max-width: 380px) {
  .logo { font-size: 14px; padding-inline: 11px; }
  .legend { width: min(190px, calc(100vw - 72px)); }
  .legend__item { font-size: 12px; }
}

@media (max-height: 520px) and (max-width: 900px) {
  .legend { max-height: 34vh; }
  .menu-panel { top: 64px; max-height: calc(100dvh - 78px); }
  .notif-panel { top: 58px; max-height: calc(100dvh - 72px); }
  .search { top: 10px; left: 92px; width: calc(100vw - 210px); }
  .search__box { height: 42px; }
}
