/* Ciudadanos: lenguaje vial. Overpass deriva de la tipografía de las señales de ruta;
   las direcciones se muestran como placas de calle; el amarillo es el de la demarcación. */

@font-face { font-family: Overpass; src: url(/fonts/overpass-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: Overpass; src: url(/fonts/overpass-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: Overpass; src: url(/fonts/overpass-800.woff2) format("woff2"); font-weight: 800; font-display: swap; }

:root {
  --asphalt: #2e3338;
  --asphalt-2: #41474e;
  --concrete: #eceeeb;
  --paper: #fafbf9;
  --line: #d4d8d3;
  --ink: #1f2428;
  --muted: #5d656c;
  --marking: #f2b705;          /* amarillo de demarcación: acción principal */
  --marking-ink: #241c00;
  --sign: #1d4f91;             /* azul de cartel: placas de calle */
  --sign-ink: #ffffff;
  --event: #d7263d;
  --problem: #e07a00;
  --ok: #1d8f55;
  --error: #b3162b;
  --note-bg: #fff4cc;
  --note-ink: #5a4300;
  --focus: #1d4f91;

  --font: Overpass, "Segoe UI", Roboto, system-ui, sans-serif;
  /* Escala tipográfica (cuarta justa aproximada) */
  --t-xs: 13px;
  --t-s: 15px;
  --t-m: 17px;
  --t-l: 21px;
  --t-xl: 28px;
  --t-xxl: 40px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --concrete: #1d2125;
    --paper: #262b30;
    --line: #3d444b;
    --ink: #eef1ee;
    --muted: #a9b1b8;
    --asphalt: #eef1ee;        /* elementos "oscuros" se invierten */
    --asphalt-2: #c9d0d6;
    --error: #ff8a97;
    --note-bg: #3a3112;
    --note-ink: #ffe28a;
    --focus: #f2b705;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: var(--t-m)/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

h1 { margin: 0; font-size: var(--t-l); font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
h2 { margin: 18px 0 8px; font-size: var(--t-s); font-weight: 800; }
h2 small { margin-left: 6px; color: var(--muted); font-size: var(--t-xs); font-weight: 400; }

/* ---------- Placa de calle: el elemento distintivo ---------- */

.plate {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  border-radius: 6px;
  background: var(--sign);
  color: var(--sign-ink);
  /* filete blanco interior, como en un cartel real */
  box-shadow: inset 0 0 0 2px var(--sign), inset 0 0 0 3.5px rgb(255 255 255 / .85);
  font-weight: 800;
  line-height: 1.15;
}
.plate-name { padding: 7px 10px 6px 11px; overflow-wrap: anywhere; }
.plate-num {
  flex: none;
  align-self: center;
  margin: 4px 4px 4px 0;
  padding: 3px 8px 2px;
  border-radius: 3px;
  background: var(--sign-ink);
  color: var(--sign);
  font-variant-numeric: tabular-nums;
}
.plate-city { display: block; margin-top: 4px; color: var(--muted); font-size: var(--t-xs); }
.plate-small { font-size: var(--t-s); }
.plate-small .plate-name { padding: 5px 9px 4px 10px; }

/* ---------- Bienvenida (sin sesión) ---------- */

#welcome { display: none; }
body[data-auth="out"] #welcome { display: flex; }
body:not([data-auth="in"]) #map-area,
body:not([data-auth="in"]) #sheet { display: none; }

#welcome {
  position: relative;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  overflow-y: auto;
  padding: calc(32px + env(safe-area-inset-top)) 24px calc(32px + env(safe-area-inset-bottom)) 56px;
  background: #2e3338;
  color: #f4f5f2;
}
/* Línea de carril: la única animación de la app, una vez al cargar */
#welcome::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 26px;
  width: 6px;
  background: repeating-linear-gradient(to bottom, #f2b705 0 46px, transparent 46px 80px);
  animation: lane 1.1s cubic-bezier(.2, .7, .2, 1) both;
}
@keyframes lane { from { background-position-y: -160px; opacity: 0; } to { background-position-y: 0; opacity: 1; } }

.welcome-box { width: 100%; max-width: 30rem; }
.welcome-brand { margin-bottom: 28px; font-size: var(--t-m); }
.welcome-box h1 {
  max-width: 13ch;
  font-size: var(--t-xxl);
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.welcome-lead { max-width: 34ch; margin: 16px 0 28px; color: #c9cfd3; font-size: var(--t-m); }
.welcome-small { max-width: 38ch; margin: 18px 0 0; color: #9aa3aa; font-size: var(--t-xs); }
#welcome .error { color: #ff9aa5; }
#welcome .note { background: #4a3e14; color: #ffe28a; }

@media (min-width: 800px) {
  #welcome { justify-content: center; padding-left: 15vw; }
  #welcome::before { left: calc(15vw - 34px); }
  .welcome-box h1 { font-size: 56px; }
}

/* ---------- Mapa ---------- */

#map-area { position: relative; flex: 1 1 auto; min-height: 180px; }
#map { position: absolute; inset: 0; background: #dfe3df; font-family: var(--font); }

#topbar {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 20px);
  padding: 4px 12px 4px 4px;
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 1px 4px rgb(0 0 0 / .28);
  font-size: var(--t-xs);
}
.counts { display: flex; gap: 12px; color: var(--ink); font-weight: 600; white-space: nowrap; }
.count { display: inline-flex; align-items: center; gap: 6px; }
.count::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--event); }
.count-problem::before { border-radius: 2px; background: var(--problem); }

.map-button {
  position: absolute;
  right: 10px;
  bottom: 28px;
  z-index: 500;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 10px;
  background: var(--paper);
  color: var(--sign);
  box-shadow: 0 1px 4px rgb(0 0 0 / .3);
  cursor: pointer;
}

/* La punta del pin marca exactamente el centro del mapa */
#center-pin {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 450;
  transform: translate(-50%, -100%);
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgb(0 0 0 / .4));
}

/* ---------- Hoja inferior ---------- */

#sheet {
  position: relative;
  z-index: 600;
  flex: 0 1 auto;
  max-height: 64dvh;
  overflow-y: auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 4px solid var(--marking);
  box-shadow: 0 -2px 10px rgb(0 0 0 / .18);
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 800px) {
  body { flex-direction: row-reverse; }
  #sheet {
    flex: 0 0 420px;
    max-height: none;
    padding: 22px 22px 22px;
    border-top: 0;
    border-right: 4px solid var(--marking); /* entre el panel y el mapa */
    box-shadow: none;
  }
  .map-button { bottom: 30px; }
}

.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.place { margin: 8px 0 0; color: var(--muted); font-size: var(--t-s); min-height: 20px; overflow-wrap: anywhere; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: var(--t-xs); }

.status { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; color: var(--muted); font-size: var(--t-s); }
.status::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--status-color, #9aa3aa);
}
.status[data-state="good"] { --status-color: var(--ok); }
.status[data-state="poor"] { --status-color: var(--problem); }
.status[data-state="off"] { --status-color: var(--event); }

/* ---------- Botones ---------- */

.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 11px 14px 9px;
  border: 0;
  border-radius: 10px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.btn + .btn { margin-top: 8px; }
.btn-large { min-height: 58px; font-size: var(--t-l); }
.btn-primary { background: var(--marking); color: var(--marking-ink); }
.btn-primary:active { filter: brightness(.94); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-secondary {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line);
  font-weight: 600;
}
.btn-text {
  flex: none;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--sign);
  font: inherit;
  font-size: var(--t-s);
  font-weight: 800;
  cursor: pointer;
}
@media (prefers-color-scheme: dark) { .btn-text { color: #8fb8ee; } .map-button { color: #8fb8ee; } }
a.btn { text-align: center; text-decoration: none; }

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-width: 24rem;
  background: #ffffff;
  color: #1f1f1f;
}

.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

/* Cantidad de controles vigentes: mismo rojo que los eventos del mapa */
#open-controls { position: relative; }
.count-badge {
  position: absolute;
  top: -10px;
  right: -6px;
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 3px 8px 0;
  box-shadow: 0 0 0 3px var(--paper);
  border-radius: 13px;
  background: var(--event);
  color: #fff;
  font-size: var(--t-xs);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.count-badge-zero { background: var(--concrete); color: var(--muted); }
/* Responde a un control nuevo: una sola vez, muestra qué cambió */
.count-badge-bump { animation: bump .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.45); } 100% { transform: scale(1); } }
.home-actions .btn { margin: 0; min-height: 52px; font-size: var(--t-s); line-height: 1.2; }

.account {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: var(--t-s);
}
.account:empty { display: none; }
.account-name { flex: 1; min-width: 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.account a { color: var(--sign); font-weight: 800; }
@media (prefers-color-scheme: dark) { .account a { color: #8fb8ee; } }
#banned-note { margin-top: 0; }

/* ---------- Tipos de reporte: la forma repite la del marcador del mapa ---------- */

.categories { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.category {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 84px;
  padding: 10px 3px 8px;
  border: 0;
  border-radius: 12px;
  background: var(--concrete);
  color: var(--ink);
  font: inherit;
  font-size: var(--t-xs);
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
}
.category .icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 3px solid var(--event);
  border-radius: 50%;
  background: #fff;
  font-size: 19px;
  line-height: 1;
}
.category-problem .icon { border-color: var(--problem); border-radius: 9px; }
.category[aria-pressed="true"] {
  background: #2e3338;
  color: #fff;
  font-weight: 800;
  box-shadow: inset 0 0 0 3px var(--marking);
}
@media (prefers-color-scheme: dark) {
  .category[aria-pressed="true"] { background: var(--marking); color: var(--marking-ink); box-shadow: none; }
}

/* ---------- Formularios ---------- */

.field { display: block; margin: 14px 0 5px; font-size: var(--t-s); font-weight: 800; }
.field span { color: var(--muted); font-weight: 400; }
input, textarea {
  display: block;
  width: 100%;
  padding: 12px 12px 10px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px evita el zoom automático de iOS al enfocar */
}
input:focus, textarea:focus { border-color: var(--sign); outline: none; }
textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: end; }
.field-row .or { padding-bottom: 14px; color: var(--muted); font-size: var(--t-s); }
#view-report > .btn, #view-manual > .btn-primary { margin-top: 16px; }

/* Enviar siempre a la vista: reportar son dos toques (tipo y enviar), sin hacer scroll */
#report-send {
  position: sticky;
  bottom: 0;
  z-index: 1;
  box-shadow: 0 0 0 8px var(--paper), 0 26px 0 8px var(--paper);
}

.note {
  margin: 12px 0 0;
  padding: 9px 12px 8px;
  border-left: 4px solid var(--marking);
  border-radius: 0 8px 8px 0;
  background: var(--note-bg);
  color: var(--note-ink);
  font-size: var(--t-s);
}
.error { margin: 12px 0 0; color: var(--error); font-size: var(--t-s); font-weight: 800; }

.results { margin: 12px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.results li { border-bottom: 1px solid var(--line); }
.results button {
  display: block;
  width: 100%;
  padding: 12px 2px;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.results small { display: block; margin-top: 4px; color: var(--muted); font-size: var(--t-xs); }

/* ---------- Listado de controles ---------- */

.control-list { margin: 14px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.control-list li { border-bottom: 1px solid var(--line); }
.control-item {
  display: block;
  width: 100%;
  padding: 14px 2px 12px;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.control-item .detail { display: block; margin-top: 8px; font-size: var(--t-s); overflow-wrap: anywhere; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; color: var(--muted); font-size: var(--t-xs); }
.facts .near { color: var(--ink); font-weight: 800; }
.empty { margin: 18px 0 4px; color: var(--muted); }

/* ---------- Marcadores ---------- */

.marker {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 3px solid var(--marker-color);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgb(0 0 0 / .45);
  font-size: 18px;
  line-height: 1;
}
.marker-event { --marker-color: #d7263d; }
.marker-problem { --marker-color: #e07a00; border-radius: 9px; }

.user-dot {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #1a73e8;
  box-shadow: 0 0 4px rgb(0 0 0 / .5);
}

.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-container { font-family: var(--font); }
.popup { min-width: 200px; font-family: var(--font); }
.popup h3 { margin: 0 0 8px; font-size: var(--t-m); font-weight: 800; }
.popup .plate { font-size: var(--t-s); }
.popup p { margin: 8px 0 0; font-size: var(--t-s); overflow-wrap: anywhere; }
.popup .facts { color: #5d656c; }
.popup .meta { color: #5d656c; font-size: var(--t-xs); }

/* ---------- Aviso flotante ---------- */

#toast {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  z-index: 1000;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 11px 16px 9px;
  border-left: 5px solid var(--marking);
  border-radius: 8px;
  background: #2e3338;
  color: #fff;
  font-size: var(--t-s);
  font-weight: 800;
  transform: translateX(-50%);
  box-shadow: 0 2px 10px rgb(0 0 0 / .35);
}
#toast:not([hidden]) { display: flex; align-items: center; gap: 14px; }
#toast-action {
  flex: none;
  min-height: 36px;
  padding: 5px 14px 3px;
  border: 0;
  border-radius: 6px;
  background: var(--marking);
  color: var(--marking-ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* ---------- Panel de administración: página normal, sin mapa ---------- */

body.page { display: block; height: auto; overflow: auto; background: var(--paper); }
.admin { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; }
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 4px solid var(--marking);
}
.admin-head h1 { font-size: var(--t-xl); }
.admin-head a { color: var(--sign); font-weight: 800; }
.user-list { margin: 14px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.user-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
}
.user-card .who { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.user-card p { margin: 2px 0 0; color: var(--muted); font-size: var(--t-s); }
.user-card .btn { flex: 0 0 auto; width: auto; min-height: 44px; }
.badge { margin-left: 6px; padding: 2px 8px 1px; border-radius: 4px; background: var(--concrete); font-size: var(--t-xs); font-weight: 800; }
.badge-banned { background: var(--event); color: #fff; }
.btn-danger { background: var(--event); color: #fff; }
dialog {
  width: min(420px, calc(100% - 32px));
  border: 0;
  border-top: 4px solid var(--event);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgb(0 0 0 / .55); }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 14px 0; font-size: var(--t-s); }
.check input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; }
.dialog-actions { display: flex; gap: 8px; margin-top: 12px; }
.dialog-actions .btn { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
