/* EncuentraCar — monocromo, tipografía grande, un único acento (azul) reservado a "tú" y la ruta. */
:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --fill: #eeece7;
  --ink: #0c0c0d;
  --muted: #74726d;
  --line: #e2e0da;
  --accent: #2f6bff;
  --ok: #1f9d55;
  --warn: #c48200;
  --danger: #d64533;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0c;
    --surface: #171718;
    --fill: #1b1b1d;
    --ink: #f4f3ef;
    --muted: #8f8e8a;
    --line: #29292b;
    --ok: #46c57e;
    --warn: #e6a92e;
    --danger: #ff6b5b;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow-x: hidden; max-width: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  width: 100%;
  overflow-x: hidden;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* Cabecera */
.topbar {
  display: flex;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  min-height: 60px;
}
.topbar h1 { flex: 1; padding: 0 12px; font-size: 1.05rem; font-weight: 600; letter-spacing: -0.01em; }
.topbar h1.wordmark { font-size: 0.74rem; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: none; cursor: pointer;
  transition: background 0.2s var(--ease);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn svg * { stroke-width: 1.6; }
.icon-btn:active { background: var(--fill); }

#view {
  overflow-x: hidden;
  overscroll-behavior-x: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 24px 0;
  outline: none;
  position: relative;
}

/* Tipografía */
.eyebrow, .fields label, dt {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}
.muted { color: var(--muted); font-size: 0.92rem; }
h2 { font-weight: 600; letter-spacing: -0.025em; line-height: 1.12; overflow-wrap: anywhere; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 50px; padding: 10px 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink);
  font-size: 0.94rem; font-weight: 500; letter-spacing: -0.005em;
  text-align: center; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease), opacity 0.2s;
}
.btn:active { transform: scale(0.97); background: var(--fill); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 600; }
.btn.primary:active { background: var(--ink); opacity: 0.85; }
.btn.big { min-height: 60px; font-size: 1.05rem; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.danger-text { color: var(--danger); }
.link { border: 0; background: none; color: var(--muted); padding: 8px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 0.9rem; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.row > .btn { padding-inline: 6px; }
.grow { flex: 2 !important; }
:is(.btn, .icon-btn, .link, input, textarea, .photo, .map.mini):focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.bottom {
  position: sticky; bottom: 0;
  margin: auto -24px 0;
  padding: 20px 24px calc(16px + var(--safe-b));
  display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(to top, var(--bg) 80%, transparent);
  z-index: 2;
}

/* Inicio sin coche */
.empty { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }
.empty h2 { font-size: 2.35rem; }
.empty > p:last-child { color: var(--muted); max-width: 30ch; font-size: 1.02rem; }
.empty.plain { justify-content: center; }
.empty.plain h2 { font-size: 1.6rem; }
.rings { position: relative; flex: 1; min-height: 180px; display: grid; place-items: center; }
.rings i { position: absolute; border: 1px solid var(--line); border-radius: 50%; aspect-ratio: 1; }
.rings i:nth-child(1) { width: 84px; }
.rings i:nth-child(2) { width: 168px; opacity: 0.8; }
.rings i:nth-child(3) { width: 252px; opacity: 0.55; }
.rings b { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); animation: pulse 2.6s var(--ease) infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ink) 28%, transparent); }
  70%, 100% { box-shadow: 0 0 0 26px transparent; }
}

/* Ficha del coche */
.place { display: grid; gap: 10px; }
.place h2 { font-size: 1.9rem; }
.specs { display: flex; gap: 36px; padding: 14px 0; border-block: 1px solid var(--line); margin-top: 4px; }
.specs dd { font-size: 1.3rem; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.note { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.banner { display: flex; align-items: baseline; gap: 10px; min-width: 0; overflow-wrap: anywhere; font-size: 0.94rem; font-weight: 500; }
.banner::before, .status::before {
  content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); transform: translateY(-1px);
}
.banner.ok::before, .status.ok::before { background: var(--ok); }
.banner.warn::before, .status.warn::before { background: var(--warn); }
.banner.danger::before { background: var(--danger); }
.banner.danger { color: var(--danger); }
.photo { border: 0; padding: 0; background: var(--fill); border-radius: 18px; overflow: hidden; cursor: zoom-in; display: block; }
.photo img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }

/* Mapas */
.map { position: relative; z-index: 0; background: var(--fill); width: 100%; }
.map.mini { flex: none; height: 30dvh; min-height: 180px; border: 0; padding: 0; display: block; cursor: pointer; border-radius: 24px; overflow: hidden; }
.map.edit { height: 34dvh; min-height: 200px; flex: none; border-radius: 24px; overflow: hidden; }
.map-off { display: grid; place-items: center; color: var(--muted); font-size: 0.9rem; text-align: center; padding: 12px; }
.leaflet-container { font: inherit; background: var(--fill); }
.leaflet-tile-pane { filter: grayscale(1) contrast(0.92) brightness(1.05); }
.leaflet-container .leaflet-control-attribution {
  font-size: 10px; padding: 2px 8px; border-radius: 999px; margin: 0 8px 8px 0;
  background: color-mix(in srgb, var(--bg) 78%, transparent); color: var(--muted);
}
.leaflet-container .leaflet-control-attribution a { color: inherit; }
.pin-car { color: var(--ink); }
.pin-car svg { filter: drop-shadow(0 4px 6px rgb(0 0 0 / 0.28)); }
.pin-me span {
  display: block; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 3px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.08), 0 2px 8px rgb(0 0 0 / 0.3);
}
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: grayscale(1) invert(1) contrast(0.86) brightness(0.92); }
}

/* Formulario */
.status { display: flex; align-items: baseline; gap: 10px; font-size: 0.9rem; color: var(--muted); }
.status.busy::before {
  width: 10px; height: 10px; background: none;
  border: 1.5px solid var(--ink); border-right-color: transparent;
  animation: spin 0.8s linear infinite; transform: none; align-self: center;
}
@keyframes spin { to { transform: rotate(360deg); } }
.addr { font-size: 1.35rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; overflow-wrap: anywhere; }
.addr:empty { display: none; }
.search { display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; }
input:not([type=file]), textarea {
  display: block; width: 100%; max-width: 100%; min-width: 0;
  -webkit-appearance: none; appearance: none; min-height: 50px; padding: 12px 16px;
  border: 1px solid transparent; border-radius: 14px; background: var(--fill);
  font-size: 16px; /* evita el zoom automático de iOS */
  letter-spacing: normal; text-transform: none; font-weight: 400; color: var(--ink);
  transition: border-color 0.2s var(--ease);
}
input:focus, textarea:focus { outline: none; border-color: var(--ink); }
::placeholder { color: var(--muted); opacity: 0.7; }
textarea { resize: none; }
input[type=time] { text-align: left; line-height: 24px; }
input[type=time]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type=time]::-webkit-datetime-edit { padding: 0; }
.results:empty { display: none; }
.results li { border-bottom: 1px solid var(--line); }
.results button { width: 100%; text-align: left; padding: 14px 0; border: 0; background: none; cursor: pointer; font-size: 0.94rem; }
.results .muted { padding: 14px 0; }
.fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; padding-top: 4px; min-width: 0; }
.fields label { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
.fields .row { gap: 12px; }
.photo-row { display: flex; align-items: center; gap: 12px; }
.fields .photo-btn { text-transform: none; letter-spacing: -0.005em; font-size: 0.94rem; font-weight: 500; color: var(--ink); display: inline-flex !important; }
#photo-preview { display: flex; align-items: center; gap: 4px; }
#photo-preview img { width: 50px; height: 50px; object-fit: cover; border-radius: 12px; }

/* Ruta */
.view-nav { padding: 0 !important; gap: 0 !important; overflow: hidden !important; }
.map.full { flex: 1; min-height: 0; }
.fab {
  position: absolute; right: 16px; top: 12px; z-index: 3;
  width: 46px; height: 46px; display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--bg); color: var(--ink); box-shadow: 0 2px 12px rgb(0 0 0 / 0.18); cursor: pointer;
}
.fab svg { width: 22px; height: 22px; }
.fab svg * { stroke-width: 1.6; }
.nav-panel {
  position: relative; z-index: 2;
  padding: 22px 24px calc(16px + var(--safe-b));
  display: grid; gap: 14px;
  background: var(--bg); border-top: 1px solid var(--line);
}
.nav-info { display: flex; align-items: center; gap: 18px; }
.dist { font-size: 2.1rem; font-weight: 600; letter-spacing: -0.035em; line-height: 1.1; }
.compass {
  flex: none; width: 60px; height: 60px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--line); color: var(--ink);
  transition: transform 0.15s linear;
}
.compass svg { width: 34px; height: 34px; }
.nav-panel .specs { margin: 0; }

/* Historial */
.history .card { padding: 20px 0; border-bottom: 1px solid var(--line); }
.history .card:first-child { padding-top: 4px; }
.card-body { display: grid; gap: 10px; }
.history h2 { font-size: 1.3rem; }
.history .row { margin-top: 6px; }
.history .row > .btn { flex: auto; padding-inline: 12px; }
.history .specs { border: 0; padding: 2px 0; }
.history .btn { min-height: 44px; font-size: 0.88rem; }

/* Crédito */
.credit {
  align-self: center; display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 10px; margin-top: 2px; border-radius: 999px;
  color: var(--muted); font-size: 0.74rem; letter-spacing: 0.02em; text-decoration: none;
  transition: color 0.2s var(--ease);
}
.credit img { width: 16px; height: 16px; border-radius: 4px; display: block; }
.credit b { font-weight: 600; color: var(--ink); }
.credit:active { color: var(--ink); }
.credit:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Foto ampliada y avisos */
.lightbox { position: fixed; inset: 0; z-index: 2000; background: rgb(0 0 0 / 0.94); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 64px); z-index: 3000;
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  width: max-content; max-width: min(88vw, 440px); padding: 11px 20px; border-radius: 22px;
  background: var(--ink); color: var(--bg); font-size: 0.9rem; font-weight: 500; text-align: center;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.2);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
