:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #14213d;
  --muted: #5b6782;
  --border: #e2e7f0;
  --primary: #3b5bdb;
  --primary-hover: #2f4ac0;
  --primary-soft: #eef2ff;
  --ok: #157f3b;
  --ok-soft: #e7f6ec;
  --warn: #9a6700;
  --warn-soft: #fff6dd;
  --err: #c0362c;
  --err-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .05), 0 4px 16px rgba(20, 33, 61, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1422; --surface: #171e30; --text: #e8ecf6; --muted: #9aa5c0; --border: #263049;
    --primary: #6d8cff; --primary-hover: #839dff; --primary-soft: #1d2747;
    --ok: #5fd38a; --ok-soft: #14301f; --warn: #f0c35b; --warn-soft: #362b10;
    --err: #ff7b70; --err-soft: #3a1815;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .35rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
p { margin: 0 0 .8rem; }
code { font-size: .85em; background: var(--primary-soft); padding: .1em .35em; border-radius: 5px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: .95rem;
}
.logout { display: flex; align-items: center; gap: .75rem; margin: 0; font-size: .9rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.container.medium { max-width: 680px; }
.container.narrow { max-width: 440px; padding-top: 3rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.4rem; box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0;
}
.card.highlight { border-color: var(--primary); background: var(--primary-soft); }
.card.center { text-align: center; }
.card.empty { text-align: center; padding: 3rem 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.grid .card { margin-bottom: 0; }
.grid + .card { margin-top: 1rem; }
.back { display: inline-block; margin-bottom: .8rem; font-size: .9rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err { color: var(--err); }
.nowrap { white-space: nowrap; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .75rem; font-weight: 700; color: var(--primary); margin-bottom: .3rem; }
.lead { font-size: 1.02rem; color: var(--muted); }

/* Formularios */
.stack { display: flex; flex-direction: column; gap: 1rem; }
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .92rem; }
label small, .help { font-weight: 400; color: var(--muted); font-size: .84rem; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: .62rem .75rem; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .8rem; min-width: 0; }
fieldset[hidden], [hidden] { display: none !important; }
legend { font-weight: 700; font-size: 1rem; margin-bottom: .6rem; padding: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.check { flex-direction: row; align-items: flex-start; gap: .6rem; font-weight: 400; }
.check input { width: auto; margin-top: .25rem; flex: none; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .5rem; }
.choice {
  flex-direction: row; align-items: center; gap: .5rem; padding: .7rem .8rem; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; font-weight: 600;
}
.choice input { width: auto; margin: 0; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

.consent { border-top: 1px solid var(--border); padding-top: 1rem; }
.consent ul { margin: .6rem 0 0 1.6rem; padding: 0; }

.copy-row { display: flex; gap: .5rem; margin-bottom: .8rem; }
.copy-row input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
details summary { cursor: pointer; margin-bottom: .5rem; font-weight: 600; }
details textarea { margin-bottom: .5rem; font-size: .88rem; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; border-radius: 9px; padding: .6rem 1rem; cursor: pointer;
  border: 1px solid transparent; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-lg { padding: .8rem 1.2rem; font-size: 1rem; }
form > .btn { align-self: flex-start; }
.stack > .btn-lg { align-self: stretch; }

/* Estados */
.alert { border-radius: 9px; padding: .7rem .9rem; margin-bottom: 1rem; font-size: .92rem; }
.alert-error { background: var(--err-soft); color: var(--err); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.badge { display: inline-block; border-radius: 999px; padding: .15rem .6rem; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-off { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.done-icon { width: 64px; height: 64px; margin: .5rem auto 1rem; border-radius: 50%; display: grid; place-items: center; font-size: 1.8rem; font-weight: 700; }
.done-icon.ok { background: var(--ok-soft); color: var(--ok); }
.done-icon.warn { background: var(--warn-soft); color: var(--warn); }

/* Tablas */
.table-card { padding: 0; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
table.compact td { padding: .45rem .5rem; font-size: .88rem; }
.facts { margin: 0 0 1rem; font-size: .9rem; }
.facts dt { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; margin-top: .55rem; }
.facts dt:first-child { margin-top: 0; }
.facts dd { margin: .1rem 0 0; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.list li { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; }
  .card { padding: 1.1rem; }
  .logout .muted { display: none; }
  .container.narrow { padding-top: 1.5rem; }
  .table-card table, .table-card tbody, .table-card tr, .table-card td { display: block; }
  .table-card thead { display: none; }
  .table-card tr { border-bottom: 1px solid var(--border); padding: .5rem 0; }
  .table-card td { border: 0; padding: .3rem 1rem; display: flex; justify-content: space-between; gap: 1rem; }
  .table-card td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; }
  table.compact td.muted.small { display: none; }
}

/* 2FA */
.steps { padding-left: 1.2rem; margin: 0.5rem 0; }
.steps li { margin: 0.25rem 0; }
.qr { display: block; margin: 0.75rem auto; background: #fff; padding: 8px; border-radius: 12px; }
.secret { display: block; word-break: break-all; padding: 0.5rem; margin-top: 0.5rem;
  background: var(--primary-soft); border-radius: 8px; font-size: 0.95rem; }
.small { font-size: 0.85rem; }

/* Resultados por anuncio */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.ads { min-width: 760px; }
table.ads th, table.ads td { vertical-align: top; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.ads tfoot th { border-top: 2px solid var(--border); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* ---- Dashboard ------------------------------------------------------------------------- */
:root {
  --c-ventas: #16a34a; --c-inversion: #f59e0b; --c-leads: #94a3b8; --c-agendados: #6d8cff;
  --c-asistidos: #3b5bdb; --track: #eef1f6;
}
@media (prefers-color-scheme: dark) {
  :root { --c-ventas: #34d399; --c-inversion: #fbbf24; --c-leads: #64748b; --c-agendados: #8ea6ff;
          --c-asistidos: #6d8cff; --track: #232c44; }
}
.dash-body .container { max-width: 1200px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.center { text-align: center; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.dash-head h1 { margin: 0 0 .2rem; }
.period { display: flex; flex-direction: column; gap: .5rem; align-items: flex-end; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.chip { padding: .35rem .7rem; border: 1px solid var(--border); border-radius: 999px; font-size: .85rem; color: var(--text); background: var(--surface); }
.chip:hover { text-decoration: none; border-color: var(--primary); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.range { display: flex; align-items: center; gap: .4rem; margin: 0; }
.range input { width: auto; padding: .35rem .5rem; font-size: .85rem; }
.range .btn { padding: .4rem .8rem; }
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; display: flex; flex-direction: column; gap: .15rem; }
.kpi span { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi strong { font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: .8rem; }
.kpi-main { border-color: var(--c-ventas); }
.kpi-main strong { color: var(--c-ventas); }
.costs { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; }
.costs div { display: flex; flex-direction: column; padding: .6rem .8rem; border-radius: 10px; background: var(--primary-soft); }
.costs span { font-size: .85rem; color: var(--muted); }
.costs strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.dash-grid { grid-template-columns: 2fr 1fr; margin-bottom: 1rem; }
.chart-wrap { overflow-x: auto; }
svg.chart { width: 100%; min-width: 560px; height: 240px; display: block; }
svg.chart .grid { stroke: var(--border); stroke-width: 1; }
svg.chart .axis { fill: var(--muted); font-size: 11px; }
.c-ventas { fill: var(--c-ventas); } .c-leads { fill: var(--c-leads); }
.c-agendados { fill: var(--c-agendados); } .c-asistidos { fill: var(--c-asistidos); }
.c-inversion { fill: var(--c-inversion); }
svg.chart .line { fill: none; stroke: var(--c-inversion); stroke-width: 2.5; }
svg.chart rect:hover { opacity: .8; }
.track { fill: var(--track); }
.legend { display: flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: .4rem; }
.sw.c-ventas { background: var(--c-ventas); } .sw.c-inversion { background: var(--c-inversion); }
.sw.c-leads { background: var(--c-leads); } .sw.c-agendados { background: var(--c-agendados); }
.sw.c-asistidos { background: var(--c-asistidos); }
.funnel { display: flex; flex-direction: column; gap: .8rem; margin-top: .5rem; }
.funnel-row { display: grid; grid-template-columns: 82px 1fr 64px 40px; align-items: center; gap: .5rem; font-size: .9rem; }
.funnel-bar { width: 100%; height: 14px; }
.funnel-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.funnel-conv { font-size: .8rem; text-align: right; }
svg.share { display: block; }
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .period { align-items: flex-start; }
  .chips { justify-content: flex-start; }
}
@media (max-width: 560px) {
  .kpis, .costs { grid-template-columns: repeat(2, 1fr); }
  .kpi strong { font-size: 1.2rem; }
}
.row-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }
li.resolved { opacity: .55; }
li.resolved .err { color: var(--muted); }
table.ads td:first-child, table.ads th:first-child { min-width: 240px; }
@media (max-width: 560px) {
  .period { width: 100%; }
  .range { flex-wrap: wrap; width: 100%; }
  .range label { flex: 1 1 120px; }
  .range input { width: 100%; }
}
.chart-sub { margin-top: 1rem; } .chart-sub h3 { margin: 0; font-size: .95rem; } svg.chart.small, .chart-small svg.chart { height: 180px; }

/* ---- Carga del dashboard con el logo de SmartIA ---------------------------------------- */
:root { --brand: #15a7db; }
.brand-logo { height: 28px; width: auto; display: block; }
.loader {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 1.1rem; background: var(--bg); transition: opacity .35s ease;
}
.loader.done { opacity: 0; pointer-events: none; }
.loader[hidden] { display: none; }
.loader-mark { position: relative; width: 120px; height: 120px; }
.loader-sphere {
  width: 120px; height: 120px; display: block; position: relative;
  animation: sphere-spin 6s linear infinite, sphere-breathe 1.8s ease-in-out infinite;
}
.loader-halo {
  position: absolute; inset: -14px; border-radius: 50%;
  background: radial-gradient(circle, rgba(21, 167, 219, .28) 0%, rgba(21, 167, 219, 0) 68%);
  animation: halo-pulse 1.8s ease-in-out infinite;
}
.loader-word { width: 220px; height: auto; animation: word-fade 1.8s ease-in-out infinite; }
.loader-bar { width: 220px; height: 4px; border-radius: 4px; background: rgba(21, 167, 219, .15); overflow: hidden; }
.loader-bar span {
  display: block; width: 40%; height: 100%; border-radius: 4px; background: var(--brand);
  animation: bar-slide 1.3s ease-in-out infinite;
}
.loader-text { margin: 0; color: var(--muted); font-size: .9rem; }
#dash-root { transition: opacity .25s ease; }
#dash-root.dimmed { opacity: .35; }
@keyframes sphere-spin { to { transform: rotate(360deg); } }
@keyframes sphere-breathe { 0%, 100% { scale: 1; } 50% { scale: 1.06; } }
@keyframes halo-pulse { 0%, 100% { opacity: .35; transform: scale(.9); } 50% { opacity: 1; transform: scale(1.08); } }
@keyframes word-fade { 0%, 100% { opacity: .75; } 50% { opacity: 1; } }
@keyframes bar-slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }
@media (prefers-reduced-motion: reduce) {
  .loader-sphere, .loader-halo, .loader-word, .loader-bar span { animation: word-fade 2.4s ease-in-out infinite; }
}
.costs strong { font-size: clamp(1rem, 2.4vw, 1.3rem); white-space: nowrap; }
