:root {
  --brand: #1a3a5c;
  --brand-light: #2e5f8a;
  --accent: #e8a33d;
  --ok: #2e7d32;
  --warn: #e65100;
  --bad: #c62828;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #64748b;
  --border: #dde3ea;
}

* { box-sizing: border-box; }

/* Avatar de foto de perfil (registro y ficha). Sin foto muestra el emoji. */
.avatar {
  width: 48px; height: 48px; flex: 0 0 auto;
  border-radius: 50%; background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; color: var(--muted); overflow: hidden;
  background-size: cover; background-position: center;
}
.avatar-lg { width: 72px; height: 72px; font-size: 2rem; cursor: pointer; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--brand) 0%, #0d1f33 100%);
}
.login-card {
  background: var(--card);
  border-radius: 12px;
  padding: 2.2rem;
  width: min(380px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card h1 {
  margin: 0 0 .2rem;
  color: var(--brand);
  letter-spacing: .12em;
  font-size: 1.7rem;
}
.login-card .tagline {
  color: var(--muted);
  font-size: .8rem;
  letter-spacing: .28em;
  text-transform: uppercase;
  margin-bottom: 1.6rem;
}

/* ---------- App shell ---------- */
header.appbar {
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1rem;
  position: sticky;
  top: 0;
  z-index: 1100;
}
header.appbar .logo { font-weight: 700; letter-spacing: .1em; }
header.appbar .who { margin-left: auto; font-size: .82rem; opacity: .9; text-align: right; }
header.appbar button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; }

nav.tabs {
  display: flex;
  overflow-x: auto;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 1090;
}
nav.tabs a {
  padding: .75rem 1.1rem;
  text-decoration: none;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
nav.tabs a.active { color: var(--brand); border-bottom-color: var(--accent); }

main { padding: 1rem; max-width: 1100px; margin: 0 auto; }

/* ---------- Componentes ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}
.card h2 { margin: 0 0 .8rem; font-size: 1.05rem; color: var(--brand); }
.card h3 { margin: 1rem 0 .4rem; font-size: .92rem; }

.grid { display: grid; gap: 1rem; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat { text-align: center; padding: 1rem .5rem; }
.stat .num { font-size: 1.9rem; font-weight: 700; color: var(--brand); }
.stat .lbl { color: var(--muted); font-size: .8rem; margin-top: .2rem; }

label { display: block; font-size: .84rem; font-weight: 600; margin: .7rem 0 .25rem; }
input, select, textarea {
  width: 100%;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--brand-light); border-color: transparent; }

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: .65rem 1.2rem;
  font-size: .95rem;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
}
button.secondary { background: #e9eef4; color: var(--brand); }
button.small { padding: .35rem .7rem; font-size: .8rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 1.2rem; }

.pill {
  display: inline-block;
  padding: .15rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
}
.pill.seguro { background: #e3f2e6; color: var(--ok); }
.pill.probable { background: #fff3e0; color: var(--warn); }
.pill.por_convencer { background: #fdecea; color: var(--bad); }
.pill.alta { background: #fdecea; color: var(--bad); }
.pill.media { background: #fff3e0; color: var(--warn); }

.affinity-picker { display: flex; gap: .5rem; }
.affinity-picker button {
  flex: 1;
  background: #e9eef4;
  color: var(--muted);
  padding: .55rem .3rem;
  font-size: .82rem;
}
.affinity-picker button.sel-seguro { background: var(--ok); color: #fff; }
.affinity-picker button.sel-probable { background: var(--warn); color: #fff; }
.affinity-picker button.sel-por_convencer { background: var(--bad); color: #fff; }

.consent-box {
  background: #f0f4f8;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .8rem;
  font-size: .82rem;
  margin-top: 1rem;
  display: flex;
  gap: .6rem;
  align-items: flex-start;
}
.consent-box input { width: auto; margin-top: .15rem; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }

.msg { padding: .7rem .9rem; border-radius: 8px; margin: .8rem 0; font-size: .9rem; }
.msg.ok { background: #e3f2e6; color: var(--ok); }
.msg.error { background: #fdecea; color: var(--bad); }
.msg.warn { background: #fff3e0; color: var(--warn); }

/* Aviso flotante breve (acciones del día D encoladas sin señal). */
#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translate(-50%, 1.5rem);
  max-width: min(92vw, 420px); padding: .7rem 1rem; border-radius: 10px;
  background: var(--text); color: #fff; font-size: .9rem; line-height: 1.3;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .28); z-index: 3200;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { background: var(--ok); }
#toast.warn { background: var(--warn); }
#toast.error { background: var(--bad); }

.offline-banner {
  background: var(--warn);
  color: #fff;
  text-align: center;
  padding: .4rem;
  font-size: .85rem;
  display: none;
}
body.offline .offline-banner { display: block; }

#map { height: calc(100vh - 210px); min-height: 380px; border-radius: 10px; }
.map-layers { display: flex; flex-wrap: wrap; gap: .9rem; margin-bottom: .7rem; font-size: .88rem; }
.map-layers label { display: flex; align-items: center; gap: .35rem; margin: 0; font-weight: 600; }
.map-layers input { width: auto; }

.alert-item { border-left: 4px solid var(--bad); padding: .5rem .8rem; margin-bottom: .5rem; background: #fff; border-radius: 0 8px 8px 0; border-top: 1px solid var(--border); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); font-size: .88rem; }
.alert-item.media { border-left-color: var(--warn); }

.mob-btns { display: flex; flex-wrap: wrap; gap: .3rem; }
.mob-btns button { background: #e9eef4; color: var(--text); padding: .3rem .55rem; font-size: .74rem; }
.mob-btns button.on { background: var(--brand); color: #fff; }

/* ---------- Metas por zona (semáforo) ---------- */
.semaforo {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  margin-right: .5rem;
  vertical-align: middle;
}
.semaforo.verde { background: var(--ok); }
.semaforo.amarillo { background: var(--warn); }
.semaforo.rojo { background: var(--bad); }
.semaforo.sin_meta { background: #cbd5e1; }
.meta-bar-track {
  background: #e9eef4; border-radius: 999px; height: 10px; overflow: hidden;
  margin-top: .25rem;
}
.meta-bar-fill { height: 100%; border-radius: 999px; transition: width .5s; }
.meta-bar-fill.verde { background: var(--ok); }
.meta-bar-fill.amarillo { background: var(--warn); }
.meta-bar-fill.rojo { background: var(--bad); }

/* ---------- Modo brigada (captura rápida) ---------- */
.brigada-form input {
  font-size: 1.2rem;
  padding: .85rem .8rem;
}
.brigada-save {
  width: 100%;
  padding: 1rem;
  font-size: 1.15rem;
  margin-top: .8rem;
}
.brigada-counter {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--brand);
  line-height: 1;
}
.brigada-flash-ok { animation: flashok .5s; }
.brigada-flash-dup { animation: flashdup .6s; }
@keyframes flashok { 0% { background: #e3f2e6; } 100% { background: transparent; } }
@keyframes flashdup { 0%, 50% { background: #fdecea; } 100% { background: transparent; } }

/* ---------- Modo jornada (día D) ---------- */
.jornada-hero {
  text-align: center;
  padding: 1.4rem 1rem;
}
.jornada-hero .pct {
  font-size: 4.2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--brand);
}
.jornada-hero .lbl { color: var(--muted); font-size: .95rem; margin-top: .3rem; }
.progress-track {
  background: #e9eef4;
  border-radius: 999px;
  height: 14px;
  overflow: hidden;
}
.progress-fill {
  background: var(--brand);
  height: 100%;
  border-radius: 999px;
  transition: width .6s ease;
}
.progress-mini { height: 8px; }
.jornada-num { font-size: 2rem; font-weight: 700; color: var(--text); }
.feed-item {
  padding: .45rem .2rem;
  border-bottom: 1px solid var(--border);
  font-size: .86rem;
  display: flex;
  gap: .6rem;
  align-items: baseline;
}
.feed-item time { color: var(--muted); font-size: .76rem; white-space: nowrap; }
.route-chip {
  display: inline-block;
  padding: .35rem .7rem;
  border-radius: 8px;
  background: #e9eef4;
  font-size: .84rem;
  margin: 0 .4rem .4rem 0;
}
.route-chip.full { background: #fdecea; color: var(--bad); font-weight: 700; }

@media (max-width: 640px) {
  main { padding: .6rem; }
  nav.tabs { top: 48px; }
  #map { height: calc(100vh - 240px); }
}
