/* ============================================================
   AMEEI — Checklist y Dashboard de carros
   Sistema visual: Apple HIG, claro.
   ============================================================ */

:root {
  /* Superficies */
  --bg:            #f5f5f7;
  --bg-elevated:   #ffffff;
  --surface:       #ffffff;
  --surface-sunken:#f0f0f2;
  --hairline:      rgba(0,0,0,0.08);
  --hairline-strong: rgba(0,0,0,0.14);

  /* Texto */
  --text:          #1d1d1f;
  --text-secondary:#525257;
  --text-tertiary: #6e6e73;

  /* Acción */
  --blue:          #0071e3;
  --blue-press:    #0063c6;
  --blue-tint:     #e8f1fd;

  /* Semáforo (color vivo para puntos/LED) */
  --green:         #28a745;
  --amber:         #e8930c;
  --red:           #e23b30;
  /* Tinte de fondo + tinta legible (AA) para las pills */
  --green-bg:      #e3f5ea;  --green-ink: #1a7a34;
  --amber-bg:      #fdf1dd;  --amber-ink: #8a5600;
  --red-bg:        #fcebea;  --red-ink:   #b4271d;

  /* Sombras (offset + blur reales) */
  --shadow-card:   0 1px 2px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
  --shadow-card-hover: 0 2px 4px rgba(0,0,0,0.06), 0 10px 28px rgba(0,0,0,0.10);
  --shadow-pop:    0 8px 40px rgba(0,0,0,0.16);

  /* Radios */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 980px;

  /* Tipografía */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;

  --maxw: 1120px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.47;
  letter-spacing: -0.01em;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Superficies del navegador tematizadas */
::selection { background: rgba(0,113,227,0.18); }
::placeholder { color: var(--text-tertiary); }
:focus-visible { outline: 3px solid rgba(0,113,227,0.45); outline-offset: 2px; border-radius: 6px; }
* { scrollbar-width: thin; scrollbar-color: #c7c7cc transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #c7c7cc; border-radius: 980px; border: 3px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: #a9a9af; }

h1,h2,h3 { letter-spacing: -0.022em; margin: 0; font-weight: 600; }
a { color: var(--blue); text-decoration: none; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ---------- Layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(245,245,247,0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
}
.topbar .wrap { display: flex; align-items: center; gap: 16px; height: 56px; }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 19px; }
.topbar .brand .dot { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg,#0a84ff,#0071e3); display: grid; place-items: center; }
.topbar .spacer { flex: 1; }
.topbar nav { display: flex; gap: 2px; }
.topbar nav a {
  color: var(--text-secondary); font-size: 15px; font-weight: 500;
  padding: 7px 14px; border-radius: var(--r-pill); transition: background .15s, color .15s;
}
.topbar nav a:hover { background: rgba(0,0,0,0.04); color: var(--text); }
.topbar nav a.active { background: var(--text); color: #fff; }

.page-head { padding: 40px 0 24px; }
.page-head h1 { font-size: clamp(28px, 4vw, 40px); font-weight: 700; }
.page-head .sub { color: var(--text-secondary); font-size: 19px; margin-top: 6px; }

/* ---------- Resumen de estado ---------- */
.summary { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.summary .chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--hairline);
  padding: 8px 14px 8px 12px; border-radius: var(--r-pill);
  font-size: 15px; font-weight: 500; box-shadow: var(--shadow-card);
}
.summary .chip .led { width: 10px; height: 10px; border-radius: 50%; }
.summary .chip b { font-variant-numeric: tabular-nums; }
.led.ok  { background: var(--green); }
.led.rev { background: var(--amber); }
.led.bad { background: var(--red); }

/* ---------- Grilla de carros ---------- */
.fleet { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; padding-bottom: 56px; }

.car {
  position: relative; text-align: left; cursor: pointer;
  background: var(--surface); border: none; border-radius: var(--r-lg);
  padding: 20px; box-shadow: var(--shadow-card);
  transition: transform .18s cubic-bezier(.2,.7,.2,1), box-shadow .18s;
  display: flex; flex-direction: column; gap: 14px; font-family: inherit; color: inherit;
}
.car:hover { transform: translateY(-3px); box-shadow: var(--shadow-card-hover); }
.car:active { transform: translateY(-1px); }
.car .car-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.car .name { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; }
.car .type { color: var(--text-secondary); font-size: 14px; margin-top: 2px; }
.car .loc { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 14px; }
.car .loc svg { width: 15px; height: 15px; opacity: .7; }
.car .car-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; }
.car .ago { color: var(--text-tertiary); font-size: 13px; }

/* ---------- Pills de estado ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: var(--r-pill); font-size: 13px; font-weight: 600; white-space: nowrap; }
.status .led { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.ok  { background: var(--green-bg); color: var(--green-ink); }
.status.rev { background: var(--amber-bg); color: var(--amber-ink); }
.status.bad { background: var(--red-bg);  color: var(--red-ink); }
.status .led { background: currentColor; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 16px; font-weight: 500; line-height: 1;
  padding: 12px 20px; border-radius: var(--r-pill); border: 1px solid transparent;
  cursor: pointer; transition: background .15s, transform .1s, box-shadow .15s;
  background: var(--surface-sunken); color: var(--text);
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--blue); color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
.btn.primary:hover { background: var(--blue-press); }
.btn.ghost { background: transparent; color: var(--blue-press); padding: 10px 14px; }
.btn.ghost:hover { background: var(--blue-tint); color: #004a99; }
.btn.block { width: 100%; }
.btn.lg { font-size: 18px; padding: 15px 24px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 20px; }
.field > label { display: block; font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.input, select.input, textarea.input {
  width: 100%; font-family: inherit; font-size: 17px; color: var(--text);
  background: var(--surface); border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md); padding: 13px 15px; transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
.input:focus, select.input:focus, textarea.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px var(--blue-tint); }
select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%236e6e73' stroke-width='1.6'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px; }
textarea.input { resize: vertical; min-height: 84px; line-height: 1.5; }

/* ---------- Checklist items ---------- */
.card {
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-card);
  padding: 8px; margin-bottom: 20px;
}
.card.pad { padding: 22px; }
.card-title { font-size: 15px; font-weight: 600; color: var(--text-secondary); padding: 14px 14px 8px; }

.chk {
  display: flex; align-items: center; gap: 14px; padding: 14px;
  border-radius: var(--r-md);
}
.chk + .chk { border-top: 1px solid var(--hairline); }
.chk .chk-name { flex: 1; font-size: 17px; font-weight: 500; }

/* Segmented control OK / Falla / N/A */
.seg { display: inline-flex; background: var(--surface-sunken); border-radius: 10px; padding: 3px; gap: 2px; flex-shrink: 0; }
.seg button {
  font-family: inherit; font-size: 13px; font-weight: 600; border: none; cursor: pointer;
  padding: 7px 12px; border-radius: 8px; background: transparent; color: var(--text-secondary);
  transition: background .15s, color .15s, box-shadow .15s;
}
.seg button.on-ok  { background: #fff; color: var(--green-ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button.on-bad { background: #fff; color: var(--red-ink);   box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button.on-na  { background: #fff; color: var(--text-secondary); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.chk .note-in {
  display: none; width: 100%; margin-top: 10px;
}
.chk.has-fail { flex-wrap: wrap; background: var(--red-bg); }
.chk.has-fail .note-in { display: block; }
.chk.has-fail .note-in input { background: #fff; }

/* ---------- Modal / hoja de detalle ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.3); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
  opacity: 0; transition: opacity .2s;
}
.sheet-backdrop.open { display: flex; opacity: 1; }
.sheet {
  background: var(--bg-elevated); border-radius: 24px; box-shadow: var(--shadow-pop);
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  transform: translateY(12px) scale(.98); transition: transform .24s cubic-bezier(.2,.8,.2,1);
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-head { position: sticky; top: 0; background: rgba(255,255,255,0.86); backdrop-filter: blur(16px); padding: 20px 22px 14px; border-bottom: 1px solid var(--hairline); display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h2 { font-size: 24px; font-weight: 700; }
.sheet-body { padding: 20px 22px 26px; }
.iconbtn { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--surface-sunken); color: var(--text-secondary); cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.iconbtn:hover { background: #e3e3e6; }
.iconbtn svg { width: 16px; height: 16px; }

/* Listas de reportes / servicios */
.rep { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--hairline); }
.rep:first-child { border-top: none; }
.rep .rep-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex-shrink: 0; }
.rep .rep-dot.open { background: var(--red); }
.rep .rep-dot.done { background: var(--green); }
.rep .rep-main { flex: 1; }
.rep .rep-desc { font-weight: 500; }
.rep .rep-meta { color: var(--text-tertiary); font-size: 13px; margin-top: 3px; }
.rep .rep-done-tag { color: var(--green-ink); font-size: 12px; font-weight: 600; }

.section-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-tertiary); margin: 22px 0 6px; }

/* ---------- Estados ---------- */
.empty { text-align: center; padding: 64px 20px; color: var(--text-secondary); }
.empty svg { width: 46px; height: 46px; opacity: .3; margin-bottom: 14px; }
.empty h3 { font-size: 19px; color: var(--text); margin-bottom: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: #1d1d1f; color: #fff; padding: 13px 20px; border-radius: var(--r-pill);
  font-size: 15px; font-weight: 500; box-shadow: var(--shadow-pop); z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; display: inline-flex; gap: 9px; align-items: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

.skeleton { background: linear-gradient(100deg, #ececee 30%, #f4f4f6 50%, #ececee 70%); background-size: 200% 100%; animation: sk 1.2s ease-in-out infinite; border-radius: var(--r-lg); height: 128px; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.spin { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- Logo en topbar ---------- */
.topbar .brand .logo { height: 26px; width: auto; display: block; }

/* ---------- Encabezados de sección del checklist ---------- */
.sec-head { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-tertiary); padding: 26px 4px 10px; display: flex; align-items: center; gap: 8px; }
.sec-head .n { background: var(--surface-sunken); color: var(--text-secondary); border-radius: 50%; width: 20px; height: 20px; display: grid; place-items: center; font-size: 11px; }

/* Datos rápidos (km, gasolina) */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 440px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Diagrama de daños ---------- */
.diagram { }
.view-tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.view-tabs button {
  font-family: inherit; font-size: 14px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--hairline-strong); background: var(--surface); color: var(--text-secondary);
  padding: 8px 15px; border-radius: var(--r-pill); cursor: pointer; transition: all .15s; position: relative;
}
.view-tabs button.active { background: var(--text); color: #fff; border-color: var(--text); }
.view-tabs button .badge { position: absolute; top: -5px; right: -5px; background: var(--red); color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 10px; display: grid; place-items: center; padding: 0 4px; }
.canvas { position: relative; width: 100%; background: var(--surface-sunken); border-radius: var(--r-md); overflow: hidden; cursor: crosshair; touch-action: manipulation; }
.canvas img { width: 100%; display: block; -webkit-user-drag: none; user-select: none; pointer-events: none; }
.canvas .hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); background: rgba(29,29,31,.7); color: #fff; font-size: 12px; padding: 5px 12px; border-radius: 980px; pointer-events: none; }
.pin {
  position: absolute; width: 26px; height: 26px; border-radius: 50%; transform: translate(-50%,-50%);
  background: var(--red); color: #fff; border: 2.5px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; cursor: pointer; z-index: 2;
}
.pin.sel { outline: 3px solid rgba(226,59,48,.4); }
.marks { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.mark { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-md); padding: 10px 12px; }
.mark .mk-num { width: 24px; height: 24px; border-radius: 50%; background: var(--red); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; flex-shrink: 0; }
.mark select, .mark input { font-family: inherit; font-size: 15px; border: none; background: transparent; color: var(--text); padding: 4px 0; }
.mark select { font-weight: 600; flex-shrink: 0; }
.mark input { flex: 1; min-width: 0; border-bottom: 1px solid var(--hairline); }
.mark input:focus, .mark select:focus { outline: none; }
.mark .mk-del { margin-left: auto; width: 26px; height: 26px; border-radius: 50%; border: none; background: var(--surface-sunken); color: var(--text-tertiary); cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.mark .mk-view { font-size: 12px; color: var(--text-tertiary); flex-shrink: 0; }

/* Diagrama solo-lectura (dashboard) */
.canvas.ro { cursor: default; }
.canvas.ro .pin { cursor: default; }

@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

/* ---------- Móvil ---------- */
.mobile-wrap { max-width: 560px; }
@media (max-width: 640px) {
  body { font-size: 17px; }
  .page-head { padding: 24px 0 18px; }
  .topbar nav a { padding: 7px 11px; }
  .fleet { grid-template-columns: 1fr; }
  .sheet { max-height: 92vh; border-radius: 20px 20px 0 0; align-self: flex-end; }
  .sheet-backdrop { align-items: flex-end; padding: 0; }
}
