/* Control de Visitas · Importadora Universal
   Diseño móvil primero: el vendedor trabaja desde el teléfono, en la calle y con una mano. */
:root {
  --navy: #14284b;
  --navy-2: #1e3a66;
  --gold: #c9a227;
  --gold-soft: #f6eccb;
  --bg: #f3f4f7;
  --card: #ffffff;
  --text: #1b2230;
  --muted: #5d6677;
  --line: #dde1e8;
  --ok: #1d7a46;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff2d6;
  --err: #b42318;
  --err-bg: #fde8e6;
  --radius: 12px;
  --tap: 48px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
a { color: var(--navy-2); }
h1 { font-size: 1.35rem; margin: .4rem 0 1rem; color: var(--navy); }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; color: var(--navy); }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; }

/* ---------- Barra superior ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; border-bottom: 3px solid var(--gold); }
.topbar-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; }
.brand-mark { background: var(--gold); color: var(--navy); font-weight: 800; border-radius: 8px; padding: 4px 8px; letter-spacing: .5px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: 40px; }
.menu summary::-webkit-details-marker { display: none; }
.menu .who { font-size: .9rem; opacity: .9; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu .burger { font-size: 1.3rem; }
.menu nav { position: absolute; right: 0; top: 46px; background: #fff; border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.18); min-width: 220px; padding: 6px; display: flex; flex-direction: column; }
.menu nav a { color: var(--text); text-decoration: none; padding: 12px 14px; border-radius: 8px; }
.menu nav a:hover, .menu nav a.active { background: var(--gold-soft); color: var(--navy); font-weight: 600; }

.container { max-width: 1200px; margin: 0 auto; padding: 16px; padding-bottom: 48px; }
.container.narrow, .narrow { max-width: 560px; }
.page-plain { padding-top: 24px; }

/* ---------- Tarjetas y formularios ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card-title { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.form label, label.field { display: block; font-weight: 600; margin-bottom: 12px; }
.form label > input, .form label > select, .form label > textarea,
label.field > input, label.field > select, label.field > textarea { margin-top: 6px; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; padding: 11px 12px; min-height: var(--tap);
  border: 1px solid #c4cad5; border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(201,162,39,.35); border-color: var(--gold); }
select:disabled { background: #eef0f4; color: var(--text); opacity: 1; }
textarea { min-height: 90px; resize: vertical; }
.req { color: var(--err); }
.hint { font-weight: 400; font-size: .85rem; color: var(--muted); display: block; margin-top: 4px; }
.field-error { color: var(--err); font-weight: 600; font-size: .9rem; margin-top: 6px; }
.invalid { border-color: var(--err) !important; outline: 2px solid rgba(180,35,24,.2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; letter-spacing: .02em;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn-danger { background: var(--err); color: #fff; }
.btn-block { width: 100%; }
.btn-xl { min-height: 58px; font-size: 1.05rem; text-transform: uppercase; }
.btn[disabled], .btn.busy { opacity: .6; cursor: progress; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Alertas y etiquetas ---------- */
.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; border: 1px solid transparent; }
.alert-ok, .alert-success { background: var(--ok-bg); color: var(--ok); border-color: #b9e2c9; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: #f1d796; }
.alert-error { background: var(--err-bg); color: var(--err); border-color: #f5c2bc; }
.alert-info { background: #e8eef9; color: var(--navy); border-color: #c8d5ee; }
.alert strong { display: block; }
.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-neutral { background: #e8eef9; color: var(--navy); }
.badge-muted { background: #eceef2; color: var(--muted); }

/* ---------- Registro de visita ---------- */
.today { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--navy); color: #fff; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }
.today .day { font-size: 1.25rem; font-weight: 800; color: var(--gold); }
.search-results { list-style: none; margin: 8px 0 0; padding: 0; }
.search-results li button {
  width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 6px; font: inherit; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.search-results li button:hover { border-color: var(--gold); }
.search-results .code { font-weight: 800; color: var(--navy); margin-right: 6px; }
.customer-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.customer-head .code { font-weight: 800; color: var(--navy); }
.customer-head .name { font-size: 1.1rem; font-weight: 700; }
.coords { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice { position: relative; display: block; }
.choice input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; min-height: 0; padding: 0; margin: 0; opacity: 0; pointer-events: none; }
.choice span {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 52px; padding: 8px;
  border: 2px solid var(--line); border-radius: 10px; background: #fff; font-weight: 700; cursor: pointer;
}
.choice input:checked + span { border-color: var(--navy); background: var(--navy); color: #fff; }
.choice input:focus-visible + span { outline: 3px solid rgba(201,162,39,.5); }
.choices.week .choice input:checked + span { background: var(--gold); color: var(--navy); border-color: var(--gold); }
.done { text-align: center; }
.done .check { font-size: 2.6rem; color: var(--ok); line-height: 1; }
.done dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; text-align: left; margin: 14px 0; }
.done dt { color: var(--muted); }
.done dd { margin: 0; font-weight: 600; }
.hidden { display: none !important; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f7f8fa; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 800; background: #f7f8fa; }

/* En el teléfono, las tablas de historial se leen como tarjetas */
@media (max-width: 760px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.stack td { border: 0; padding: 3px 8px; display: flex; justify-content: space-between; gap: 12px; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; font-weight: 600; flex-shrink: 0; }
  table.stack td.wrap { display: block; }
  table.stack td.wrap::before { display: block; }
}

/* ---------- Filtros y panel ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.filters label { margin: 0; font-size: .85rem; }
.filters .actions { display: flex; gap: 8px; flex-wrap: wrap; grid-column: 1 / -1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; border-top: 4px solid var(--navy); }
.kpi.gold { border-top-color: var(--gold); }
.kpi .v { font-size: 1.7rem; font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.grid-2 { display: grid; gap: 14px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 14px 0; }
.log { background: #0f1b33; color: #d7e3ff; padding: 14px; border-radius: 10px; white-space: pre-wrap; font-size: .9rem; }
.inline-form { display: inline; }
.login-wrap { max-width: 400px; margin: 8vh auto 0; }
.login-wrap .brand-big { text-align: center; margin-bottom: 18px; }
.login-wrap .brand-big .brand-mark { font-size: 1.6rem; padding: 8px 14px; }
.brand-logo { width: 40px; height: 40px; border-radius: 10px; background: #fff; padding: 2px; flex: none; display: block; }
.login-logo { display: block; width: 240px; max-width: 70vw; height: auto; margin: 0 auto 4px; background: #fff; border-radius: 20px; padding: 10px; box-shadow: 0 2px 10px rgba(20, 40, 75, .10); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Mapa ---------- */
.map-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.map { height: calc(100vh - 230px); min-height: 380px; border-radius: var(--radius); border: 1px solid var(--line); background: #e8ecf1; z-index: 1; }
.mini-map { height: 240px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 8px; z-index: 1; }
.map-results { margin: -6px 0 10px; }
.map-results:empty { display: none; }
.map-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; margin: 10px 0 4px; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.pop { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.pop > div { margin-bottom: 3px; }
.pop-code { font-weight: 800; color: var(--navy); }
.pop-name { font-size: 1.02rem; font-weight: 700; }
.pop-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px !important; }
.pop-actions .btn { min-height: 36px; padding: 6px 10px; font-size: .85rem; }
.leaflet-container a.btn-primary { color: #fff; }
.leaflet-container a.btn-gold, .leaflet-container a.btn-ghost { color: var(--navy); }
@media (max-width: 760px) {
  .map { height: 65vh; }
  .map-filters { grid-template-columns: 1fr 1fr; }
}

/* ---------- Llamadas de Televentas ---------- */
.call-list { display: grid; gap: 10px; }
@media (min-width: 980px) { .call-list { grid-template-columns: 1fr 1fr; } }
.call-card { margin: 0; border-left: 5px solid var(--gold); }
.call-card.state-reintentar { border-left-color: var(--navy-2); }
.call-card.state-gestionado { border-left-color: var(--ok); opacity: .9; }
.call-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.call-top .code { font-weight: 800; color: var(--navy); font-size: .9rem; }
.call-top .name { font-size: 1.08rem; font-weight: 700; }
.call-visit { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin: 8px 0 4px; font-size: .9rem; }
.last-call { background: #f7f8fa; border-radius: 8px; padding: 6px 8px; margin-top: 6px; }
.call-actions { margin-top: 10px; }
.call-form { margin-top: 10px; }
.call-form summary { cursor: pointer; font-weight: 700; color: var(--navy-2); padding: 6px 0; }
.call-form .choices { margin: 8px 0 12px; }
.copy-field { display: flex; gap: 8px; }
.copy-field input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.switch-row { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; }
.switch-row input { width: auto; min-height: 0; margin-top: 4px; transform: scale(1.3); }
.call-actions .badge { align-self: center; white-space: normal; }
