:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #10b981;
  --danger: #ef4444;
  --border: #e2e8f0;
  --border-dark: #334155;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-surface);
}

.hidden {
  display: none !important;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-inverse);
  z-index: 9999;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Authentication Screen */
.auth-container {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, #1e293b, #0f172a);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-icon {
  font-size: 42px;
  display: inline-block;
  margin-bottom: 8px;
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

.auth-notice {
  margin: 24px 0;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-primary);
}

.email-badge {
  font-weight: 600;
  color: var(--primary);
  margin-top: 4px;
  word-break: break-all;
}

.g-btn-wrapper {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  min-height: 44px;
}

.error-msg {
  margin-top: 16px;
  padding: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* Authenticated Main App */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

/* Top App Header */
.app-header {
  height: 60px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 500;
  color: var(--text-inverse);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text-inverse);
  margin-right: 8px;
}

.date-selector-group {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 8px;
  border-radius: var(--radius-md);
}

.date-input {
  background: transparent;
  border: none;
  color: var(--text-inverse);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  color-scheme: dark;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-inverse);
  font-size: 18px;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-pill {
  background: var(--primary);
  border: none;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-pill:hover {
  background: var(--primary-hover);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.status-live {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 1.5s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.btn-icon-label {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-inverse);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-icon-label:hover {
  background: rgba(255, 255, 255, 0.15);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 1px solid var(--border-dark);
  padding-left: 12px;
}

.user-email {
  font-size: 13px;
  color: #94a3b8;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-text {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
}

.btn-text:hover {
  color: var(--text-inverse);
}

/* Map Canvas Container */
#map-container {
  position: relative;
  flex: 1;
  width: 100%;
  height: calc(100% - 60px);
}

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

/* Floating Telemetry Card */
.telemetry-card {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-lg);
  padding: 12px 24px;
  color: #fff;
  z-index: 600;
  box-shadow: var(--shadow-lg);
  min-width: 320px;
  max-width: 90vw;
}

.telemetry-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 20px;
}

.telemetry-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.telemetry-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
}

.telemetry-val {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  margin-top: 2px;
}

/* Empty State */
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  padding: 24px 32px;
  border-radius: var(--radius-lg);
  color: #fff;
  text-align: center;
  z-index: 600;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
}

.empty-state p {
  font-size: 16px;
  font-weight: 600;
}

.empty-state small {
  display: block;
  margin-top: 6px;
  color: #94a3b8;
  font-size: 13px;
}

/* Modal Drawer (Settings) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

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

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

.btn-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.time-range-inputs {
  display: flex;
  align-items: center;
  gap: 12px;
}

.time-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.time-field input, .form-group select, .form-group input[type="text"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
}

.time-sep {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 14px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.form-group-toggle label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.otrc-section {
  padding: 14px;
  background: #f8fafc;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.otrc-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.otrc-section p {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.btn-secondary {
  display: inline-block;
  padding: 8px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-secondary:hover {
  background: #f1f5f9;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}

.btn-primary {
  padding: 9px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

/* Pulsing Custom Marker on Map */
.pulse-marker-icon {
  position: relative;
  width: 24px;
  height: 24px;
}

.pulse-marker-center {
  width: 14px;
  height: 14px;
  background: #ef4444;
  border: 2.5px solid #fff;
  border-radius: 50%;
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 2;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.pulse-marker-ring {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.4);
  position: absolute;
  top: -2px;
  left: -2px;
  animation: pulse-ring 2s infinite;
  z-index: 1;
}

@keyframes pulse-ring {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .app-header {
    height: auto;
    padding: 10px 12px;
    flex-direction: column;
    gap: 8px;
  }
  .header-left, .header-right {
    width: 100%;
    justify-content: space-between;
  }
  .brand-name {
    display: none;
  }
  .telemetry-card {
    bottom: 16px;
    padding: 10px 16px;
    min-width: 90vw;
  }
  .telemetry-row {
    gap: 10px;
  }
  .telemetry-val {
    font-size: 13px;
  }
  .user-email {
    display: none;
  }
}
