/* Sígueme PE */
:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --text: #17211e;
  --muted: #63706c;
  --border: #e1e7e4;
  --primary: #0f5c4d;
  --primary-600: #0b4a3e;
  --primary-50: #e7f2ef;
  --accent: #e8622c;
  --accent-600: #cc5020;
  --danger: #c4322b;
  --danger-50: #fdecea;
  --success: #15803d;
  --success-50: #e8f6ed;
  --warn: #b7791f;
  --warn-50: #fdf5e6;
  --info-50: #eaf2fb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .05), 0 1px 3px rgba(16, 24, 20, .06);
  --sidebar: 248px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }
h4 { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: .75rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
.center { text-align: center; }
.accent { color: var(--accent); }
.ico { width: 20px; height: 20px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: #0d2d27; color: #d5e3df;
  display: flex; flex-direction: column; z-index: 50; transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.25rem; color: #fff; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--accent); }
.sidebar nav { flex: 1; overflow-y: auto; padding: .5rem .75rem; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; border-radius: var(--radius-sm); color: #c2d4cf; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.sidebar nav a.active .ico { color: var(--accent); }
.sidebar-foot { display: flex; align-items: center; gap: .5rem; padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.08); }
.who { flex: 1; min-width: 0; }
.who strong, .who small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who strong { color: #fff; font-size: .9rem; }
.who small { color: #8fa9a2; }
.logout { color: #c2d4cf; padding: .4rem; border-radius: 6px; }
.logout:hover { background: rgba(255,255,255,.08); color: #fff; }

.main { flex: 1; margin-left: var(--sidebar); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem;
  padding: .85rem 1.5rem; background: rgba(244,246,245,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; font-size: 1.2rem; margin: 0; }
.topbar-actions { display: flex; gap: .5rem; }
.icon-btn { display: none; background: none; border: 0; padding: .35rem; border-radius: 8px; color: var(--text); cursor: pointer; }
.content { padding: 1.25rem 1.5rem 3rem; display: flex; flex-direction: column; gap: 1rem; max-width: 1400px; width: 100%; }
.content--bare { min-height: 100vh; display: grid; place-items: center; padding: 1rem; max-width: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .nav-open .sidebar { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
  .main { margin-left: 0; }
  .icon-btn { display: inline-flex; }
  .topbar { padding: .7rem 1rem; }
  .topbar-actions .btn { padding: .45rem .7rem; font-size: .85rem; }
  .content { padding: 1rem 1rem 3rem; }
}

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: .85rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.form-narrow { max-width: 860px; }
@media (max-width: 760px) { .grid-2, .grid-side { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .87rem; font-weight: 600; color: #34413d; }
label.inline { flex-direction: row; align-items: center; gap: .4rem; font-weight: 500; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid #cdd6d2; border-radius: var(--radius-sm); padding: .6rem .7rem; min-height: 42px;
}
textarea { resize: vertical; min-height: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); margin: 0; flex: none; }
input[type=file] { padding: .45rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem 1rem 1rem; margin: 0; }
legend { font-weight: 700; padding: 0 .35rem; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .45rem 1rem; }
.help { background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: .65rem .8rem; font-size: .85rem; color: var(--muted); margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .9rem;
  padding: .55rem 1rem; border-radius: var(--radius-sm); border: 1px solid #cdd6d2; background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; line-height: 1.2; min-height: 38px;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-600); }
.btn-danger { color: var(--danger); border-color: #efc4c1; }
.btn-danger:hover { background: var(--danger-50); }
.btn-primary.btn-danger, .tracker .btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; min-height: 30px; }
.btn-lg { padding: .85rem 1.2rem; font-size: 1rem; min-height: 52px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn-row form, .row-actions form { display: inline; margin: 0; }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; flex-wrap: wrap; }

.alert { padding: .7rem 1rem; border-radius: var(--radius-sm); border: 1px solid; font-size: .9rem; }
.alert-success { background: var(--success-50); border-color: #b9e2c7; color: #14532d; }
.alert-error { background: var(--danger-50); border-color: #f2c3bf; color: #7f1d1d; }
.alert-info { background: var(--info-50); border-color: #c6dbf3; color: #1e3a5f; }

.badge, .tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; white-space: nowrap; }
.tag { background: #eef1f0; color: #3e4b47; }
.tag-lg { font-size: .85rem; padding: .25rem .75rem; }
.badge-admin { background: #ece8fb; color: #4c2ca8; }
.badge-supervisor { background: #e4effb; color: #1d4f91; }
.badge-agente, .badge-ventas { background: var(--primary-50); color: var(--primary); }
.badge-cobranza { background: #fdeee6; color: #a8431a; }
.badge-otro { background: #eef1f0; color: #3e4b47; }

.table-wrap { overflow-x: auto; margin: 0 -1.25rem; padding: 0 1.25rem; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: .55rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: .65rem .6rem; border-bottom: 1px solid #eef2f0; vertical-align: top; }
.table tbody tr:hover { background: #fafcfb; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-compact td { padding: .45rem .6rem; font-size: .85rem; white-space: nowrap; }
.is-muted { opacity: .6; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem !important; }
.empty-state { text-align: center; padding: 2rem; }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; padding: .75rem 1rem; }
.filters input, .filters select { width: auto; flex: 1 1 160px; min-height: 38px; padding: .4rem .6rem; }
.filters input[type=date] { flex: 0 1 auto; }
.filters label.inline input { flex: none; }
@media (max-width: 600px) { .filters > * { flex: 1 1 100% !important; } .filters label.inline input { flex: 1 !important; } }

.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); }
.tabs a { padding: .6rem .9rem; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.pager { display: flex; gap: .3rem; justify-content: center; margin-top: 1rem; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; }
.details dt { color: var(--muted); font-size: .85rem; }
.details dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 500px) { .details { grid-template-columns: 1fr; } .details dd { margin-bottom: .4rem; } }
.photo { max-width: 100%; max-height: 260px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.kpi span { font-size: .78rem; color: var(--muted); font-weight: 600; }
.kpi b { font-size: 1.7rem; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: .15rem; }
.kpi b small { font-size: .9rem; color: var(--muted); font-weight: 500; }
.kpi em { font-style: normal; font-size: .75rem; color: var(--muted); }
.kpis--compact { grid-template-columns: 1fr 1fr; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.chart-box { position: relative; height: 240px; }
.status { font-size: .8rem; font-weight: 600; }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .35rem; background: #a3aeaa; }
.status.online { color: var(--success); }
.status.online::before { background: #22c55e; }

/* Campañas */
.campaign { display: flex; flex-direction: column; gap: .35rem; }
.campaign-head { display: flex; gap: .4rem; }
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .25rem 0 .5rem; }
.mini-stats div { background: var(--surface-2); border-radius: var(--radius-sm); padding: .4rem .6rem; }
.mini-stats dt { font-size: .7rem; color: var(--muted); }
.mini-stats dd { margin: 0; font-weight: 700; font-size: 1.1rem; }
.campaign .btn-row { margin-top: auto; padding-top: .5rem; }

/* Constructor de formularios */
.builder { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 960px) { .builder { grid-template-columns: 1fr; } }
.preview { position: sticky; top: 76px; background: var(--surface-2); }
.add-field { display: flex; gap: .5rem; }
.add-field select { width: auto; }
.field-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.field-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .7rem; background: var(--surface); display: flex; flex-direction: column; gap: .5rem; }
.field-item-head { display: flex; gap: .5rem; align-items: center; }
.field-item-head .f-label { flex: 1; font-weight: 600; }
.field-item-head .f-type { width: 170px; flex: none; }
.field-item-body { display: flex; flex-direction: column; gap: .5rem; }
.field-item-foot { display: flex; gap: .35rem; align-items: center; }
.spacer { flex: 1; }
.drag { width: 26px; height: 26px; flex: none; display: grid; place-items: center; background: var(--primary-50); color: var(--primary); font-weight: 700; border-radius: 50%; font-size: .8rem; }
@media (max-width: 560px) { .field-item-head { flex-wrap: wrap; } .field-item-head .f-type { width: 100%; } .add-field { flex-wrap: wrap; } }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field-label { font-size: .87rem; font-weight: 600; color: #34413d; }
.choices { display: flex; flex-direction: column; gap: .4rem; padding: .2rem 0; }
.choices--inline { flex-direction: row; gap: 1.5rem; }

/* Login */
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2rem; box-shadow: 0 10px 30px rgba(15, 92, 77, .08); display: flex; flex-direction: column; gap: 1rem; }
.auth-brand { display: flex; align-items: center; gap: .9rem; }
.auth-brand h1 { font-size: 1.5rem; margin: 0; }
.auth-brand p { margin: 0; }
body.auth { background: radial-gradient(1200px 500px at 50% -10%, #d7ebe5, var(--bg)); }

/* Mapa */
.page-map .content { max-width: none; padding-bottom: 1rem; }
.map-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 1rem; height: calc(100vh - 100px); min-height: 480px; }
.map-panel { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.map-panel-head { padding: .9rem; display: flex; flex-direction: column; gap: .5rem; border-bottom: 1px solid var(--border); }
.map-panel-foot { padding: .5rem .9rem; border-top: 1px solid var(--border); }
.legend { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #a3aeaa; flex: none; }
.dot.online { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.dot.stale { background: #f59e0b; }
.agent-list { list-style: none; margin: 0; padding: .35rem; overflow-y: auto; flex: 1; }
.agent-list li { display: flex; align-items: center; gap: .65rem; padding: .55rem .6rem; border-radius: var(--radius-sm); cursor: pointer; }
.agent-list li:hover, .agent-list li.active { background: var(--primary-50); }
.agent-list .grow { flex: 1; min-width: 0; }
.agent-list strong, .agent-list small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-list .count { min-width: 28px; text-align: center; font-weight: 700; font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .1rem .45rem; }
.map-wrap { position: relative; padding: 0; overflow: hidden; }
#map { position: absolute; inset: 0; }
.route-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 500; background: var(--surface); box-shadow: 0 4px 18px rgba(0,0,0,.15); border-radius: var(--radius); padding: .5rem .6rem .5rem 1rem; display: flex; align-items: center; gap: .6rem; max-width: calc(100% - 24px); flex-wrap: wrap; }
.route-bar input { width: auto; min-height: 32px; padding: .2rem .5rem; }
@media (max-width: 900px) {
  .map-layout { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; }
  .map-wrap { order: -1; min-height: 55vh; }
  .agent-list { max-height: 50vh; }
  .route-bar { border-radius: var(--radius); left: 12px; right: 12px; transform: none; }
}
.agent-pin-wrap { background: none; border: 0; }
.agent-pin { width: 36px; height: 36px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: #8b9893; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); display: grid; place-items: center; }
.agent-pin span { transform: rotate(45deg); color: #fff; font-weight: 700; font-size: .72rem; }
.agent-pin.online { background: var(--primary); }
.agent-pin.stale { background: #d97706; }
.visit-pin-wrap { background: none; border: 0; }
.visit-pin { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: .75rem; display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.pop { min-width: 210px; font-family: var(--font); }
.pop-grid { display: grid; grid-template-columns: auto 1fr; gap: .15rem .75rem; margin: .5rem 0; font-size: .8rem; }
.pop-grid span { color: var(--muted); }
.pop-actions { display: flex; gap: .3rem; flex-wrap: wrap; }
.pop-actions .btn { color: var(--text); }
.map-strip { padding: 0; overflow: hidden; }
.map-strip #visitsMap { height: 280px; }
.map-small { height: 300px; border-radius: var(--radius-sm); margin-bottom: .5rem; }

/* App del agente */
.agent-app .content { max-width: 640px; margin: 0 auto; }
.tracker { display: flex; flex-direction: column; gap: .9rem; border-width: 2px; }
.tracker-status { display: flex; gap: .85rem; align-items: center; }
.tracker-status strong { display: block; font-size: 1.1rem; }
.pulse { width: 16px; height: 16px; border-radius: 50%; background: #a3aeaa; flex: none; position: relative; }
.tracker[data-state=on] { border-color: #86d3a3; }
.tracker[data-state=on] .pulse { background: #22c55e; }
.tracker[data-state=on] .pulse::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid #22c55e; animation: pulse 1.6s ease-out infinite; }
.tracker[data-state=warn] { border-color: #f5cf8b; }
.tracker[data-state=warn] .pulse { background: #f59e0b; }
.tracker[data-state=error] { border-color: #efb4af; }
.tracker[data-state=error] .pulse { background: var(--danger); }
@keyframes pulse { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tracker .pulse::after { animation: none; } }
.tracker-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.tracker-meta div { background: var(--surface-2); border-radius: var(--radius-sm); padding: .45rem .6rem; }
.tracker-meta span { display: block; font-size: .72rem; color: var(--muted); }
.tracker-meta b { font-variant-numeric: tabular-nums; }
.gps-pill { font-size: .85rem; padding: .55rem .8rem; border-radius: var(--radius-sm); background: var(--warn-50); color: #7c4a03; }
.gps-pill.ok { background: var(--success-50); color: #14532d; }
.gps-pill.bad { background: var(--danger-50); color: #7f1d1d; }
.visit-list { list-style: none; margin: 0; padding: 0; }
.visit-list li { display: flex; justify-content: space-between; gap: .75rem; padding: .65rem 0; border-bottom: 1px solid #eef2f0; }
.visit-list li:last-child { border-bottom: 0; }
.visit-list strong, .visit-list small { display: block; }
.visit-list .right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .25s; z-index: 1000; background: #17211e; color: #fff; padding: .7rem 1.1rem; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: calc(100% - 32px); font-size: .9rem; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
