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

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: var(--app-h, 100vh);
  overflow: hidden;
}

/* ===== HEADER ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg);
  flex-shrink: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.3px;
  color: var(--text);
}

.logo span {
  color: var(--accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== SENSOR PILLS ===== */
.sensor-status {
  display: flex;
  gap: 10px;
}

.sensor-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  background: rgba(110, 115, 133, 0.15);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.sensor-pill.connected {
  background: rgba(52, 211, 153, 0.1);
  color: var(--success);
}

.sensor-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: background 0.2s;
}

.sensor-pill.connected .dot {
  background: var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== THEME TOGGLE ===== */
.theme-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  flex-direction: column;
  height: var(--app-h, 100vh);
  overflow: hidden;
  padding-bottom: 52px; /* espaço para tab-bar fixa */
}
.screen.active { display: flex; }
#screen-ride { padding-bottom: 0; } /* tela de treino não tem tab-bar */

/* Telas com conteúdo rolável */
.route-screen,
.summary-screen,
.config-screen {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== MAP SECTION ===== */
.map-section {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  z-index: 1;
}

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

.map-overlay-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.map-badge {
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  pointer-events: auto;
  border: 1px solid var(--border);
}

.map-badge .value {
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

.route-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--text-dim);
  z-index: 1000;
}

.route-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-secondary));
  border-radius: 0 2px 2px 0;
  transition: width 1s ease;
}

/* ===== DATA PANEL ===== */
.data-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 12px;
  gap: 12px;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

.data-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20px;
  right: 20px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.3;
}

/* ===== HERO METRICS ===== */
.hero-row {
  display: flex;
  gap: 12px;
  flex: 1;
}

.hero-metric {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.hero-metric::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  opacity: 0.8;
}

.hero-metric .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -1px;
}

.hero-metric .label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hero-metric .sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ===== SECONDARY METRICS ===== */
.secondary-row {
  display: flex;
  gap: 8px;
}

.secondary-metric {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.secondary-metric .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.secondary-metric .label {
  font-size: 9px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* ===== CONTROLS ===== */
.controls {
  display: flex;
  gap: 10px;
  padding-top: 4px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 24px var(--accent-glow);
}

.btn-primary:active {
  transform: scale(0.97);
  filter: brightness(0.9);
}

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

.btn-secondary:active {
  background: var(--bg-card);
}

.btn-stop {
  flex: 0 0 52px;
  background: var(--bg-card-elevated);
  color: #ef4444;
  font-size: 18px;
  border: 1px solid rgba(239, 68, 68, 0.15);
}

/* ===== ROUTE SCREEN ===== */
.route-screen {
  padding: 0 20px 20px;
  flex: 1;
  overflow-y: auto;
}

.route-screen h2 {
  font-size: 22px;
  font-weight: 700;
  margin: 20px 0 16px;
  letter-spacing: -0.5px;
}

.route-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
}

.route-card:active {
  transform: scale(0.98);
  border-color: var(--accent);
}

.route-card .route-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 6px;
}

.route-card .route-info {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}

.route-card .route-info span {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}

.upload-area {
  border: 2px dashed var(--text-dim);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

.upload-area:active {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.upload-area .icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.upload-area .text {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===== SUMMARY SCREEN ===== */
.summary-screen {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.summary-screen h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.summary-screen .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 24px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.summary-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  border: 1px solid var(--border);
}

.summary-item .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.summary-item .value.highlight {
  color: var(--accent);
}

.summary-item .label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 6px;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

/* ===== CONFIG SCREEN ===== */
.config-screen {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.config-screen h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
}

.config-field {
  margin-bottom: 20px;
}

.config-field label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.config-field input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.config-field input:focus {
  border-color: var(--accent);
}

/* ===== TAB BAR ===== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 6px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 9999;
}

.tab-item {
  flex: 1;
  text-align: center;
  padding: 6px 0;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-family: 'DM Sans', sans-serif;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: color 0.2s;
}

.tab-item.active {
  color: var(--accent);
}

.tab-item .tab-icon {
  font-size: 18px;
  display: block;
  margin-bottom: 2px;
}

/* ===== NAV BOTTOM ===== */
.nav-bottom {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

/* ===== PAUSED INDICATOR ===== */
.paused .hero-metric .value {
  animation: blink 1s ease infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== STATUS INDICATOR ===== */
.sync-status {
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 8px;
  text-align: center;
}

/* ===== LEAFLET OVERRIDES ===== */
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
  font-size: 8px !important;
  background: rgba(15,17,23,0.7) !important;
  color: var(--text-dim) !important;
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }
