/* =====================================================================
   Plataforma de servicios de marketing · hoja de estilos única
   Idea visual: "cuaderno de diagnóstico". Tinta azul profunda sobre papel frío,
   el plan de acción como protagonista: cada acción lleva una franja de prioridad
   y un interruptor de estado grande, fácil de pulsar con el pulgar.
   ===================================================================== */
:root {
  --ink: #16243f;
  --ink-2: #3d4b66;
  --muted: #6b7690;
  --line: #d9dfe9;
  --paper: #ffffff;
  --bg: #eef1f5;
  --brand: #1f4fd1;          /* se sustituye por el color del cliente */
  --accent: #0e8a7e;
  --high: #c8372d;
  --mid: #c98a00;
  --low: #4f7d4f;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4b00;
  --ok-bg: #e2f4ef;
  --ok-ink: #0b5d55;
  --err-bg: #fde8e6;
  --err-ink: #8c241c;
  --radius: 10px;
  --sans: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --display: "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", "Segoe UI Semibold", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e7ecf5; --ink-2: #c2cbdb; --muted: #94a0b8; --line: #2c3850; --paper: #16203a; --bg: #0f172b;
    --warn-bg: #3a2f10; --warn-ink: #f4d58a; --ok-bg: #0f3a35; --ok-ink: #9be2d6; --err-bg: #42181a; --err-ink: #f5b3ad;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--sans); color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-underline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 700; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.08rem; font-weight: 700; }
p { margin: 0 0 1em; max-width: 72ch; }
small, .muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- Estructura */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; min-width: 0; }
.topbar .brand img { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; }
.topbar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.logo-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; flex: none; }
.side { display: none; }
.main { padding: 18px 16px 96px; max-width: 1180px; width: 100%; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head p { margin: 0; color: var(--muted); }

/* Navegación inferior en móvil (cliente) */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--paper); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 9px; font-size: .72rem;
  color: var(--muted); text-decoration: none; }
.bottom-nav a svg { width: 22px; height: 22px; }
.bottom-nav a[aria-current="page"] { color: var(--brand); font-weight: 600; }

@media (min-width: 960px) {
  .shell { grid-template-columns: 240px 1fr; }
  .topbar { grid-column: 1 / -1; }
  .side { display: block; position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto; padding: 16px 10px;
    border-right: 1px solid var(--line); background: var(--paper); }
  .bottom-nav { display: none; }
  .main { padding: 28px 32px 48px; }
}
.side nav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: .95rem; }
.side nav a svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.side nav a:hover { background: var(--bg); }
.side nav a[aria-current="page"] { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); font-weight: 600; }
.side .group { margin: 16px 12px 6px; font-size: .8rem; color: var(--muted); }
.side .version { margin: 20px 12px 0; font-size: .75rem; color: var(--muted); }

/* Contador de créditos: el elemento distintivo de la cabecera */
.credit-pill { display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 12px 5px 10px; border-radius: 999px;
  border: 2px solid var(--brand); color: var(--brand); text-decoration: none; font-weight: 700; white-space: nowrap; }
.credit-pill b { font-family: var(--display); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.credit-pill.low { border-color: var(--high); color: var(--high); }

/* ---------------------------------------------------------------- Componentes */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.panel.flat { background: transparent; border-style: dashed; }
.grid { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } .grid.four { grid-template-columns: repeat(4, 1fr); } }
.stack > * + * { margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 8px;
  border: 1px solid transparent; background: var(--brand); color: #fff; font: 600 .95rem var(--sans); text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn[disabled], .btn.is-busy { opacity: .6; cursor: progress; }
.btn.secondary { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--brand); border-color: transparent; padding-inline: 8px; }
.btn.danger { background: var(--high); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; }

label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 16px; }
.field .help { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.field .error { font-size: .85rem; color: var(--err-ink); margin-top: 4px; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
  color: var(--ink); font: 16px/1.4 var(--sans); }
textarea { min-height: 110px; resize: vertical; }
textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; min-height: 220px; }
input[type=color] { width: 56px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.has-error input, .has-error textarea, .has-error select { border-color: var(--high); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin-bottom: 8px; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px;
  font-weight: 500; cursor: pointer; background: var(--paper); }
.chips input { accent-color: var(--brand); }
.chips label:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--paper)); }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-family: var(--display); font-weight: 700; font-size: 1.1rem; margin-bottom: 10px; }

.flash { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.success { background: var(--ok-bg); color: var(--ok-ink); }
.flash.error { background: var(--err-bg); color: var(--err-ink); }
.flash.info { background: color-mix(in srgb, var(--brand) 10%, var(--paper)); color: var(--ink); }
.flash.warn, .notice { background: var(--warn-bg); color: var(--warn-ink); padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; }
.demo-banner { background: var(--warn-bg); color: var(--warn-ink); border-left: 5px solid var(--mid); padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 600; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--ink-2); white-space: nowrap; }
.badge.succeeded, .badge.published, .badge.active, .badge.completada, .badge.paid { background: var(--ok-bg); color: var(--ok-ink); }
.badge.failed, .badge.disabled, .badge.suspended, .badge.cancelled { background: var(--err-bg); color: var(--err-ink); }
.badge.queued, .badge.running, .badge.retrying, .badge.testing, .badge.en_curso, .badge.pending { background: var(--warn-bg); color: var(--warn-ink); }
.badge.demo { background: var(--warn-bg); color: var(--warn-ink); }
.prio { font-weight: 700; }
.prio.alta { color: var(--high); } .prio.media { color: var(--mid); } .prio.baja { color: var(--low); }

table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.data td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data td.r, table.data th.r { text-align: right; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 719px) {
  table.data.cards thead { display: none; }
  table.data.cards tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.data.cards td { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border: 0; }
  table.data.cards td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; }
  table.data.cards td.r { text-align: right; }
}

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty h3 { color: var(--ink); }

/* Métricas */
.metric { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.metric .v { font-family: var(--display); font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric .l { color: var(--muted); font-size: .88rem; }
.metric.alert .v { color: var(--high); }

/* Catálogo de servicios */
.service { display: flex; flex-direction: column; gap: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.service .meta { display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: .88rem; }
.service .price { margin-left: auto; font-family: var(--display); font-weight: 700; font-size: 1.25rem; color: var(--brand); white-space: nowrap; }
.service .actions { margin-top: auto; display: flex; gap: 8px; }
.service h3 { margin: 0; }

.cost-box { border: 2px solid var(--brand); border-radius: var(--radius); padding: 16px; background: color-mix(in srgb, var(--brand) 6%, var(--paper)); }
.cost-box .big { font-family: var(--display); font-size: 2.4rem; font-weight: 700; color: var(--brand); line-height: 1; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* Pasos de una ejecución */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: grid; grid-template-columns: 24px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.steps .dot { width: 14px; height: 14px; margin-top: 5px; border-radius: 50%; border: 2px solid var(--muted); }
.steps .succeeded .dot { background: var(--accent); border-color: var(--accent); }
.steps .running .dot { border-color: var(--mid); border-top-color: transparent; animation: spin .9s linear infinite; }
.steps .failed .dot { background: var(--high); border-color: var(--high); }
.steps .skipped .dot { border-style: dashed; }
.steps small { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-hero { display: flex; align-items: center; gap: 14px; }
.status-hero .spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; flex: none; }

/* ---------------------------------------------------------------- Informe */
.report-head { border-bottom: 3px solid var(--brand); padding-bottom: 12px; margin-bottom: 18px; }
.report section { margin-bottom: 26px; }
.report section > h2 { font-size: 1.25rem; padding-left: 12px; border-left: 4px solid var(--brand); }
.score { display: flex; align-items: center; gap: 16px; }
.score .ring { width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-size: 1.6rem; font-weight: 700;
  background: conic-gradient(var(--brand) calc(var(--v) * 1%), var(--line) 0); position: relative; flex: none; }
.score .ring::before { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--paper); }
.score .ring span { position: relative; }
.origin { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; white-space: nowrap; vertical-align: 1px; }
.origin.cliente { border-color: var(--accent); color: var(--accent); }
.origin.fuente_publica { border-color: var(--brand); color: var(--brand); }
.origin.supuesto { border-color: var(--mid); color: var(--mid); }
.finding { padding: 10px 0; border-bottom: 1px solid var(--line); }
.finding:last-child { border-bottom: 0; }

/* Plan de acción: el protagonista */
.action { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 14px 22px; margin-bottom: 14px; overflow: hidden; }
.action::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px; background: var(--low); }
.action.p-alta::before { background: var(--high); }
.action.p-media::before { background: var(--mid); }
.action.is-done { opacity: .72; }
.action.is-done h3 { text-decoration: line-through; text-decoration-thickness: 2px; }
.action h3 { margin: 0 0 6px; }
.action .facts { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .86rem; color: var(--muted); margin-bottom: 10px; }
.action .facts b { color: var(--ink-2); font-weight: 600; }
.action ol { margin: 6px 0 10px; padding-left: 22px; }
.action details { margin-top: 8px; }
.action summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.status-switch { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-top: 10px; }
.status-switch button { min-height: 42px; border: 0; border-right: 1px solid var(--line); background: var(--paper); color: var(--ink-2); font: 600 .88rem var(--sans); cursor: pointer; }
.status-switch button:last-child { border-right: 0; }
.status-switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.status-switch button[data-v="completada"][aria-pressed="true"] { background: var(--accent); color: #fff; }
.note { font-size: .9rem; padding: 8px 10px; background: var(--bg); border-radius: 6px; margin-top: 6px; }

/* Barra de filtros */
.filters { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-bottom: 16px; }
@media (min-width: 720px) { .filters { grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: end; } }
.filters .field { margin: 0; }

/* Pestañas del administrador */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 10px 14px; white-space: nowrap; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }

/* Editor de campos del formulario */
.field-row { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: var(--paper); }
.field-row .grid { gap: 10px; }
.field-row .tools { display: flex; gap: 6px; justify-content: flex-end; }
.field-row input, .field-row select, .field-row textarea { min-height: 38px; padding: 7px 10px; font-size: .92rem; }
.field-row textarea { min-height: 64px; }

/* Web pública */
.public-top { display: flex; align-items: center; gap: 12px; padding: 14px 20px; max-width: 1180px; margin: 0 auto; }
.public-top nav { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.hero { max-width: 1180px; margin: 0 auto; padding: 32px 20px 24px; display: grid; gap: 28px; }
@media (min-width: 900px) { .hero { grid-template-columns: 1.1fr .9fr; align-items: center; padding: 56px 20px 40px; } }
.hero h1 { font-size: clamp(2.1rem, 6vw, 3.6rem); line-height: 1.02; }
.hero p.lead { font-size: 1.15rem; color: var(--ink-2); }
.sample-plan { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: 0 18px 40px -24px rgba(22, 36, 63, .45); }
.sample-plan .action { margin-bottom: 10px; padding-block: 12px; }
.sample-plan .action h3 { font-size: 1rem; }
.section { max-width: 1180px; margin: 0 auto; padding: 28px 20px; }
.how { counter-reset: how; display: grid; gap: 16px; }
@media (min-width: 720px) { .how { grid-template-columns: repeat(4, 1fr); } }
.how li { list-style: none; counter-increment: how; padding-top: 10px; border-top: 3px solid var(--brand); }
.how li::before { content: counter(how); font-family: var(--display); font-size: 1.6rem; font-weight: 700; color: var(--brand); display: block; }
.footer { border-top: 1px solid var(--line); padding: 20px; text-align: center; color: var(--muted); font-size: .85rem; }
.auth-card { max-width: 420px; margin: 40px auto; }

.prewrap { white-space: pre-wrap; }
pre.prompt { white-space: pre-wrap; background: var(--bg); padding: 14px; border-radius: 8px; font-size: .85rem; max-height: 60vh; overflow: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
@media (min-width: 960px) { .admin-menu { display: none; } }
@media (max-width: 719px) { .grid.four { grid-template-columns: 1fr 1fr; gap: 10px; } .metric .v { font-size: 1.5rem; } }
.row > select, .row > input:not([type=checkbox]) { width: auto; flex: 0 1 auto; }
.row > input[style*="flex:1"] { flex: 1 1 200px; }
@media (max-width: 719px) { .grid.two > aside.panel { order: -1; } }
