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

:root {
  --bg: #14171c;
  --panel: #1e232b;
  --panel-2: #262c36;
  --border: #333b48;
  --text: #e8ebf0;
  --text-dim: #8a93a3;
  --accent: #4c8dff;
  --new-marker: #ff9f2e;
  --done-marker: #3ecf6e;
  --danger: #e5484d;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- Вход ---------- */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
  padding: 16px;
}
.login-box {
  width: 100%; max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  display: flex; flex-direction: column; gap: 12px;
  text-align: center;
}
.login-box h1 { font-size: 28px; }
.login-sub { color: var(--text-dim); margin-bottom: 8px; }
.login-box input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button {
  padding: 12px;
  border: none; border-radius: 10px;
  background: var(--accent); color: #fff;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.login-error { color: var(--danger); font-size: 14px; min-height: 18px; }

/* ---------- Каркас ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  gap: 4px;
  min-height: 48px;
}
.tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 4px;
  flex: 0 1 auto;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border-radius: 10px 10px 0 0;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
  border: none; background: none;
  user-select: none;
}
.tab.active {
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
}
.tab .tab-gear {
  border: none; background: none; color: var(--text-dim);
  cursor: pointer; font-size: 13px; padding: 2px;
}
.tab-add {
  border: none; background: none; color: var(--text-dim);
  font-size: 20px; cursor: pointer; padding: 4px 10px;
  flex-shrink: 0;
}
.tab-add:hover { color: var(--text); }
.topbar-right {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
  padding-left: 8px;
}
.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  display: inline-block;
}
.conn-dot.online { background: var(--done-marker); }
.user-name { font-size: 13px; color: var(--text-dim); max-width: 120px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Карта ---------- */
.viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(circle at 30% 30%, #1a1f27 0%, var(--bg) 70%);
}
.viewport.add-mode { cursor: crosshair; }

.world {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
}
.map-image {
  display: block;
  user-select: none;
  pointer-events: none;
}
.marker-layer { position: absolute; inset: 0; }

/* ---------- Метки ---------- */
.marker {
  position: absolute;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  color: #fff;
  cursor: pointer;
  border: 2.5px solid rgba(255,255,255,.9);
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  user-select: none;
}
.marker.new {
  background: var(--new-marker);
  animation: pulse 1.6s infinite;
}
.marker.done {
  background: var(--done-marker);
  opacity: .85;
}
.marker.moving {
  outline: 3px dashed var(--accent);
  outline-offset: 3px;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255,159,46,.55), 0 2px 8px rgba(0,0,0,.5); }
  70%  { box-shadow: 0 0 0 14px rgba(255,159,46,0), 0 2px 8px rgba(0,0,0,.5); }
  100% { box-shadow: 0 0 0 0 rgba(255,159,46,0), 0 2px 8px rgba(0,0,0,.5); }
}

/* ---------- Пустое состояние ---------- */
.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
  color: var(--text-dim);
  text-align: center;
  padding: 24px;
}

/* ---------- Управление картой ---------- */
.map-controls {
  position: absolute;
  right: 12px; top: 12px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 5;
}
.map-controls-left {
  position: absolute;
  left: 12px; top: 12px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 6;
}
.map-controls button,
.map-controls-left button {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

/* ---------- Тултипы при наведении ---------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: 50%; left: calc(100% + 8px);
  transform: translateY(-50%);
  white-space: nowrap;
  background: #0b0e13;
  color: #e8ebf0;
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.2;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease .35s;
  z-index: 40;
  box-shadow: 0 3px 12px rgba(0,0,0,.5);
}
[data-tip]:hover::after { opacity: 1; }
/* тултип слева от элемента */
[data-tip-side="left"]::after {
  left: auto; right: calc(100% + 8px);
}
/* тултип снизу (для верхней панели) */
[data-tip-side="bottom"]::after {
  top: calc(100% + 8px); left: 50%;
  transform: translateX(-50%);
}
/* на узких экранах тултипы мешают — прячем на тач-устройствах */
@media (hover: none) {
  [data-tip]::after { display: none; }
}

.fab {
  position: absolute;
  right: 16px; bottom: 20px;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  z-index: 5;
}
.fab.active {
  background: var(--new-marker);
  transform: scale(1.08);
}

.mode-banner {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 6;
  max-width: calc(100% - 130px);
  text-align: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}

/* ---------- Карточка метки ---------- */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: flex; justify-content: center;
}
.sheet-content {
  width: 100%; max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 16px 20px 24px;
  box-shadow: 0 -6px 24px rgba(0,0,0,.5);
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.seq-badge {
  font-size: 13px; font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--new-marker);
  color: #201400;
}
.seq-badge.done { background: var(--done-marker); color: #00230e; }
.sheet-close {
  border: none; background: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 4px;
}
.marker-code {
  font-size: 22px; font-weight: 700;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  word-break: break-all;
  margin-bottom: 4px;
}
.marker-meta { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }
.seq-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.seq-row label { font-size: 14px; color: var(--text-dim); }
.seq-row input {
  width: 80px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
}
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Кнопки и модалки ---------- */
.btn {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
  padding: 16px;
}
.modal-box {
  width: 100%; max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-box h3 { font-size: 17px; }
.modal-box input {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
}
.modal-box input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.level-menu-actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Онлайн-карта (Leaflet) ---------- */
.geo-map {
  position: absolute; inset: 0;
  z-index: 1;
  background: #10141a;
}
.geo-map .leaflet-container { background: #10141a; }

/* метка внутри leaflet divIcon — без абсолютного позиционирования */
.marker.on-map {
  position: relative;
  width: 34px; height: 34px;
}

.fab-secondary {
  bottom: 92px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

/* гео участников */
.geo-wrap { background: none; border: none; }
.geo-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #2f7bff;
  border: 2.5px solid #fff;
  box-shadow: 0 0 8px rgba(0,0,0,.45);
}
.geo-dot.me { background: #9b59ff; }
.geo-name {
  position: absolute;
  top: 17px; left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 11px; font-weight: 600;
  color: #1a2230;
  background: rgba(255,255,255,.85);
  padding: 1px 5px;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}

/* свитч передачи гео */
.geo-switch {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
  user-select: none;
}
.geo-switch-label {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}
.geo-switch input:checked ~ .switch,
.geo-switch input:checked + .geo-switch-label { }

.switch {
  position: relative;
  display: inline-block;
  width: 40px; height: 22px;
  flex-shrink: 0;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: #3a4250;
  border-radius: 22px;
  transition: background .18s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .18s;
}
.switch input:checked + .slider { background: var(--done-marker); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* на узких экранах прячем текст, оставляем сам переключатель */
@media (max-width: 560px) {
  .geo-switch-label { display: none; }
}

/* поиск по адресу */
.search-bar {
  position: absolute;
  top: 12px; left: 60px;
  width: min(340px, calc(100% - 90px));
  z-index: 8;
}
.search-bar input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.search-bar input:focus { outline: none; border-color: var(--accent); }
.search-results {
  margin-top: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  max-height: 40vh;
  overflow-y: auto;
}
.search-results:empty { display: none; }
.search-result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--panel-2); }

/* рисование зон */
.zone-toolbar {
  position: absolute;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  z-index: 7;
  box-shadow: 0 4px 16px rgba(0,0,0,.45);
  font-size: 14px;
  white-space: nowrap;
}

/* подпись зоны на карте */
.zone-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  text-shadow: 0 1px 4px rgba(0,0,0,.9), 0 0 10px rgba(0,0,0,.6);
}
.zone-label::before { display: none; }

/* выбор цвета зоны */
.zone-colors { display: flex; gap: 8px; flex-wrap: wrap; }
.zone-color {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.zone-color.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

/* фото в карточке метки */
.marker-photo {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

/* ==================== Голосовой чат ==================== */
.voice-btn {
  display: flex; align-items: center; gap: 4px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 14px;
  cursor: pointer;
}
.voice-btn.active {
  border-color: var(--done-marker);
  box-shadow: 0 0 6px rgba(62,207,110,.35);
}
.voice-count {
  font-size: 12px;
  min-width: 16px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  text-align: center;
}

/* панель войсчата */
.voice-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(340px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--border);
  z-index: 55;
  display: flex;
  box-shadow: -6px 0 24px rgba(0,0,0,.5);
}
.voice-panel-inner {
  flex: 1;
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
.voice-header {
  display: flex; align-items: center; justify-content: space-between;
}
.voice-header h3 { font-size: 17px; }

.voice-roster {
  display: flex; flex-direction: column; gap: 6px;
  min-height: 40px;
}
.voice-empty { color: var(--text-dim); font-size: 14px; padding: 8px 0; }
.voice-peer {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid transparent;
}
.voice-peer.speaking {
  border-color: var(--done-marker);
  box-shadow: 0 0 8px rgba(62,207,110,.3);
}
.voice-peer-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.voice-peer.speaking .voice-peer-dot {
  background: var(--done-marker);
  animation: vpulse 1s infinite;
}
@keyframes vpulse {
  0% { box-shadow: 0 0 0 0 rgba(62,207,110,.5); }
  70% { box-shadow: 0 0 0 7px rgba(62,207,110,0); }
  100% { box-shadow: 0 0 0 0 rgba(62,207,110,0); }
}
.voice-peer-name { flex: 1; font-size: 14px; }
.voice-peer-icon { font-size: 15px; }

.voice-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.voice-controls .btn { flex: 1; }
.voice-live { display: flex; flex-direction: column; gap: 12px; }
.voice-mode { display: flex; flex-direction: column; gap: 6px; }
.voice-mode-label { font-size: 13px; color: var(--text-dim); }
.voice-hint { font-size: 12px; color: var(--text-dim); line-height: 1.35; }

/* сегментированный переключатель режимов */
.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.seg-btn {
  flex: 1;
  padding: 9px;
  border: none;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* плавающая кнопка микрофона — на всех вкладках */
.mic-fab {
  position: absolute;
  left: 16px; bottom: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--done-marker);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  z-index: 6;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  touch-action: none;
  user-select: none;
}
.mic-fab.muted { background: var(--danger); }
.mic-fab.ptt { background: var(--accent); }
.mic-fab.speaking {
  box-shadow: 0 0 0 4px rgba(62,207,110,.4), 0 4px 16px rgba(0,0,0,.4);
  transform: scale(1.06);
}

.voice-peer-conn { font-size: 13px; opacity: .85; }
.voice-peer-conn.bad { opacity: 1; }
