/* ============================================================
   Evacuator Dashboard — Premium Dark Theme
   ============================================================ */

:root {
  /* Colors */
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2035;
  --bg-card: #151c2e;
  --bg-card-hover: #1d2640;
  --bg-glass: rgba(17, 24, 39, 0.85);

  --text-primary: #f0f4ff;
  --text-secondary: #94a3c0;
  --text-muted: #5b6b8a;

  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --accent-light: #60a5fa;
  --accent-dark: #2563eb;

  --green: #10b981;
  --green-glow: rgba(16, 185, 129, 0.25);
  --yellow: #f59e0b;
  --yellow-glow: rgba(245, 158, 11, 0.25);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.25);
  --orange: #f97316;

  --border: rgba(255, 255, 255, 0.06);
  --border-active: rgba(59, 130, 246, 0.4);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8f9fb;
  --bg-card: #ffffff;
  --bg-card-hover: #f3f6fa;
  --bg-glass: rgba(255, 255, 255, 0.9);

  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;

  --border: rgba(0, 0, 0, 0.08);
  --border-active: rgba(59, 130, 246, 0.5);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.15);
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Header
   ============================================================ */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 64px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 100;
  position: relative;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.logo-icon svg {
  width: 22px;
  height: 22px;
  color: white;
}

.logo-text h1 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent-light), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* APK Download Button */
.apk-download {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 42px;
  height: 42px;
  margin-left: 10px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #3DDC84, #2BA560);
  color: white;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(61, 220, 132, 0.25);
}

.apk-download:hover {
  transform: scale(1.12);
  box-shadow: 0 4px 20px rgba(61, 220, 132, 0.45);
}

.apk-download .apk-icon {
  transition: transform 0.3s ease;
}

.apk-download:hover .apk-icon {
  transform: translateY(-3px);
}

.apk-download .apk-arrow {
  position: absolute;
  bottom: 3px;
  right: 3px;
  color: rgba(255,255,255,0.85);
  animation: none;
}

.apk-download:hover .apk-arrow {
  animation: apk-bounce 0.6s ease infinite;
}

@keyframes apk-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

/* Stats Bar */
.header-center {
  display: flex;
  align-items: center;
}

.stats-bar {
  display: flex;
  gap: 24px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

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

.stat-dot.online {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
  animation: pulse-green 2s infinite;
}

.stat-dot.busy {
  background: var(--yellow);
  box-shadow: 0 0 8px var(--yellow-glow);
}

.stat-dot.offline {
  background: var(--text-muted);
}

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

.stat-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

/* Header Right */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.connection-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--yellow);
  transition: var(--transition);
}

.connection-status.connected .status-dot {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
}

.connection-status.disconnected .status-dot {
  background: var(--red);
  box-shadow: 0 0 8px var(--red-glow);
}

/* ============================================================
   Main Content
   ============================================================ */
#main-content {
  display: flex;
  height: calc(100vh - 64px);
}

/* ============================================================
   Sidebar
   ============================================================ */
#sidebar {
  width: 420px;
  min-width: 420px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: -0.3px;
}

.sidebar-controls {
  display: flex;
  gap: 8px;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 36px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

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

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}

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

.filter-select {
  height: 36px;
  padding: 0 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

.filter-select:focus {
  border-color: var(--accent);
}

/* Truck List */
.truck-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.truck-list::-webkit-scrollbar {
  width: 6px;
}

.truck-list::-webkit-scrollbar-track {
  background: transparent;
}

.truck-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.truck-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.empty-state span {
  font-size: 12px;
}

/* Truck Card */
.truck-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.truck-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 3px 0 0 3px;
  transition: var(--transition);
}

.truck-card.status-free::before { background: var(--green); }
.truck-card.status-busy::before { background: var(--yellow); }
.truck-card.status-offline::before { background: var(--text-muted); }

.truck-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
  transform: translateX(2px);
  box-shadow: var(--shadow-md);
}

.truck-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.truck-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.truck-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.truck-status {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.truck-status.free {
  background: var(--green-glow);
  color: var(--green);
}

.truck-status.busy {
  background: var(--yellow-glow);
  color: var(--yellow);
}

.truck-status.offline {
  background: rgba(107, 114, 128, 0.15);
  color: var(--text-muted);
}

.truck-card-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.truck-info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.truck-info-row svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.truck-phone-link {
  color: var(--accent-light);
  text-decoration: none;
  font-weight: 600;
  transition: var(--transition);
}

.truck-phone-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.truck-address {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}

.truck-time {
  font-size: 11px;
  color: var(--text-muted);
}

.truck-card-actions {
  display: flex;
  gap: 6px;
}

.btn-sm {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: var(--transition);
}

.btn-call {
  background: linear-gradient(135deg, var(--green), #059669);
  color: white;
  border-color: transparent;
}

.btn-call:hover {
  box-shadow: 0 0 16px var(--green-glow);
  transform: translateY(-1px);
}

.btn-callback {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.btn-callback:hover {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

.btn-order {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.btn-order:hover {
  background: var(--orange);
  color: white;
  border-color: transparent;
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

/* ============================================================
   Map
   ============================================================ */
#map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* Leaflet custom markers */
.custom-marker {
  position: relative;
}

.marker-pin {
  background: var(--accent);
  padding: 6px 10px;
  border-radius: 20px;
  color: white;
  font-weight: 700;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  border: 2px solid rgba(255,255,255,0.3);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
  cursor: pointer;
  position: relative;
}

.marker-pin::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--accent);
}

.marker-pin.free {
  background: linear-gradient(135deg, #10b981, #059669);
}

.marker-pin.free::after {
  border-top-color: #059669;
}

.marker-pin.busy {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.marker-pin.busy::after {
  border-top-color: #d97706;
}

.marker-pin.offline {
  background: linear-gradient(135deg, #6b7280, #4b5563);
}

.marker-pin.offline::after {
  border-top-color: #4b5563;
}

.marker-pin:hover {
  transform: scale(1.08);
  z-index: 1000 !important;
}

.marker-icon {
  width: 16px;
  height: 16px;
}

.marker-pulse {
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: marker-pulse 2s infinite;
}

.marker-pin.free + .marker-pulse { background: var(--green); }
.marker-pin.busy + .marker-pulse { background: var(--yellow); }

/* Map overlay buttons */
.map-overlay-top {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-md);
}

.map-btn:hover {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

/* ============================================================
   Modals
   ============================================================ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fade-in 0.2s ease;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--red);
  color: white;
}

.modal-body {
  padding: 20px 24px;
}

.modal-truck-info {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
}

.btn-primary:hover {
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* ============================================================
   Toast
   ============================================================ */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 360px;
}

.toast.success {
  border-left: 3px solid var(--green);
}

.toast.error {
  border-left: 3px solid var(--red);
}

.toast.info {
  border-left: 3px solid var(--accent);
}

.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes marker-pulse {
  0% { transform: translateX(-50%) scale(1); opacity: 0.4; }
  50% { transform: translateX(-50%) scale(2); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes truck-card-in {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes blink-border {
  0%, 100% { border-color: var(--accent); }
  50% { border-color: transparent; }
}

/* Leaflet overrides */
.leaflet-control-attribution {
  background: var(--bg-glass) !important;
  backdrop-filter: blur(8px);
  color: var(--text-muted) !important;
  font-size: 10px !important;
  border-radius: var(--radius-sm) !important;
  padding: 2px 8px !important;
}

.leaflet-control-attribution a {
  color: var(--accent-light) !important;
}

.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--bg-glass) !important;
  backdrop-filter: blur(8px);
  color: var(--text-primary) !important;
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--accent) !important;
  color: white !important;
}

.leaflet-tile-pane {
  filter: brightness(0.85) contrast(1.1) saturate(0.8);
}

[data-theme="light"] .leaflet-tile-pane {
  filter: none;
}

/* ============================================================
   Mobile Responsive
   ============================================================ */
@media (max-width: 768px) {
  html, body {
    overflow: auto;
    height: auto;
  }

  #main-content {
    flex-direction: column;
    height: auto;
  }

  #sidebar {
    width: 100%;
    min-width: 100%;
    max-height: none;
    order: 2;
  }

  .truck-list {
    overflow-y: visible;
  }

  #map-container {
    order: 1;
    flex: none;
    display: block;
    width: 100%;
    height: 45vh;
    min-height: 350px;
    position: relative;
    z-index: 5;
  }

  .stats-bar {
    display: none;
  }

  .logo-subtitle {
    display: none;
  }

  #header {
    padding: 0 12px;
    height: 54px;
  }

  .sidebar-header h2 {
    font-size: 13px;
  }

  .truck-card-actions {
    flex-wrap: wrap;
  }

  .btn-sm {
    font-size: 11px;
    padding: 6px 8px;
  }

  .modal {
    margin: 16px;
    max-width: calc(100% - 32px);
  }
}

@media (max-width: 480px) {
  .header-right {
    gap: 4px;
  }

  .connection-status span {
    display: none;
  }

  .truck-address {
    max-width: 180px;
  }
}

/* Высветляем темную карту (CartoDB Dark), чтобы дороги были отлично видны */
[data-theme="dark"] .leaflet-tile-pane {
  filter: brightness(1.7) contrast(1.3) saturate(1.2);
}
