:root {
  --bg: #F3F0EA; --surface: #FBF9F5; --surface-2: #ECE6DC;
  --ink: #181B1E; --ink-soft: #565A5F; --line: #DED7CB;
  --brand: #14465F; --brand-strong: #0E3346; --accent: #EC8613; --on-accent: #22150A;
  --ok: #2C7A4B; --warn: #C77A18; --bad: #B4472B; --wa: #25D366;
  --font-display: "Helvetica Neue", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111518; --surface: #1A2024; --surface-2: #232B31;
    --ink: #ECEAE3; --ink-soft: #9AA1A7; --line: #2B333A;
    --brand: #57A2C9; --brand-strong: #123B54; --accent: #F59E2A; --on-accent: #22150A;
    --ok: #52B478; --warn: #E0A94B; --bad: #E08267;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
.wrap { width: min(1000px, 94vw); margin-inline: auto; }

/* header */
.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; gap: 12px; flex-wrap: wrap; }
.brand-mark { font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; letter-spacing: -.03em; }
.brand-mark .dot { color: var(--accent); }
.brand-sub { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* menú hamburguesa: oculto en escritorio, no cambia nada de la vista ancha */
.nav-toggle { display: none; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); cursor: pointer; place-items: center; }
.nav-toggle svg { width: 22px; height: 22px; }
.nav-toggle:active { transform: scale(.96); }

@media (max-width: 768px) {
  .nav-toggle { display: inline-grid; }
  .top .wrap { position: relative; }
  /* los MISMOS enlaces, ahora como panel desplegable anclado a la cabecera */
  .actions {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
    flex-direction: column; align-items: stretch; flex-wrap: nowrap;
    min-width: 220px; max-width: min(280px, 86vw);
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
    padding: 8px; box-shadow: 0 12px 28px -10px rgba(0,0,0,.35);
    opacity: 0; visibility: hidden; transform: translateY(-6px);
    transition: opacity .18s var(--ease-out), transform .18s var(--ease-out), visibility .18s;
  }
  .actions.open { opacity: 1; visibility: visible; transform: translateY(0); }
  .actions > .btn, .actions > form { width: 100%; margin: 0; }
  .actions > form > .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .actions { transition: none; }
  .nav-toggle:active { transform: none; }
}

/* botones */
.btn { display: inline-flex; align-items: center; gap: .5ch; font-family: var(--font-display); font-weight: 700; font-size: .9rem; padding: .6em 1.05em; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; transition: filter .18s var(--ease-out), transform .18s var(--ease-out), box-shadow .18s var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .btn:hover { transform: translateY(-1px); } }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); color: #fff; border-color: transparent; }
.btn-accent { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn-wa { background: var(--wa); color: #06331a; border-color: transparent; }
.btn-danger { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.btn-danger:hover { background: color-mix(in srgb, var(--bad) 20%, var(--surface)); }
.btn svg { width: 1.05em; height: 1.05em; fill: currentColor; }

/* layout */
main { padding: 30px 0 70px; }
h1 { font-family: var(--font-display); font-size: clamp(1.7rem, 4vw, 2.3rem); font-weight: 800; letter-spacing: -.02em; margin: 0 0 4px; }
.eyebrow { font-family: var(--font-mono); font-size: .7rem; letter-spacing: .16em; text-transform: uppercase; color: var(--brand); font-weight: 600; margin: 34px 0 14px; }

/* resumen */
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin: 18px 0 6px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; min-width: 130px; }
.stat .n { font-family: var(--font-display); font-weight: 800; font-size: 2rem; letter-spacing: -.03em; line-height: 1; }
.stat .n.alert { color: var(--accent); }
.stat .k { color: var(--ink-soft); font-size: .85rem; margin-top: 4px; }

/* tarjetas de aviso */
.avisos { display: grid; gap: 14px; }
.aviso { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; display: grid; gap: 12px; }
.aviso-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.aviso-quien b { font-family: var(--font-display); font-size: 1.05rem; }
.aviso-quien span { color: var(--ink-soft); font-size: .9rem; }
.aviso-quien .plate { color: #fff; }
.plate { font-family: var(--font-mono); font-weight: 700; letter-spacing: .05em; background: var(--brand); color: #fff; padding: .1em .5em; border-radius: 4px; font-size: .8rem; }
.msg { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; font-size: .93rem; color: var(--ink); }
.aviso-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.aviso-foot .sin-tel { color: var(--ink-soft); font-size: .82rem; }

/* pills de estado */
.pill { font-family: var(--font-mono); font-size: .72rem; font-weight: 700; letter-spacing: .02em; padding: .25em .65em; border-radius: 999px; white-space: nowrap; }
.pill.vencida { background: color-mix(in srgb, var(--bad) 18%, var(--surface)); color: var(--bad); }
.pill.pronto  { background: color-mix(in srgb, var(--warn) 20%, var(--surface)); color: var(--warn); }
.pill.ok      { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); color: var(--ok); }
.pill.sin_fecha { background: var(--surface-2); color: var(--ink-soft); }

/* tabla */
.tabla-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--surface); }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td .plate { font-size: .74rem; }

/* flash */
.flashes { display: grid; gap: 8px; margin: 18px 0 4px; }
.flash { border-radius: 10px; padding: 11px 14px; font-size: .9rem; border: 1px solid; }
.flash.ok { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.flash.error { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.flash.warn { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); }

/* vacío / importar */
.vacio { text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: 16px; padding: 46px 24px; }
.vacio p { color: var(--ink-soft); margin: 6px 0 18px; }
.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; max-width: 560px; }
.form-card input[type=file] { display: block; margin: 14px 0; width: 100%; }
.hint { color: var(--ink-soft); font-size: .88rem; }
.hint code { font-family: var(--font-mono); background: var(--surface-2); padding: .1em .4em; border-radius: 5px; }

/* formulario de alta */
.campo { display: block; margin: 12px 0; font-size: .88rem; color: var(--ink-soft); }
.campo input, .campo select, .campo textarea { display: block; width: 100%; margin-top: 6px; padding: .6em .7em; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--ink); font-size: 1rem; font-family: inherit; }
.campo textarea { resize: vertical; line-height: 1.5; }
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.fila { display: flex; gap: 14px; }
.fila .campo { flex: 1; }
@media (max-width: 520px) { .fila { flex-direction: column; gap: 0; } }

/* ficha del vehículo */
.ficha-head { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline; margin: 6px 0 2px; }
.ficha-head .dato { font-size: .9rem; color: var(--ink-soft); }
.ficha-head .dato b { color: var(--ink); }
.check-group { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; margin: 6px 0 4px; }
.check-group label { display: flex; align-items: center; gap: 9px; font-size: .92rem; color: var(--ink); background: var(--surface-2); padding: 9px 11px; border-radius: 9px; cursor: pointer; margin: 0; }
.check-group input { width: auto; margin: 0; }
.historial { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.historial li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: .9rem; }
.historial .cab { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 4px; }
.historial .ops { color: var(--ink-soft); margin-top: 2px; }

/* buscador */
.buscador { display: flex; align-items: center; gap: 9px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 9px 13px; margin: 0 0 14px; }
.buscador svg { width: 18px; height: 18px; flex: none; stroke: var(--ink-soft); }
.buscador input { flex: 1; border: 0; background: transparent; color: var(--ink); font-size: 1rem; font-family: inherit; outline: none; }
.buscador input::placeholder { color: var(--ink-soft); }

/* campos numéricos de intervalos en Ajustes */
.num-cfg { width: 100px; padding: .45em .55em; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--ink); font-size: .95rem; font-family: inherit; }
.num-cfg:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

/* filtros por estado (chips) */
.filtros { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.chip { font-family: var(--font-display); font-weight: 700; font-size: .82rem; padding: .42em .9em; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer; transition: filter .15s var(--ease-out), color .15s var(--ease-out); }
.chip.is-activo { background: var(--brand); color: #fff; border-color: transparent; }
@media (hover: hover) and (pointer: fine) { .chip:hover { color: var(--ink); } .chip.is-activo:hover { color: #fff; } }

/* botón flotante subir/bajar */
.fab-scroll { position: fixed; right: 20px; bottom: 20px; width: 48px; height: 48px; border-radius: 50%; background: var(--brand); color: #fff; border: 0; cursor: pointer; display: grid; place-items: center; box-shadow: 0 10px 24px -8px rgba(0,0,0,.4); z-index: 55; transition: transform .18s var(--ease-out); }
.fab-scroll:active { transform: scale(.92); }
.fab-scroll svg { width: 22px; height: 22px; transition: transform .3s var(--ease-out); }
.fab-scroll[data-dir="up"] svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .fab-scroll, .fab-scroll svg { transition: none; } }

/* buscador: contador de resultados y resaltado de coincidencias */
.buscador .contador { color: var(--ink-soft); font-size: .82rem; font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }
mark { background: color-mix(in srgb, var(--accent) 32%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.sin-resultados td { text-align: center; color: var(--ink-soft); padding: 28px 14px; }
tbody tr { transition: background .15s ease; }

/* foco de teclado visible en todo lo interactivo (accesibilidad) */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 8px;
}

/* enlace al nombre del cliente (lleva a su ficha) */
.cliente-link { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1.5px; font-weight: 600; }
.cliente-link:hover { color: var(--brand-strong); }
@media (prefers-color-scheme: dark) { .cliente-link:hover { color: var(--accent); } }

/* tarjeta de coche en la ficha del cliente (toda ella es un enlace) */
.coche-card { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  text-decoration: none; color: inherit; transition: border-color .18s var(--ease-out), transform .18s var(--ease-out), box-shadow .18s var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .coche-card:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); transform: translateY(-1px); box-shadow: 0 8px 20px -14px rgba(0,0,0,.4); } }
.coche-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.coche-main b { font-family: var(--font-display); font-size: 1.05rem; }
.coche-tipo { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); background: var(--surface-2); padding: .2em .55em; border-radius: 999px; }
.coche-side { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.coche-side .dato { font-size: .82rem; color: var(--ink-soft); }
.coche-side .dato b { color: var(--ink); }
.coche-side .abrir { font-family: var(--font-mono); font-size: .72rem; color: var(--brand); font-weight: 700; }

/* ficha del cliente: identidad a la izquierda, datos editables a la derecha */
.cliente-cabecera { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 30px; align-items: start; margin: 6px 0 10px; }
@media (max-width: 720px) { .cliente-cabecera { grid-template-columns: 1fr; } }
.cliente-id h1 { margin: 0 0 4px; }
.cliente-id .dato-coches { color: var(--ink-soft); font-size: .92rem; margin: 0 0 16px; }
.cliente-datos { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; }
.cliente-datos .campo { margin: 8px 0; }

/* página 404 */
.error-404 { text-align: center; padding: clamp(40px, 9vw, 90px) 20px 50px; }
.error-404 .cifra { font-family: var(--font-display); font-weight: 800; font-size: clamp(4.5rem, 20vw, 10rem); line-height: .9; letter-spacing: -.05em; color: var(--brand); }
.error-404 .cifra span { color: var(--accent); }
.error-404 h1 { margin: 10px 0 6px; }
.error-404 p { color: var(--ink-soft); max-width: 42ch; margin: 0 auto 24px; }

/* ---- campo de fecha a la española (dd/mm/aaaa) + calendario ---- */
.fecha-campo { position: relative; display: block; margin-top: 6px; }
.fecha-campo input { margin-top: 0 !important; padding-right: 2.6em !important; font-variant-numeric: tabular-nums; }
.fecha-campo input[aria-invalid="true"] { border-color: var(--bad); }
.fecha-boton { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--ink-soft); cursor: pointer; }
.fecha-boton:hover { background: var(--surface); color: var(--brand); }
.fecha-boton:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.fecha-boton svg { width: 20px; height: 20px; }
.fecha-aviso { display: block; margin-top: 5px; font-size: .82rem; color: var(--bad); }
.fecha-cal { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; width: min(280px, 86vw); padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 14px 34px rgba(0,0,0,.16); }
.fecha-cal-top { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-bottom: 8px; }
.fecha-cal-top b { font-size: .92rem; text-transform: capitalize; }
.fecha-cal-mover { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--ink); font-size: 1.1rem; line-height: 1; cursor: pointer; }
.fecha-cal-mover:hover { background: var(--brand); color: #fff; border-color: transparent; }
.fecha-cal-mover[disabled] { opacity: .3; cursor: default; }
.fecha-cal-mover[disabled]:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
/* el mes y el año de la cabecera son botones: llevan a la vista de meses y de años */
.fecha-cal-titulo { flex: 1; min-width: 0; padding: .32em .3em; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--ink); font-family: inherit; font-size: .92rem; font-weight: 700; text-transform: capitalize; cursor: pointer; }
.fecha-cal-titulo:hover { background: var(--surface-2); border-color: var(--line); }
.fecha-cal-titulo:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.fecha-cal-rango { flex: 1; text-align: center; font-variant-numeric: tabular-nums; }
.fecha-cal-rejilla { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.fecha-cal-opcion { height: 40px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--ink); font-family: inherit; font-size: .86rem; text-transform: capitalize; font-variant-numeric: tabular-nums; cursor: pointer; }
.fecha-cal-opcion:hover { background: var(--surface-2); }
.fecha-cal-opcion:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.fecha-cal-opcion.es-hoy { border-color: var(--accent); font-weight: 700; }
.fecha-cal-opcion.es-elegida { background: var(--brand); color: #fff; }
.fecha-cal-dias { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.fecha-cal-letra { display: grid; place-items: center; height: 26px; font-family: var(--font-mono); font-size: .66rem; color: var(--ink-soft); }
.fecha-cal-dia { height: 34px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--ink); font-size: .88rem; font-family: inherit; cursor: pointer; font-variant-numeric: tabular-nums; }
.fecha-cal-dia:hover { background: var(--surface-2); }
.fecha-cal-dia:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.fecha-cal-dia.es-hoy { border-color: var(--accent); font-weight: 700; }
.fecha-cal-dia.es-elegida { background: var(--brand); color: #fff; }
.fecha-cal-pie { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.fecha-cal-hoy { width: 100%; padding: .45em .6em; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--ink); font-family: inherit; font-size: .82rem; cursor: pointer; }
.fecha-cal-hoy:hover { background: var(--brand); color: #fff; border-color: transparent; }
