:root {
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-text: #ffffff;
  --accent: #10b981;
  --accent-light: #ecfdf5;
  --accent-text: #065f46;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px -1px rgb(0 0 0 / 0.05);
  --chip-bg: #f1f5f9;
  --chip-hover: #e2e8f0;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --border: #334155;
    --border-focus: #60a5fa;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #1e3a8a;
    --primary-text: #ffffff;
    --accent: #10b981;
    --accent-light: #064e3b;
    --accent-text: #a7f3d0;
    --danger: #f87171;
    --danger-light: #450a0a;
    --warning: #fbbf24;
    --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.35), 0 2px 4px -2px rgb(0 0 0 / 0.25);
    --chip-bg: #334155;
    --chip-hover: #475569;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 1rem 0.75rem 3rem;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 580px;
  margin: 0 auto;
}

/* Header & Vehicle Selector */
.app-header {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-icon {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
}

.vehicle-selector-bar {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--card-shadow);
}

.vehicle-select-wrap {
  flex: 1;
}

.vehicle-select-wrap select {
  font-weight: 600;
  border-color: transparent;
  background-color: transparent;
  padding: 0.25rem 1.5rem 0.25rem 0.25rem;
  font-size: 1rem;
}

.btn-add-veh {
  background: var(--chip-bg);
  color: var(--primary);
  border: 1px solid var(--border);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

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

/* Nav Tabs */
.nav-tabs {
  display: flex;
  background: var(--chip-bg);
  padding: 0.3rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  gap: 0.3rem;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.925rem;
  font-weight: 600;
  padding: 0.6rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.tab-btn.active {
  background: var(--card-bg);
  color: var(--primary);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.1);
}

/* Card Container */
.form-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

/* Photo Upload Dual Grid */
.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (max-width: 480px) {
  .photo-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.photo-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.5rem;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  overflow: hidden;
}

.photo-box:hover, .photo-box:focus-within {
  border-color: var(--primary);
}

.photo-box.has-image {
  border-style: solid;
  border-color: var(--border);
  padding: 0;
}

.photo-box input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 5;
}

.photo-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  pointer-events: none;
}

.photo-preview-wrap {
  width: 100%;
  height: 140px;
  position: relative;
  pointer-events: none;
}

.photo-preview {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}

.photo-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.75);
  color: white;
  padding: 0.35rem;
  font-size: 0.725rem;
  font-weight: 600;
  backdrop-filter: blur(2px);
  z-index: 2;
}

.photo-icon {
  font-size: 1.8rem;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
}

.photo-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.photo-subtitle {
  font-size: 0.725rem;
  color: var(--text-muted);
}

/* AI Action Button */
.btn-ai-extract {
  width: 100%;
  padding: 0.75rem;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: opacity 0.15s ease, transform 0.05s ease;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.btn-ai-extract:hover:not(:disabled) {
  opacity: 0.95;
}

.btn-ai-extract:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* AI Extraction Status Banner */
.extraction-alert {
  display: none;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  align-items: center;
  gap: 0.5rem;
}

.extraction-alert.active {
  display: flex;
}

.extraction-alert.success {
  background: var(--accent-light);
  color: var(--accent-text);
  border: 1px solid var(--accent);
}

.extraction-alert.warning {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* Form Groups & Inputs */
.form-group {
  margin-bottom: 1rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

label.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.field-tag {
  font-size: 0.7rem;
  font-weight: normal;
  color: var(--text-muted);
}

.field-ai-tag {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

input[type="text"],
input[type="number"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Location Badge & Button */
.location-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.location-status {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--chip-bg);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-loc-refresh {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
}

/* Live Efficiency Metric Preview */
.efficiency-preview {
  display: none;
  margin-top: 1rem;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  color: var(--accent-text);
}

.efficiency-preview.active {
  display: block;
}

.eff-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.eff-value {
  font-size: 1.4rem;
  font-weight: 800;
}

.eff-sub {
  font-size: 0.825rem;
  opacity: 0.9;
}

/* Submit Bar */
.submit-container {
  margin-top: 1.5rem;
}

.btn-submit {
  width: 100%;
  padding: 0.95rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-text);
  background: var(--primary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(37, 99, 235, 0.3);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

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

.btn-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Stats Overview Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  box-shadow: var(--card-shadow);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

.stat-num {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
}

.stat-unit {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 0.2rem;
}

/* Entry History List */
.entry-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.9rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--card-shadow);
}

.entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.entry-date {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-muted);
}

.entry-eff-badge {
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--accent-light);
  color: var(--accent-text);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--accent);
}

.entry-metrics {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
}

.metric-val {
  font-weight: 700;
  color: var(--text);
}

.entry-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px dashed var(--border);
  padding-top: 0.45rem;
  margin-top: 0.45rem;
}

.btn-delete-entry {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 0.4rem;
}

/* Modal for Adding Vehicle */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

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

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

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

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

.btn-secondary {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

