:root {
  --bg-color: #0d1117;
  --panel-bg: #161b22;
  --border-color: #30363d;
  --accent-color: #58a6ff;
  --accent-glow: rgba(88, 166, 255, 0.2);
  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --danger-color: #f85149;
  --success-color: #2ea043;
  --warning-color: #d29922;
  --tg-safe-bottom: env(safe-area-inset-bottom, 16px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
}

/* Верхній хедер */
.header {
  height: 52px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-badge {
  background: linear-gradient(135deg, #00d2ff, #3a7bd5);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.4);
}

.logo-title {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.5px;
}

.logo-title span {
  color: #00d2ff;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  background: #161b22;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success-color);
  box-shadow: 0 0 6px var(--success-color);
  transition: background-color 0.3s, box-shadow 0.3s;
}

.status-dot.offline {
  background-color: var(--danger-color);
  box-shadow: 0 0 6px var(--danger-color);
}

/* Постійний банер-попередження про маячок */
.beacon-warning-banner {
  background: #251318;
  border-bottom: 1px solid rgba(248, 81, 73, 0.4);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1001;
}

.beacon-warning-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.beacon-warning-content {
  flex: 1;
}

.beacon-warning-title {
  font-size: 13px;
  font-weight: 700;
  color: #ff7b72;
}

.beacon-warning-sub {
  font-size: 11px;
  color: #c9d1d9;
  line-height: 1.2;
}

.beacon-warning-btn {
  background: #da3633;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

/* Контейнери вкладок */
.tab-content {
  flex: 1;
  position: relative;
  display: none;
  height: calc(100vh - 52px - 64px);
}

.tab-content.active {
  display: block;
}

/* Карта Leaflet */
#map {
  width: 100%;
  height: 100%;
  background: #0d1117;
  z-index: 1;
}

/* Нижня панель навігації */
.nav-bar {
  height: calc(64px + var(--tg-safe-bottom));
  padding-bottom: var(--tg-safe-bottom);
  background: var(--panel-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  flex: 1;
  height: 100%;
  transition: all 0.2s ease;
}

.nav-item.active {
  color: #00d2ff;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

/* Плаваючі кнопки карти */
.map-actions {
  position: absolute;
  right: 14px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 500;
}

.map-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  transition: transform 0.15s, background 0.15s;
}

.map-btn:active {
  transform: scale(0.92);
}

.map-btn.primary {
  background: linear-gradient(135deg, #00d2ff, #0072ff);
  color: #fff;
  border: none;
  font-size: 24px;
  box-shadow: 0 4px 16px rgba(0, 210, 255, 0.4);
}

.map-btn.sos {
  background: linear-gradient(135deg, #ff416c, #ff4b2b);
  color: #fff;
  border: none;
  font-weight: bold;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(255, 65, 108, 0.4);
}

/* Верхній фільтр категорій на карті */
.category-filter-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  z-index: 500;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.category-filter-bar::-webkit-scrollbar {
  display: none;
}

.cat-pill {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.cat-pill.active {
  background: #238636;
  border-color: #2ea043;
  color: #fff;
}

/* Mapbox GL JS Fixes */
.mapboxgl-map {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}


/* Кастомний маркер кур'єра */
.courier-marker {
  position: relative;
  width: 20px;
  height: 20px;
}

.courier-pin {
  width: 16px;
  height: 16px;
  background: #00d2ff;
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 10px #00d2ff;
}

.courier-pulse {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 210, 255, 0.3);
}

/* Маркери подій на карті */
.event-map-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #161b22;
  border: 2px solid #58a6ff;
  box-shadow: 0 3px 8px rgba(0,0,0,0.5);
  font-size: 18px;
}

.event-map-icon.sos {
  border-color: #ff4b2b;
  background: #2d1015;
  box-shadow: 0 0 12px rgba(255, 75, 43, 0.7);
}


/* Bottom Sheet для деталей або створення */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #161b22;
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border-color);
  padding: 16px 20px calc(24px + var(--tg-safe-bottom));
  z-index: 2000;
  transform: translateY(105%);
  transition: transform 0.25s cubic-bezier(0.1, 0.9, 0.2, 1);
  box-shadow: 0 -8px 24px rgba(0,0,0,0.6);
}

.bottom-sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: #30363d;
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-address {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sheet-body {
  font-size: 15px;
  line-height: 1.4;
  margin-bottom: 16px;
  color: #c9d1d9;
}

.sheet-btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s;
}

.btn:active {
  opacity: 0.8;
}

.btn-primary {
  background: #238636;
  color: #fff;
}

.btn-secondary {
  background: #21262d;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-danger {
  background: #da3633;
  color: #fff;
}

/* Форми та інпути */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-control {
  width: 100%;
  background: #0d1117;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-main);
  font-size: 15px;
  outline: none;
}

.form-control:focus {
  border-color: var(--accent-color);
}

/* Кабінет кур'єра */
.profile-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 16px;
}

.profile-card {
  background: #161b22;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.avatar-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1f6feb, #238636);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.profile-names h3 {
  font-size: 17px;
  font-weight: 700;
}

.profile-names p {
  font-size: 13px;
  color: var(--text-muted);
}

.badge-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(88, 166, 255, 0.15);
  color: #58a6ff;
  margin-top: 4px;
}

/* Чекбокси підписок на події */
.cat-checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.cat-check-item {
  background: #0d1117;
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 13px;
}

.cat-check-item.selected {
  border-color: #2ea043;
  background: rgba(46, 160, 67, 0.1);
}

.toggle-switch {
  width: 42px;
  height: 24px;
  background: #30363d;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-switch.on {
  background: #2ea043;
}

.toggle-thumb {
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.toggle-switch.on .toggle-thumb {
  transform: translateX(18px);
}

/* Індикатор завантаження */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 9999;
  transition: opacity 0.3s;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(88, 166, 255, 0.2);
  border-top-color: #00d2ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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