:root {
  color-scheme: light dark;
  --magenta: #d6249b;
  --purple: #7b2ff7;
  --blue: #2b5cf6;
  --gradient: linear-gradient(115deg, var(--magenta) 0%, var(--purple) 55%, var(--blue) 100%);
  --accent: var(--purple);
  --bg: #f2f3f7;
  --card-bg: #ffffff;
  --text: #17181c;
  --text-muted: #767a86;
  --border: #e4e6ec;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.04), 0 8px 24px rgba(20, 20, 40, 0.06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1015;
    --card-bg: #191a21;
    --text: #eceef3;
    --text-muted: #8b8e9a;
    --border: #2a2c36;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1015;
  --card-bg: #191a21;
  --text: #eceef3;
  --text-muted: #8b8e9a;
  --border: #2a2c36;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.35);
}
:root[data-theme="light"] {
  --bg: #f2f3f7;
  --card-bg: #ffffff;
  --text: #17181c;
  --text-muted: #767a86;
  --border: #e4e6ec;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.04), 0 8px 24px rgba(20, 20, 40, 0.06);
}

* { box-sizing: border-box; }

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

/* ---- Topbar / marca ---- */
.topbar {
  background: #000;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1.1rem clamp(1rem, 4vw, 2.5rem);
  flex-wrap: wrap;
}
.marca { display: flex; align-items: center; gap: 0.7rem; }
.marca-icono {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.marca-icono img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.marca-icono-fallback {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.marca-icono-fallback .barra {
  width: 9px;
  height: 40px;
  background: var(--gradient);
  transform: skewX(-12deg);
  border-radius: 2px;
}
.marca-icono-fallback .barra-2 { height: 44px; opacity: 0.92; }
.marca-icono-fallback .barra-3 { height: 36px; opacity: 0.85; }
.marca-texto {
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.15;
  letter-spacing: 0.02em;
  font-style: italic;
}
.titulo-app { margin-left: auto; text-align: right; }
.titulo-app h1 { margin: 0; font-size: 1.3rem; font-weight: 700; }
.titulo-app .subtitulo { margin: 0.15rem 0 0; color: #b8bac2; font-size: 0.85rem; }
.titulo-app .sesion-info { margin: 0.3rem 0 0; color: #b8bac2; font-size: 0.8rem; }
.titulo-app .sesion-info a { color: #fff; }

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .titulo-app { margin-left: 0; text-align: left; }
}

/* ---- Layout ---- */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.8rem 1.2rem 0;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.6rem 1.7rem;
}
#form-section {
  max-width: 560px;
}
.card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 700;
}

/* ---- Form ---- */
.campo { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.campo:last-of-type { margin-bottom: 1.3rem; }
.campo-rango-fechas { flex-direction: row; gap: 0.8rem; }
.campo-rango-fechas > div { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.campo-ayuda { margin: -0.5rem 0 1rem; font-size: 0.8rem; }
.campo-vendedor { display: flex; align-items: center; gap: 0.7rem; }
.avatar-vendedor { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; object-fit: cover; border: 1.5px solid var(--border); }
.campo-vendedor select { flex: 1; }

.badge-ubicacion {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-ubicacion-ok { background: rgba(15, 157, 107, 0.15); color: #0f9d6b; }
.badge-ubicacion-alerta { background: rgba(224, 53, 107, 0.15); color: #e0356b; }
label { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
select, input {
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
select:focus, input:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(123, 47, 247, 0.15);
}

button {
  background: var(--gradient);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(123, 47, 247, 0.3);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(123, 47, 247, 0.4); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn-link {
  background: none;
  border: none;
  color: var(--purple);
  padding: 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  box-shadow: none;
}
.btn-link:hover:not(:disabled) { transform: none; box-shadow: none; opacity: 0.8; }
.btn-link.btn-peligro { color: #e0356b; }
.btn-link:disabled { color: var(--text-muted); text-decoration: none; opacity: 1; }

#mensaje, .mensaje-error { color: #e0356b; font-size: 0.88rem; margin-top: 0.6rem; }
.texto-tenue { color: var(--text-muted); font-size: 0.85rem; }

/* ---- Tables ---- */
.tabla-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin: 0.2rem 0; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.6rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 700; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: rgba(123, 47, 247, 0.06); }
tbody tr:last-child td { border-bottom: none; }
.celda-visita {
  white-space: nowrap;
  position: sticky;
  right: 0;
  background: var(--card-bg);
  box-shadow: -6px 0 6px -6px rgba(0, 0, 0, 0.2);
}

a { color: var(--purple); font-weight: 600; }

#resumen { color: var(--text-muted); font-size: 0.92rem; }
#resumen strong { color: var(--text); }

#link-maps {
  display: inline-block;
  margin-top: 0.8rem;
  text-decoration: none;
  padding: 0.5rem 0;
}

/* ---- Giros (chips) ---- */
.giros-toolbar { margin-bottom: 0.5rem; }
.lista-checks {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.chip-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  background: var(--card-bg);
}
.chip-check input { margin: 0; accent-color: var(--purple); }

/* ---- Modal visita ---- */
dialog#modal-visita {
  border: none;
  border-radius: var(--radius);
  padding: 1.6rem 1.7rem;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: var(--shadow);
  width: min(460px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
}
dialog#modal-visita::backdrop {
  background: rgba(10, 10, 20, 0.55);
}
dialog#modal-visita h2 {
  margin: 0 0 0.2rem;
  font-size: 1.1rem;
}
.separador-opcional {
  margin: 1.2rem 0 0.8rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.modal-acciones {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1.2rem;
}
.btn-secundario {
  background: none;
  color: var(--text);
  border: 1.5px solid var(--border);
  box-shadow: none;
}
.btn-secundario:hover:not(:disabled) {
  transform: none;
  box-shadow: none;
  background: var(--bg);
}

/* ---- Login ---- */
.contenedor-login {
  min-height: calc(100vh - 2rem);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.card-login {
  width: min(360px, 100%);
  text-align: center;
}
.marca-login { justify-content: center; margin-bottom: 1rem; }
.card-login h1 { font-size: 1.15rem; margin: 0 0 1.4rem; }
.card-login .campo { text-align: left; }
.card-login button { width: 100%; margin-top: 0.4rem; }

/* ---- Menu principal ---- */
.menu-tarjetas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.2rem;
  max-width: 900px;
}
.tarjeta-menu {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.tarjeta-menu:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 18px rgba(123, 47, 247, 0.18);
}
.tarjeta-menu h2 { color: var(--purple); }

/* ---- Simulador ---- */
.modo-simulador { flex-direction: column; max-height: none; }
.modo-simulador .chip-check { border-radius: 12px; }
.resultado-principal { font-size: 1.3rem; font-weight: 700; margin: 0 0 0.4rem; }

/* ---- Vendedor: encabezado del resultado con boton de imprimir ---- */
.resultado-encabezado { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.resultado-encabezado h2 { margin: 0; }
.solo-imprimir { display: none; }

/* ---- Impresion (vista de vendedor) ---- */
@media print {
  .no-imprimir, .topbar { display: none !important; }
  .solo-imprimir { display: block !important; }
  body { background: #fff; padding: 0; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: none; padding: 0; }
  table { font-size: 0.85rem; }
}
