:root {
  --fondo: #f2f3ef; --tarjeta: #ffffff; --tarjeta2: #eef0eb; --borde: #e2e5de;
  --texto: #191b1d; --suave: #5c6168; --tenue: #8b9097;
  --acento: #2f9e5b; --acento-tinta: #ffffff; --acento-suave: #e3f4e9;
  --ok: #2f9e5b; --alerta: #b97c12; --alerta-suave: #fdf3e0; --critico: #d4504d; --critico-suave: #fdecec;
  --sombra: 0 1px 2px rgba(20,30,20,.04), 0 6px 18px rgba(20,30,20,.06);
  --radio: 20px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* iPhone: franja fija arriba del color del fondo. En la app instalada tapa la zona del reloj; en Safari,
   Safari toma su color para pintar esa zona y lo que se desplaza no se monta con la hora.
   Tiene que ser un elemento de verdad: Safari ignora ::before. */
.techo { position: fixed; top: 0; left: 0; right: 0; z-index: 16; pointer-events: none;
               height: max(env(safe-area-inset-top), 16px); background: var(--fondo); }
@media print { .techo { display: none; } }
html, body { margin: 0; background: var(--fondo); color: var(--texto); }
body { font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
       padding: max(16px, env(safe-area-inset-top)) 16px calc(150px + env(safe-area-inset-bottom));
       max-width: 560px; margin-inline: auto; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: var(--texto); }
a { color: inherit; text-decoration: none; }
h1 { font-size: 28px; margin: 4px 0 0; letter-spacing: -.02em; line-height: 1.15; }
h2 { font-size: 18px; margin: 28px 4px 10px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
h2 small { font-weight: 400; font-size: 15px; color: var(--suave); }
.num { font-variant-numeric: tabular-nums; }
.suave { color: var(--suave); }
.tarjeta { background: var(--tarjeta); border-radius: var(--radio); padding: 4px 16px; box-shadow: var(--sombra); }
.cargando, .nada { text-align: center; color: var(--suave); padding: 40px 12px; }
.nada b { display: block; color: var(--texto); font-size: 18px; margin-bottom: 4px; }

/* la patente chilena */
.patente { display: inline-flex; flex-direction: column; align-items: center; background: #fff; color: #111;
           border: 2px solid #111; border-radius: 6px; padding: 2px 7px 1px; line-height: 1; }
.patente b { font: 700 15px/1 "DIN Condensed", "Arial Narrow", "Roboto Condensed", sans-serif; letter-spacing: .08em; }
.patente i { font: 600 5px/1.2 system-ui; letter-spacing: .35em; font-style: normal; margin-top: 1px; }
.patente.grande { padding: 5px 14px 3px; border-width: 3px; border-radius: 9px; }
.patente.grande b { font-size: 30px; }
.patente.grande i { font-size: 8px; margin-top: 2px; }
.patente.vacia { border-style: dashed; border-color: #8b9097; color: #6b7077; }
.patente.vacia b { font-size: 11px; letter-spacing: .03em; }
.patente.grande.vacia b { font-size: 17px; }

/* volver */
.volver { display: inline-block; border: 0; background: none; color: var(--acento); font-size: 17px; padding: 6px 0; margin-bottom: 8px; }

/* inicio */
.cabecera { display: flex; justify-content: space-between; align-items: baseline; }
.buscar { display: flex; align-items: center; gap: 8px; background: var(--tarjeta); border-radius: 14px; box-shadow: var(--sombra); padding: 0 14px; margin: 14px 0 0; }
.buscar svg { width: 20px; height: 20px; stroke: var(--tenue); fill: none; stroke-width: 2; stroke-linecap: round; flex: none; }
.buscar input { flex: 1; min-width: 0; border: 0; background: none; padding: 14px 0; font-size: 17px; outline: none; }

.fila { display: flex; gap: 12px; align-items: center; width: 100%; padding: 13px 0; border: 0; border-top: 1px solid var(--borde);
        background: none; text-align: left; }
.fila:first-child { border-top: 0; }
.fila { flex-wrap: wrap; }
.fila .que { flex: 1 1 9em; min-width: 0; }
.fila .que b { display: block; font-weight: 600; }
.fila .que small { display: block; color: var(--suave); font-size: 15px; overflow-wrap: anywhere; }
.fila .der { margin-left: auto; text-align: right; white-space: nowrap; font-size: 15px; }
.fila .flecha { color: var(--tenue); font-size: 20px; line-height: 1; }
.estado { font-weight: 600; }
.estado.vencido { color: var(--critico); } .estado.pronto { color: var(--alerta); } .estado.ok { color: var(--ok); }
.mini { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; flex: none; background: var(--tarjeta2); }
.mini.chica { width: 34px; height: 34px; border-radius: 50%; }
.mas { display: block; width: 100%; border: 0; border-top: 1px solid var(--borde); background: none; color: var(--acento);
       font-weight: 600; padding: 13px 0; text-align: left; }

.grilla { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.carta { display: flex; flex-direction: column; border: 0; padding: 0; text-align: left; background: var(--tarjeta);
         border-radius: 18px; overflow: hidden; box-shadow: var(--sombra); }
.carta .sobre { position: relative; display: block; }
.carta img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--tarjeta2); }
.carta .sobre .patente { position: absolute; left: 8px; bottom: 8px; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.carta .patente b { font-size: 12px; }
.carta .datos { padding: 9px 12px 12px; }
.carta .datos b { display: block; font-weight: 650; font-size: 15px; line-height: 1.2; }
.carta .datos small { display: block; color: var(--suave); font-size: 14px; margin-top: 2px; }
.etiqueta { position: absolute; right: 8px; top: 8px; border-radius: 999px; padding: 3px 9px; font-size: 13px; font-weight: 700; color: #fff; }
.etiqueta.vencido { background: var(--critico); } .etiqueta.pronto { background: var(--alerta); }

/* ficha */
.portada { position: relative; margin-bottom: 26px; }
.portada img { display: block; width: 100%; aspect-ratio: 16 / 11; object-fit: cover; border-radius: var(--radio); box-shadow: var(--sombra); background: var(--tarjeta2); }
.portada .patente { position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%); box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.titulo { text-align: center; margin: 34px 0 4px; }
.titulo h1 { font-size: 25px; }
.titulo p { margin: 4px 0 0; color: var(--suave); }
.enlace { border: 0; background: none; padding: 0; color: var(--acento); font-weight: 600; font-size: inherit; }
.aldia { display: flex; gap: 10px; align-items: center; color: var(--ok); font-weight: 600; padding: 14px 0; }
.detalle-vence { padding: 0 0 14px 0; margin-top: -4px; color: var(--suave); font-size: 15px; }
.detalle-vence p { margin: 0 0 10px; }
.btn-chico { border: 0; border-radius: 12px; padding: 10px 16px; background: var(--acento-suave); color: var(--acento); font-weight: 650; }
details.mas-info { margin-top: 26px; }
details.mas-info summary { list-style: none; cursor: pointer; color: var(--acento); font-weight: 600; padding: 8px 4px; }
details.mas-info summary::-webkit-details-marker { display: none; }
details.mas-info[open] summary { margin-bottom: 8px; }
.dato { padding: 12px 0; border-top: 1px solid var(--borde); }
.dato:first-child { border-top: 0; }
.dato span { display: block; font-size: 14px; color: var(--tenue); }
.dato p { margin: 2px 0 0; font-size: 16px; }
.parado { background: var(--alerta-suave); border-radius: 16px; padding: 12px 14px; margin-top: 12px; font-size: 15px; }
.parado b { display: block; }
.parado ul { margin: 6px 0 0; padding-left: 18px; color: var(--suave); }
.clip { width: 16px; height: 16px; stroke: var(--tenue); fill: none; stroke-width: 2; vertical-align: -3px; margin-left: 4px; }

/* registrar */
.camara { text-align: center; padding: 34px 20px 28px; margin-top: 16px; }
.camara svg { width: 64px; height: 64px; stroke: var(--acento); fill: none; stroke-width: 1.5; stroke-linejoin: round; }
.camara h2 { display: block; margin: 10px 0 6px; font-size: 21px; }
.camara p { margin: 0; color: var(--suave); }
.otras { display: flex; flex-direction: column; gap: 4px; align-items: center; margin-top: 18px; }
.otras .enlace { padding: 10px; font-size: 17px; }
.chip-auto { display: flex; gap: 10px; align-items: center; margin-top: 14px; color: var(--suave); }
.leyendo { position: relative; margin-top: 16px; border-radius: var(--radio); overflow: hidden; box-shadow: var(--sombra); background: #222; }
.leyendo img { display: block; width: 100%; max-height: 56vh; object-fit: contain; opacity: .55; }
.leyendo div { position: absolute; inset: auto 0 0 0; padding: 18px; color: #fff; font-weight: 700; font-size: 19px;
               background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.leyendo small { display: block; font-weight: 400; font-size: 15px; opacity: .9; }
@media (prefers-reduced-motion: no-preference) {
  .leyendo::after { content: ""; position: absolute; left: 0; right: 0; height: 3px; top: 0; background: var(--acento);
                    box-shadow: 0 0 12px var(--acento); animation: barrer 1.6s ease-in-out infinite alternate; }
  @keyframes barrer { to { top: calc(100% - 3px); } }
}
.leida { display: flex; gap: 12px; align-items: center; margin: 14px 0 16px; }
.leida img { width: 56px; height: 72px; object-fit: cover; border-radius: 10px; flex: none; cursor: zoom-in; box-shadow: var(--sombra); }
.leida div { flex: 1; min-width: 0; }
.leida b { display: block; }
.leida small { display: block; color: var(--suave); font-size: 15px; }
.leida.error small { color: var(--alerta); }
.agregar-foto { display: flex; gap: 10px; align-items: center; justify-content: center; width: 100%; margin: 14px 0 16px; padding: 14px;
                border: 2px dashed var(--borde); border-radius: 16px; background: none; color: var(--suave); font-weight: 600; }
.agregar-foto svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.form .campo { display: flex; gap: 12px; align-items: center; min-height: 58px; border-top: 1px solid var(--borde); }
.form .campo:first-child { border-top: 0; }
.form .campo > label, .form .campo > span.etq { flex: none; width: 74px; color: var(--suave); font-size: 15px; }
.form .campo input { flex: 1; min-width: 0; border: 0; background: none; padding: 16px 0; font-size: 17px; outline: none; text-align: right; }
.form .campo input[type=date] { text-align: right; -webkit-appearance: none; appearance: none; min-height: 52px; }
.form .campo input::placeholder { color: #b6bab4; }
.form .campo .pre, .form .campo .suf { color: var(--tenue); }
.form .elegir { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; justify-content: flex-end; border: 0; background: none; padding: 10px 0;
                font-weight: 600; text-align: right; }
.form .elegir span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.form .elegir.falta { color: var(--acento); }
.form .elegir svg { width: 24px; height: 24px; stroke: var(--suave); fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.segmento { display: flex; flex: 1; background: var(--tarjeta2); border-radius: 12px; padding: 3px; }
.segmento button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 10px; color: var(--suave); }
.segmento button.activo { background: var(--tarjeta); color: var(--texto); font-weight: 600; box-shadow: var(--sombra); }
.segmento button.activo.rojo { color: var(--critico); }
.calculo { margin: 12px 4px 0; color: var(--suave); font-size: 15px; }
.calculo b { color: var(--texto); font-weight: 600; }
.calculo.alerta { color: var(--critico); }

.tipos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.tipos button { min-height: 84px; border-radius: 16px; border: 2px solid transparent; background: var(--tarjeta); box-shadow: var(--sombra);
                display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 12px 14px;
                font-weight: 600; text-align: left; line-height: 1.2; }
.tipos button svg { width: 26px; height: 26px; stroke: var(--suave); fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tipos button.elegido { border-color: var(--acento); background: var(--acento-suave); }
.tipos button.elegido svg { stroke: var(--acento); }
.grilla .carta.elegido { outline: 3px solid var(--acento); }

/* un registro */
.boleta-grande { display: block; width: 100%; border: 0; padding: 0; background: #222; border-radius: var(--radio); overflow: hidden; box-shadow: var(--sombra); margin: 8px 0 16px; cursor: zoom-in; }
.boleta-grande img { display: block; width: 100%; max-height: 50vh; object-fit: contain; }
.borrar { display: block; margin: 26px auto 0; border: 0; background: none; color: var(--critico); font-weight: 600; padding: 12px; }

/* gastos */
.total { padding: 18px 16px; margin-top: 14px; }
.total b { display: block; font-size: 40px; letter-spacing: -.03em; line-height: 1.05; }
.total span { color: var(--suave); }
.segmento.años { margin-top: 16px; }
.barra { display: block; height: 6px; border-radius: 3px; background: var(--tarjeta2); margin-top: 6px; overflow: hidden; }
.barra i { display: block; height: 100%; border-radius: 3px; background: var(--texto); opacity: .7; }

/* entrar */
.entrar { text-align: center; padding-top: 12vh; }
.entrar p { color: var(--suave); }
.entrar input { width: 100%; margin-top: 18px; padding: 16px; border: 0; border-radius: 14px; box-shadow: var(--sombra); font-size: 20px; text-align: center; }

/* informe para la venta */
.informe { background: #fff; border-radius: var(--radio); padding: 22px 18px; box-shadow: var(--sombra); margin-bottom: 14px; }
.informe header small { color: var(--tenue); font-size: 13px; }
.informe header h1 { font-size: 24px; margin: 2px 0 4px; }
.informe header p { margin: 0; color: var(--suave); font-size: 14px; }
.informe .fotos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.informe .fotos img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; }
.informe .resumen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.informe .resumen b { display: block; font-size: 20px; }
.informe .resumen span { font-size: 12px; color: var(--suave); }
.informe h2 { margin: 22px 0 8px; font-size: 16px; }
.informe table { width: 100%; border-collapse: collapse; font-size: 13px; }
.informe td, .informe th { text-align: left; padding: 7px 6px 7px 0; border-top: 1px solid var(--borde); vertical-align: top; }
.informe th { font-weight: 600; color: var(--suave); border-top: 0; }
.informe td small { display: block; color: var(--tenue); }
.informe footer { margin-top: 18px; font-size: 12px; color: var(--tenue); }
@media print {
  body { background: #fff; padding: 0; max-width: none; }
  .no-imprimir, .abajo { display: none !important; }
  .informe { box-shadow: none; padding: 0; }
  tr { break-inside: avoid; }
}

/* abajo: un solo botón verde + pestañas */
.abajo { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; padding: 10px 16px calc(8px + env(safe-area-inset-bottom));
         background: color-mix(in srgb, var(--fondo) 90%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.abajo > * { max-width: 528px; margin-inline: auto; }
.btn { display: flex; gap: 10px; align-items: center; justify-content: center; width: 100%; padding: 17px; border: 0; border-radius: 16px;
       background: var(--acento); color: var(--acento-tinta); font-weight: 700; font-size: 18px; }
.btn svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linejoin: round; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; }
#tabs { display: flex; justify-content: center; gap: 4px; margin-top: 6px; }
#tabs a { flex: 1; max-width: 160px; color: var(--tenue); font-size: 13px; display: grid; gap: 2px; padding: 4px; text-align: center; }
#tabs a svg { width: 24px; height: 24px; margin: 0 auto; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.activa { color: var(--acento); font-weight: 600; }

#aviso { position: fixed; left: 16px; right: 16px; top: max(16px, env(safe-area-inset-top)); z-index: 20; max-width: 528px; margin-inline: auto;
         background: var(--texto); color: #fff; border-radius: 14px; padding: 14px 16px; font-weight: 600; box-shadow: var(--sombra); }
#visor { position: fixed; inset: 0; z-index: 30; border: 0; padding: 20px; background: rgba(10,12,10,.9); display: grid; place-items: center; }
#visor img { max-width: 100%; max-height: 100%; border-radius: 8px; }
@media (prefers-reduced-motion: no-preference) { #aviso { animation: bajar .25s ease; } @keyframes bajar { from { transform: translateY(-12px); opacity: 0; } } }
