/* ===================================================
   AutoLog – Mobile-first responsive styles
   =================================================== */

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

:root {
  --green:       #1D9E75;
  --green-dark:  #0F6E56;
  --green-light: #E1F5EE;
  --green-text:  #085041;
  --blue:        #185FA5;
  --blue-light:  #E6F1FB;
  --blue-text:   #0C447C;
  --amber:       #BA7517;
  --amber-btn:   #EF9F27;
  --amber-light: #FAEEDA;
  --amber-text:  #633806;
  --red:         #A32D2D;
  --red-light:   #FCEBEB;
  --red-text:    #791F1F;
  --red-border:  #F7C1C1;
  --bg:          #F0F2F5;
  --bg-card:     #FFFFFF;
  --bg-surface:  #E8EAF0;
  --text:        #1a1a18;
  --text-muted:  #5F5E5A;
  --text-hint:   #959590;
  --border:      rgba(0,0,0,0.09);
  --border-md:   rgba(0,0,0,0.16);
  --radius:      10px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --shadow:      0 1px 4px rgba(0,0,0,0.07);
  color-scheme: light;
  --shadow-md:   0 4px 16px rgba(0,0,0,0.10);
  --font:        'Inter', system-ui, -apple-system, sans-serif;
  --topbar-h:    56px;
  --bottomnav-h: 64px;
}


/* ── Base ───────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Login ──────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: var(--bg);
}
.login-box { width: 100%; max-width: 400px; }
.brand-center { text-align: center; margin-bottom: 1.75rem; }
.brand-icon-lg {
  width: 64px; height: 64px;
  background: var(--green);
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 34px;
  margin: 0 auto 12px;
}
.brand-center h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.brand-center span { font-size: 14px; color: var(--text-muted); }
.switch-link { text-align: center; font-size: 14px; color: var(--text-muted); margin-top: 16px; }
.switch-link a { color: var(--green); text-decoration: none; font-weight: 500; }

/* ── App shell ──────────────────────────────────── */
#mainApp { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  width: 36px; height: 36px;
  background: var(--green);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px;
  flex-shrink: 0;
}
.brand-name { font-size: 17px; font-weight: 700; display: block; line-height: 1.2; }
.brand-sub  { font-size: 12px; color: var(--text-muted); display: block; line-height: 1; }

/* ── Sidebar (desktop) ──────────────────────────── */
.app-body { display: flex; flex: 1; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
}

.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  text-align: left;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn i { font-size: 18px; flex-shrink: 0; }
.nav-btn:hover  { background: var(--bg-surface); color: var(--text); }
.nav-btn.active { background: var(--green-light); color: var(--green-dark); font-weight: 600; }
.nav-divider {
  margin-top: 0.75rem; padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.nav-group-label {
  font-size: 10px; color: var(--text-hint);
  padding: 0 12px 6px;
  text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600;
}

/* ── Bottom nav (mobile) ────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottomnav-h);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 200;
  padding: 0 0.25rem;
  padding-bottom: env(safe-area-inset-bottom);
  align-items: center;
  justify-content: space-around;
}
.bnav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  flex: 1;
  height: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-hint);
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
  padding: 8px 4px 4px;
  border-radius: var(--radius);
}
.bnav-btn i { font-size: 22px; }
.bnav-btn.active { color: var(--green); }
.bnav-btn:active { transform: scale(0.93); }

/* ── Main content ───────────────────────────────── */
.main-content {
  flex: 1;
  padding: 1.25rem;
  min-width: 0;
  padding-bottom: 1.5rem;
}

/* ── Card ───────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card-subtitle { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 1rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Forms ──────────────────────────────────────── */
.field { margin-bottom: 1rem; }
label { font-size: 13px; color: var(--text-muted); display: block; margin-bottom: 6px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border-md);
  border-radius: var(--radius);
  font-size: 16px; /* 16px evita zoom en iOS */
  font-family: var(--font);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29,158,117,0.15);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
textarea { resize: vertical; min-height: 80px; font-size: 15px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.875rem; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 20px;
  border-radius: var(--radius);
  font-size: 15px; font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 44px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--green);     color: #fff;    border-color: var(--green); }
.btn-primary:hover, .btn-primary:active { background: var(--green-dark); border-color: var(--green-dark); }
.btn-ghost   { background: transparent;      color: var(--text-muted); border-color: var(--border-md); }
.btn-ghost:hover { background: var(--bg-surface); }
.btn-danger  { background: transparent;      color: var(--red);  border-color: var(--red-border); }
.btn-danger:hover { background: var(--red-light); }
.btn-amber   { background: var(--amber-btn); color: #3a1f00; border-color: var(--amber-btn); }
.btn-amber:hover, .btn-amber:active { background: var(--amber); border-color: var(--amber); }
.btn-sm  { padding: 7px 14px; font-size: 13px; min-height: 36px; }
.btn-full { width: 100%; }
.btn-icon { padding: 9px; min-height: 36px; min-width: 36px; }

/* ── Badges ─────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.badge-success { background: var(--green-light); color: var(--green-text); }
.badge-warning { background: var(--amber-light); color: var(--amber-text); }
.badge-danger  { background: var(--red-light);   color: var(--red-text);   }
.badge-info    { background: var(--blue-light);   color: var(--blue-text);  }
.badge-amber   { background: var(--amber-light);  color: var(--amber-text); }

/* ── Alerts ─────────────────────────────────────── */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.5;
}
.alert i { font-size: 17px; flex-shrink: 0; margin-top: 1px; }
.alert-warning { background: var(--amber-light); color: var(--amber-text); border: 1px solid #FAC775; }
.alert-success { background: var(--green-light); color: var(--green-text); border: 1px solid #9FE1CB; }
.alert-danger  { background: var(--red-light);   color: var(--red-text);   border: 1px solid var(--red-border); }
.alert-info    { background: var(--blue-light);   color: var(--blue-text);  border: 1px solid #B5D4F4; }

/* ── Section title ──────────────────────────────── */
.section-title { font-size: 18px; font-weight: 700; margin-bottom: 1.25rem; }

/* ── Vehicle cards ──────────────────────────────── */
.vehicles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.veh-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.veh-card:active { transform: scale(0.99); }
.veh-card.active { border-color: var(--green); box-shadow: 0 0 0 3px rgba(29,158,117,0.12); }
.veh-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  margin-bottom: 12px;
}
.veh-name { font-size: 17px; font-weight: 700; margin-bottom: 2px; }
.veh-meta { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.veh-stats { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 6px; flex-wrap: wrap; }
.veh-oil-label { font-size: 12px; color: var(--text-hint); margin-bottom: 4px; }
.km-bar  { height: 7px; background: var(--bg-surface); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
.km-fill { height: 100%; border-radius: 4px; transition: width 0.6s ease; }
.veh-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Stat cards ─────────────────────────────────── */
.stat-card { background: var(--bg-surface); border-radius: var(--radius); padding: 0.875rem 0.75rem; text-align: center; }
.stat-val  { font-size: 20px; font-weight: 700; line-height: 1.2; }
.stat-lbl  { font-size: 11px; color: var(--text-muted); margin-top: 3px; font-weight: 500; }

/* ── History ────────────────────────────────────── */
.hist-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.entry-row {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.entry-row:last-child { border-bottom: none; }
.entry-date { font-size: 12px; color: var(--text-hint); min-width: 82px; flex-shrink: 0; }
.entry-date strong { display: block; font-size: 13px; color: var(--text); margin-top: 2px; font-weight: 600; }

/* ── Fuel rows ──────────────────────────────────── */
.fuel-row {
  border-bottom: 1px solid var(--border);
  padding: 13px 0;
  display: grid;
  grid-template-columns: 86px 1fr auto;
  gap: 10px;
  align-items: center;
}
.fuel-row:last-child { border-bottom: none; }

/* ── Checkboxes ─────────────────────────────────── */
.checks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 8px;
  margin-bottom: 1rem;
}
.chk-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  position: relative;
  user-select: none;
}
.chk-item:hover { border-color: var(--green); }
.chk-item:has(input:checked) {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}
.chk-item:has(input:checked) label { color: #fff; }
.chk-item:has(input:checked) label i { color: #fff !important; }
/* Ocultar el checkbox nativo — el item completo actúa como toggle */
.chk-item input[type=checkbox] {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
  pointer-events: none;
}
/* Checkmark visible cuando está marcado */
.chk-item::after {
  content: '';
  display: none;
  width: 18px; height: 18px;
  background: rgba(255,255,255,0.25);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8l3.5 3.5L13 5' stroke='white' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  flex-shrink: 0;
  margin-left: auto;
}
.chk-item:has(input:checked)::after { display: block; }
.chk-item label {
  font-size: 13px; cursor: pointer; margin: 0;
  display: flex; align-items: center; gap: 6px;
  font-weight: 500; line-height: 1.3;
  pointer-events: none;
}

/* ── Misc ───────────────────────────────────────── */
.empty-msg  { color: var(--text-muted); font-size: 14px; padding: 1rem 0; text-align: center; }
.calc-hint  { font-size: 13px; color: var(--green); margin-bottom: 0.75rem; min-height: 20px; font-weight: 500; }
.analysis-table { width: 100%; font-size: 14px; border-collapse: collapse; }
.analysis-table td { padding: 9px 0; border-bottom: 1px solid var(--border); }
.analysis-table tr:last-child td { border-bottom: none; }
.analysis-table td:last-child  { text-align: right; font-weight: 600; }
.analysis-table td:first-child { color: var(--text-muted); }

/* ── Action row (form buttons) ──────────────────── */
.action-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 0.25rem; }

/* ====================================================
   DESKTOP (≥ 768px)
   ==================================================== */
@media (min-width: 768px) {
  .sidebar   { display: flex; }
  .bottom-nav { display: none !important; }
  .main-content { padding: 1.75rem; padding-bottom: 2rem; }
  .vehicles-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

/* ====================================================
   MOBILE (< 768px)
   ==================================================== */
@media (max-width: 767px) {
  /* Hide sidebar, show bottom nav */
  .sidebar    { display: none; }
  .bottom-nav { display: flex; }

  /* Push content above bottom nav */
  .main-content {
    padding: 1rem;
    padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 1rem);
  }

  /* Topbar compacto */
  .topbar { padding: 0 0.875rem; }
  .brand-name { font-size: 16px; }

  /* Cards sin padding excesivo */
  .card { padding: 1rem; }

  /* Grids en columna */
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .grid2 .field { margin-bottom: 0.875rem; }
  .vehicles-grid { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Checkboxes 1 col en móvil muy chico */
  .checks-grid { grid-template-columns: 1fr 1fr; gap: 7px; }

  /* Botones full en forms */
  .action-row { flex-direction: column; }
  .action-row .btn { width: 100%; }

  /* Section title */
  .section-title { font-size: 17px; margin-bottom: 1rem; }

  /* History header stack */
  .hist-header { flex-direction: column; }
  .hist-header .grid4 { width: 100%; grid-template-columns: 1fr 1fr 1fr; }

  /* Stat vals más chicos */
  .stat-val { font-size: 17px; }
  .stat-lbl { font-size: 10px; }

  /* Entry rows */
  .entry-date { min-width: 72px; }

  /* Fuel rows */
  .fuel-row { grid-template-columns: 78px 1fr auto; gap: 8px; }
}

@media (max-width: 380px) {
  .checks-grid { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .hist-header .grid4 { grid-template-columns: 1fr 1fr; }
  .veh-actions { gap: 4px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; }
}
