:root {
  --bg-color: #0d1117;
  --card-bg: rgba(22, 27, 34, 0.88);
  --card-border: rgba(255, 255, 255, 0.12);
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-blue: #38bdf8;
  --accent-blue-glow: rgba(56, 189, 248, 0.35);
  --accent-indigo: #6366f1;
  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.35);
  --accent-red: #f43f5e;
  --accent-red-glow: rgba(244, 63, 94, 0.45);
  --accent-amber: #f59e0b;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.25);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  position: fixed;
  display: flex;
  flex-direction: column;
}

/* App Viewport Container */
.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Map Container */
#map {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  background-color: #1e293b;
}

/* Top Floating Search & Status Bar */
.top-bar {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.search-box-wrapper {
  position: relative;
  pointer-events: auto;
}

.search-bar {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  padding: 8px 14px;
  box-shadow: var(--shadow-lg);
  transition: all 0.2s ease;
}

.search-bar:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow), var(--shadow-lg);
}

.search-icon {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  margin-right: 10px;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  outline: none;
  user-select: auto;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.clear-search-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: none;
  align-items: center;
  justify-content: center;
}

.clear-search-btn.visible {
  display: flex;
}

/* Search Autocomplete Suggestions */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  z-index: 30;
}

.search-results.visible {
  display: flex;
}

.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover, .search-result-item:active {
  background: rgba(255, 255, 255, 0.08);
}

.result-icon {
  color: var(--accent-blue);
  flex-shrink: 0;
}

.result-text {
  flex: 1;
  overflow: hidden;
}

.result-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Floating Map Buttons */
.map-floating-controls {
  position: absolute;
  right: 14px;
  top: calc(var(--safe-top) + 72px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.map-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.map-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.15);
}

.map-btn.active {
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

/* Bottom Control Sheet */
.bottom-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--card-bg);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-top: 1px solid var(--card-border);
  border-radius: 28px 28px 0 0;
  padding: 12px 18px calc(var(--safe-bottom) + 16px) 18px;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sheet-handle-bar {
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  margin: 0 auto 4px auto;
}

/* Status Banner / Card */
.status-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.stat-unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  width: fit-content;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.badge-ready {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-blue);
}
.badge-ready .badge-dot {
  background: var(--accent-blue);
}

.badge-armed {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
}
.badge-armed .badge-dot {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse-dot 1.5s infinite;
}

.badge-triggered {
  background: rgba(244, 63, 94, 0.2);
  color: var(--accent-red);
}
.badge-triggered .badge-dot {
  background: var(--accent-red);
  animation: pulse-dot 0.6s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

/* Radius Slider Section */
.radius-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radius-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.radius-display {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-blue);
}

.radius-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}

.radius-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.1s;
}

.radius-slider::-webkit-slider-thumb:active {
  transform: scale(1.2);
}

/* Radius Preset Pills */
.preset-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.preset-chip {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.preset-chip.active {
  background: var(--accent-blue);
  color: #0b0f19;
  border-color: var(--accent-blue);
}

/* Action Controls (Arm/Disarm + Settings) */
.action-row {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.arm-btn {
  flex: 1;
  height: 52px;
  border-radius: var(--radius-lg);
  border: none;
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(14, 165, 233, 0.4);
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
}

.arm-btn:active {
  transform: scale(0.98);
}

.arm-btn.armed {
  background: linear-gradient(135deg, #e11d48, #f43f5e);
  box-shadow: 0 4px 18px var(--accent-red-glow);
}

.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.icon-btn:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.15);
}

/* Quick Settings & Audio Select Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.visible {
  display: flex;
}

.modal-sheet {
  background: #161b22;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 400px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modal-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-enter {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.close-modal-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
}

.sound-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sound-opt-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  padding: 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.sound-opt-btn.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.test-sound-btn {
  height: 44px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.test-sound-btn:active {
  background: rgba(255, 255, 255, 0.18);
}

/* Fullscreen Alarm Trigger Overlay */
.alarm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  background: #f43f5e;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  animation: strobe-alert 0.8s infinite alternate;
}

.alarm-overlay.visible {
  display: flex;
}

@keyframes strobe-alert {
  0% { background: #e11d48; }
  100% { background: #9f1239; }
}

.alarm-icon-pulse {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  animation: siren-bounce 0.6s infinite alternate;
}

@keyframes siren-bounce {
  0% { transform: scale(0.9); }
  100% { transform: scale(1.15); }
}

.alarm-title {
  font-size: 32px;
  font-weight: 900;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.alarm-subtitle {
  font-size: 18px;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 32px;
  max-width: 320px;
}

.dismiss-alarm-btn {
  height: 60px;
  width: 100%;
  max-width: 280px;
  border-radius: var(--radius-xl);
  border: none;
  background: #ffffff;
  color: #e11d48;
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.dismiss-alarm-btn:active {
  transform: scale(0.96);
}

/* Simulation Toolbar (Dev / Testing) */
.sim-toolbar {
  position: absolute;
  top: calc(var(--safe-top) + 64px);
  left: 14px;
  z-index: 20;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.sim-tag {
  font-size: 11px;
  font-weight: 700;
  background: #3b82f6;
  color: #ffffff;
  padding: 2px 6px;
  border-radius: 4px;
}

.sim-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.sim-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

/* Custom Marker Styles */
.custom-user-icon {
  position: relative;
}

.user-beacon-wrapper {
  position: relative;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-beacon-pulse {
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.4);
  animation: beacon-wave 2s infinite;
}

.user-beacon-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #0ea5e9;
  border: 2.5px solid #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  position: relative;
  z-index: 2;
}

.heading-arrow {
  position: absolute;
  top: -6px;
  left: 3px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 7px solid #38bdf8;
  transform-origin: 4px 13px;
}

@keyframes beacon-wave {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(2.2); opacity: 0; }
}

.target-pin-wrapper {
  position: relative;
  width: 36px;
  height: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.target-pin-pulse {
  position: absolute;
  bottom: 0;
  width: 20px;
  height: 8px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.6);
  animation: pin-shadow 1.5s infinite;
}

.target-pin-head {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border: 2px solid #ffffff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  z-index: 2;
}

.target-pin-stem {
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 10px solid #dc2626;
  margin-top: -3px;
  z-index: 1;
}

@keyframes pin-shadow {
  0% { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(2); opacity: 0; }
}

/* Leaflet Geofence SVG style */
.geofence-circle-pulse {
  stroke-dashoffset: 0;
  animation: dash-stroke 20s linear infinite;
}

@keyframes dash-stroke {
  to {
    stroke-dashoffset: 1000;
  }
}

/* Permission & Notice Banner */
.notice-banner {
  background: rgba(245, 158, 11, 0.92);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  color: #0b0f19;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: banner-slide 0.3s ease;
}

.notice-banner.visible {
  display: flex;
}

.notice-banner.error {
  background: rgba(244, 63, 94, 0.95);
  color: #ffffff;
}

.notice-btn {
  background: #0b0f19;
  color: #ffffff;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.notice-banner.error .notice-btn {
  background: #ffffff;
  color: #f43f5e;
}

@keyframes banner-slide {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
