:root {
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --surface-alt: #F8FAFC;
  --dark: #0F172A;
  --dark-2: #1E293B;
  --border: #E2E8F0;
  --text: #0F172A;
  --muted: #64748B;
  --accent: #EA580C;
  --accent-soft: #FFEDD5;
  --amber: #F59E0B;
  --green: #16A34A;
  --green-soft: #DCFCE7;
  --blue: #2563EB;
  --blue-soft: #DBEAFE;
  --red: #DC2626;
  --red-soft: #FEE2E2;
  --purple: #7C3AED;
  --purple-soft: #EDE9FE;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] {
  --bg: #0B1120;
  --surface: #111827;
  --surface-alt: #1E293B;
  --dark: #090E1A;
  --dark-2: #1E293B;
  --border: #2D3748;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --accent-soft: #431407;
  --green-soft: #052E16;
  --blue-soft: #172554;
  --red-soft: #450A0A;
  --purple-soft: #2E1065;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

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

html {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Login */
.login-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--dark) 0%, var(--dark-2) 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.login-logo {
  margin-bottom: 10px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.login-card .muted {
  margin: 0 0 22px;
  font-size: 0.92rem;
}

/* Layout principal */
.main-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.topbar {
  background: var(--dark);
  color: #FFFFFF;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-icon {
  width: 34px;
  height: 34px;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--amber);
  line-height: 1.15;
}

.topbar-sub {
  font-size: 0.78rem;
  color: #CBD5E1;
}

.content-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 24px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

/* Bottom Navigation */
.bottom-nav {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  z-index: 20;
}

.nav-item {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  border-radius: 10px;
  transition: transform 0.1s ease, color 0.15s ease;
}

.nav-item:active {
  transform: scale(0.94);
}

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

.nav-icon {
  font-size: 1.25rem;
  line-height: 1.1;
}

/* Botones e inputs (regla 16px para evitar zoom iOS) */
input, textarea, select {
  font-size: 16px;
  font-family: inherit;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.14);
}

textarea {
  resize: vertical;
  min-height: 76px;
}

button {
  font-family: inherit;
  user-select: none;
  touch-action: manipulation;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 11px;
  padding: 11px 15px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn-sm {
  padding: 8px 11px;
  font-size: 0.84rem;
  border-radius: 9px;
}

.btn-lg {
  padding: 13px 18px;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
}

.btn-dark {
  background: var(--dark);
  color: #FFFFFF;
}

.btn-secondary {
  background: #E2E8F0;
  color: var(--text);
}

.btn-success {
  background: var(--green);
  color: #FFFFFF;
}

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #FFFFFF;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
}

.icon-btn-dark {
  background: #F1F5F9;
  border: none;
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover { opacity: 0.92; }
  .card-clickable:hover { border-color: #CBD5E1; }
}

/* Tarjetas y utilidades */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.card-clickable {
  cursor: pointer;
  transition: transform 0.08s ease;
}

.card-clickable:active {
  transform: scale(0.985);
}

.stack-xs { display: flex; flex-direction: column; gap: 6px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }

.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wrap { flex-wrap: wrap; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.section-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 6px 0 4px;
}

.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.bold { font-weight: 700; }
.error-text { color: var(--red); font-size: 0.9rem; margin: 0; }

/* Stats & Badges */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--dark);
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-presupuesto { background: var(--purple-soft); color: var(--purple); }
.badge-pendiente { background: #FEF3C7; color: #B45309; }
.badge-esperando_piezas { background: var(--accent-soft); color: var(--accent); }
.badge-en_curso { background: var(--blue-soft); color: var(--blue); }
.badge-terminado { background: var(--green-soft); color: var(--green); }
.badge-cobrado { background: #E2E8F0; color: #334155; }
.badge-low { background: var(--red-soft); color: var(--red); }

[data-theme="dark"] .badge-presupuesto { color: #C4B5FD; }
[data-theme="dark"] .badge-pendiente { background: #451A03; color: #FCD34D; }
[data-theme="dark"] .badge-esperando_piezas { color: #FDBA74; }
[data-theme="dark"] .badge-en_curso { color: #93C5FD; }
[data-theme="dark"] .badge-terminado { color: #86EFAC; }
[data-theme="dark"] .badge-cobrado { background: #334155; color: #CBD5E1; }
[data-theme="dark"] .badge-low { color: #FCA5A5; }

[data-theme="dark"] .stat-value { color: var(--text); }
[data-theme="dark"] .btn-dark { background: #334155; color: #F8FAFC; }
[data-theme="dark"] .btn-secondary { background: #1E293B; color: #E2E8F0; border: 1px solid var(--border); }
[data-theme="dark"] .icon-btn-dark { background: #1E293B; color: #F1F5F9; }
[data-theme="dark"] .field > span { color: #CBD5E1; }
[data-theme="dark"] .plate-tag { background: #1E293B; border-color: #64748B; color: #F8FAFC; }
[data-theme="dark"] .chip.active { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
[data-theme="dark"] .photo-thumb { background: #1E293B; }
[data-theme="dark"] .toast { background: #1E293B; border: 1px solid var(--border); }

/* Borde visual por estado en tarjetas de trabajo */
.job-card-presupuesto { border-left: 4px solid var(--purple); }
.job-card-pendiente { border-left: 4px solid var(--amber); }
.job-card-esperando_piezas { border-left: 4px solid var(--accent); }
.job-card-en_curso { border-left: 4px solid var(--blue); }
.job-card-terminado { border-left: 4px solid var(--green); }
.job-card-cobrado { border-left: 4px solid #94A3B8; }

/* Selector rápido de estado por píldoras */
.status-pills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.status-pill-btn {
  border: 1.5px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.status-pill-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

[data-theme="dark"] .status-pill-btn.active {
  color: #FDBA74;
}

.plate-tag {
  display: inline-block;
  background: #F8FAFC;
  border: 1.5px solid #94A3B8;
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--dark);
}

/* Filtros horizontales */
.chips-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.chips-row::-webkit-scrollbar { display: none; }

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.chip.active {
  background: var(--dark);
  color: #FFFFFF;
  border-color: var(--dark);
}

/* Formularios */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
}

.field > span {
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
}

.line-item-row {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Galería de fotos */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #E2E8F0;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-del-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.78);
  color: #FFFFFF;
  font-size: 0.75rem;
  cursor: pointer;
}

/* Modal / Bottom Sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-sheet {
  background: var(--surface);
  width: 100%;
  max-width: 680px;
  max-height: 92dvh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 680px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }
  .modal-sheet {
    border-radius: 18px;
    max-height: 88dvh;
  }
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.modal-body {
  padding: 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox img {
  max-width: 100%;
  max-height: 82dvh;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
  font-size: 1.2rem;
  cursor: pointer;
}

.lightbox-caption {
  color: #E2E8F0;
  margin-top: 10px;
  font-size: 0.9rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--dark);
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 90;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}

/* Línea del tiempo (Historial del coche) */
.timeline {
  position: relative;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
}

.timeline-dot {
  position: absolute;
  left: -20px;
  top: 14px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--border);
}

.timeline-dot.dot-terminado,
.timeline-dot.dot-cobrado { background: var(--green); }
.timeline-dot.dot-en_curso { background: var(--blue); }
.timeline-dot.dot-esperando_piezas { background: var(--accent); }
.timeline-dot.dot-pendiente { background: var(--amber); }
.timeline-dot.dot-presupuesto { background: var(--purple); }

/* Recordatorios ITV / Revisión */
.reminder-card {
  border-left: 4px solid var(--amber);
}

.reminder-card.reminder-overdue {
  border-left-color: var(--red);
}

/* Buscador global */
.search-group-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 10px 0 6px;
}

.search-result-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.search-result-item:active {
  transform: scale(0.985);
}

/* Gráfica de barras mensual (Beneficios) */
.profit-bars {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  align-items: end;
  height: 120px;
  padding-top: 10px;
}

.profit-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}

.profit-bar-track {
  width: 100%;
  max-width: 28px;
  height: 76px;
  background: var(--surface-alt);
  border-radius: 7px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  border: 1px solid var(--border);
}

.profit-bar-fill {
  width: 100%;
  background: linear-gradient(180deg, var(--green) 0%, #15803D 100%);
  border-radius: 5px 5px 0 0;
  min-height: 2px;
  transition: height 0.25s ease;
}

.profit-bar-val {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text);
}

.profit-bar-lbl {
  font-size: 0.7rem;
  color: var(--muted);
}
