/* ===================================================================
   Pet Tracker — общий стиль (экран актёра + админ-панель)
   Тёмная тема, крупные элементы, высокий контраст для камеры.
   =================================================================== */

:root {
  --bg: #0a0e14;
  --bg-panel: rgba(16, 22, 32, 0.86);
  --bg-panel-solid: #121826;
  --line: rgba(255, 255, 255, 0.08);
  --text: #ffffff;
  --text-dim: #9fb0c3;
  --green: #29e07a;
  --blue: #2f7bff;
  --red: #ff2b39;
  --red-soft: rgba(255, 43, 57, 0.35);
  --amber: #ffb020;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

/* =================== ЭКРАН АКТЁРА (tracker) ======================== */

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}

/* ---- Верхняя панель ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: linear-gradient(180deg, rgba(10,14,20,0.96), rgba(10,14,20,0.0));
  position: relative; z-index: 30;
}
.sensor-id { display: flex; flex-direction: column; gap: 2px; }
.sensor-id .name { font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.sensor-id .sub { font-size: 12px; color: var(--text-dim); }

.status-pill {
  display: flex; align-items: center; gap: 8px;
  background: rgba(41, 224, 122, 0.12);
  border: 1px solid rgba(41, 224, 122, 0.35);
  color: var(--green);
  padding: 7px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  transition: all .3s;
}
.status-pill.warn { background: rgba(255,176,32,.12); border-color: rgba(255,176,32,.4); color: var(--amber); }
.status-pill.lost { background: rgba(255,43,57,.14); border-color: rgba(255,43,57,.45); color: var(--red); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; animation: blink 1.6s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.25} }

/* ---- Область карты ---- */
.map-wrap { position: relative; flex: 1 1 auto; overflow: hidden; }
#fakeMap, #leafletMap { position: absolute; inset: 0; }
#fakeMap svg { width: 100%; height: 100%; display: block; }
#leafletMap { display: none; background: #0c1018; }
body.map-leaflet #fakeMap { display: none; }
body.map-leaflet #leafletMap { display: block; }

/* затемнение карты в режимах поиска/потери */
.map-veil {
  position: absolute; inset: 0; background: rgba(4,7,12,0.0);
  pointer-events: none; transition: background .6s; z-index: 15;
}
body.scene-search .map-veil { background: rgba(4,7,12,0.55); }
body.scene-lost .map-veil { background: rgba(40,0,4,0.32); }

/* ---- Точка на фейк-карте (внутри SVG) ---- */
.ring { fill: var(--red); transform-box: fill-box; transform-origin: center; }
.fakeDot .ring1 { animation: pulseRing 2s ease-out infinite; }
.fakeDot .ring2 { animation: pulseRing 2s ease-out infinite 1s; }
.fakeDot .core { fill: var(--red); filter: drop-shadow(0 0 4px var(--red)); }
.fakeDot .core-inner { fill: #ffd2d6; }
@keyframes pulseRing {
  0%   { transform: scale(0.4); opacity: 0.55; }
  80%  { transform: scale(3.4); opacity: 0; }
  100% { transform: scale(3.4); opacity: 0; }
}

/* мигание точки при потере сигнала */
body.scene-lost .fakeDot { animation: dotBlink 0.7s steps(2,start) infinite; }
body.scene-lost #leaflet-dot { animation: dotBlink 0.7s steps(2,start) infinite; }
@keyframes dotBlink { 50% { opacity: 0.15; } }

/* ---- Точка для Leaflet (HTML divIcon) ---- */
.leaflet-dot { position: relative; width: 26px; height: 26px; }
.leaflet-dot .ldot-core {
  position: absolute; left: 50%; top: 50%; width: 18px; height: 18px;
  transform: translate(-50%,-50%); border-radius: 50%;
  background: var(--red); box-shadow: 0 0 10px 2px var(--red);
}
.leaflet-dot .ldot-inner {
  position: absolute; left: 50%; top: 50%; width: 7px; height: 7px;
  transform: translate(-50%,-50%); border-radius: 50%; background: #ffd2d6;
}
.leaflet-dot .ldot-ring {
  position: absolute; left: 50%; top: 50%; width: 18px; height: 18px;
  transform: translate(-50%,-50%); border-radius: 50%;
  border: 2px solid var(--red); animation: ringHtml 2s ease-out infinite;
}
.leaflet-dot .ldot-ring.r2 { animation-delay: 1s; }
@keyframes ringHtml {
  0% { width: 18px; height: 18px; opacity: .6; }
  100% { width: 90px; height: 90px; opacity: 0; }
}

/* ---- Нижняя панель ---- */
.bottombar {
  background: var(--bg-panel);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 16px 18px calc(env(safe-area-inset-bottom, 0px) + 16px);
  position: relative; z-index: 30;
}
.dist-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.dist { font-size: 38px; font-weight: 800; letter-spacing: -0.5px; line-height: 1; }
.dist .unit { font-size: 18px; font-weight: 600; color: var(--text-dim); margin-left: 4px; }
.dist-label { font-size: 13px; color: var(--text-dim); text-align: right; }
.moving-tag { color: var(--green); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: rgba(255,255,255,0.04); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 17px; font-weight: 700; margin-top: 3px; }
.stat .v.bat { color: var(--green); }

/* индикатор связи / спутников вверху справа */
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--green); }
.conn .bars { display: flex; align-items: flex-end; gap: 2px; height: 14px; }
.conn .bars i { width: 3px; background: var(--green); border-radius: 1px; }
.conn .bars i:nth-child(1){height:5px}.conn .bars i:nth-child(2){height:8px}
.conn .bars i:nth-child(3){height:11px}.conn .bars i:nth-child(4){height:14px}

/* ---- Оверлеи состояний ---- */
.center-overlay {
  position: absolute; inset: 0; z-index: 25;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; text-align: center; pointer-events: none;
}
.spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--red);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-text { font-size: 18px; font-weight: 600; }
.overlay-text small { display:block; color: var(--text-dim); font-weight: 400; font-size: 13px; margin-top: 4px; }

/* всплывающая плашка «Сигнал найден» */
.flash-toast {
  position: absolute; left: 50%; top: 26%; transform: translate(-50%, -8px);
  z-index: 28; background: rgba(41,224,122,0.16); border: 1px solid rgba(41,224,122,.5);
  color: var(--green); padding: 14px 22px; border-radius: 14px; text-align: center;
  font-weight: 700; font-size: 17px; opacity: 0; pointer-events: none;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); transition: opacity .35s, transform .35s;
}
.flash-toast.show { opacity: 1; transform: translate(-50%, 0); }
.flash-toast small { display:block; font-weight:400; font-size:13px; color: var(--text); opacity:.85; margin-top:3px; }

/* маленький флаг «Сигнал обновлён» */
.update-flag {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 24; background: rgba(47,123,255,.16); border: 1px solid rgba(47,123,255,.45);
  color: #bcd3ff; padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
.update-flag.show { opacity: 1; }

/* плашка тревоги */
.alarm-banner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 27;
  background: var(--red); color: #fff; text-align: center;
  padding: 12px 16px; font-weight: 800; font-size: 16px; letter-spacing: .5px;
  transform: translateY(-110%); transition: transform .4s;
  box-shadow: 0 6px 24px rgba(255,43,57,.5);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.alarm-banner.show { transform: translateY(0); animation: alarmPulse 1.1s infinite; }
@keyframes alarmPulse { 0%,100%{ background:#ff2b39 } 50%{ background:#c4101c } }
.alarm-banner::before { content: '⚠'; font-size: 20px; }

/* лёгкая встряска интерфейса при обнаружении сигнала */
@keyframes shake {
  0%,100%{transform:translateX(0)} 20%{transform:translateX(-4px)}
  40%{transform:translateX(4px)} 60%{transform:translateX(-3px)} 80%{transform:translateX(3px)}
}
#app.shake { animation: shake .4s; }

/* лейблы зон на фейк-карте */
.zone-label { fill: rgba(255,255,255,0.5); font-size: 4.2px; font-weight: 600; font-family: var(--font); letter-spacing: .3px; }
