/* MotoRidePulse PWA - Dark motorcycle dashboard theme */

:root {
  --bg-primary: #0a0a0a;
  --bg-card: #16213e;
  --bg-card-border: #1a1a3e;
  --accent: #e94560;
  --text-primary: #e0e0e0;
  --text-secondary: #8892a4;
  --text-muted: #4a5568;
  --color-rpm: #ef4444;
  --color-tps: #f59e0b;
  --color-afr: #3b82f6;
  --color-speed: #4ade80;
  --color-coolant: #f87171;
  --color-ignition: #a78bfa;
  --color-voltage: #facc15;
  --color-connected: #4ade80;
  --color-disconnected: #ef4444;
  --btn-start: #16a34a;
  --btn-stop: #e94560;
  --bar-height: 4px;
  --radius: 12px;
  --nav-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--bg-card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.app-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.device-name {
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

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

.status-dot.disconnected {
  background: var(--color-disconnected);
}

.btn-connect {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  transition: opacity 0.2s;
}

.btn-connect:active {
  opacity: 0.8;
}

/* --- Views --- */
.view {
  padding: 12px;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  min-height: calc(100vh - 56px);
}

.hidden {
  display: none !important;
}

/* --- Gauge Grid --- */
.gauge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.gauge-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gauge-card.full-width {
  grid-column: 1 / -1;
}

.gauge-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.gauge-value {
  font-size: 42px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -1px;
}

.gauge-value.rpm {
  font-size: 56px;
  color: var(--color-rpm);
}

.gauge-value.tps {
  color: var(--color-tps);
}

.gauge-value.afr {
  color: var(--color-afr);
}

.gauge-value.speed {
  color: var(--color-speed);
}

.gauge-value.coolant {
  color: var(--color-coolant);
}

.gauge-value.ignition {
  color: var(--color-ignition);
}

.gauge-value.voltage {
  color: var(--color-voltage);
}

/* --- Progress Bars --- */
.bar-track {
  width: 100%;
  height: var(--bar-height);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.15s ease-out;
  will-change: width;
}

.bar-fill.rpm {
  background: var(--color-rpm);
}

.bar-fill.tps {
  background: var(--color-tps);
}

/* --- AFR indicator dot --- */
.afr-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
  transition: background-color 0.2s;
}

/* --- ECU status banner --- */
.ecu-status {
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-coolant);
  background: rgba(248, 113, 113, 0.1);
  border-radius: 8px;
  margin-top: 10px;
}

/* --- Logging controls --- */
.log-controls {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-log {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  color: #fff;
  transition: background-color 0.2s, transform 0.1s;
}

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

.btn-log.btn-start {
  background: var(--btn-start);
}

.btn-log.btn-stop {
  background: var(--btn-stop);
  animation: pulse-stop 1.5s ease-in-out infinite;
}

@keyframes pulse-stop {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

.log-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--text-secondary);
}

.log-info span {
  font-variant-numeric: tabular-nums;
}

/* --- Rides View --- */
.ride-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.ride-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.ride-date {
  font-size: 14px;
  font-weight: 600;
}

.ride-duration {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.ride-stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.ride-actions {
  display: flex;
  gap: 8px;
}

.btn-small {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 32px;
  transition: opacity 0.2s;
}

.btn-small:active {
  opacity: 0.8;
}

.btn-export {
  background: var(--color-afr);
  color: #fff;
}

.btn-delete {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-rpm);
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 15px;
}

/* --- Settings View --- */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.settings-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}

.setting-row + .setting-row {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.setting-label {
  font-size: 14px;
}

.setting-value {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 48px;
  height: 26px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #374151;
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* --- Bottom Nav --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--bg-card-border);
  display: flex;
  z-index: 100;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s;
  padding: 6px 0;
}

.tab-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

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

/* --- Responsive: 320-480px --- */
@media (max-width: 360px) {
  .gauge-value {
    font-size: 36px;
  }
  .gauge-value.rpm {
    font-size: 48px;
  }
  .gauge-card {
    padding: 10px;
  }
}

/* --- Noscript --- */
.noscript-msg {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.6;
}
