:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2330;
  --muted: #677285;
  --line: #e2e6ec;
  --accent: #2456d6;
  --accent-soft: #e8eefc;
  --good: #11804a;
  --good-soft: #e3f4ea;
  --bad: #c43737;
  --bad-soft: #fbe9e9;
  --warn-soft: #fdf4dc;
  --top3: #11804a;
  --top10: #2456d6;
  --top20: #a86a00;
  --rest: #677285;
  --chart-impr: #c9d4ea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --surface: #1a1f27; --surface-2: #222833; --text: #e4e8ef; --muted: #939cad;
    --line: #2c3340; --accent: #6d95ff; --accent-soft: #1f2a44; --good: #4cc584; --good-soft: #17302a;
    --bad: #f07474; --bad-soft: #3a1f22; --warn-soft: #362e18; --top3: #4cc584; --top10: #6d95ff;
    --top20: #e0a43a; --rest: #939cad; --chart-impr: #33415e; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --surface: #1a1f27; --surface-2: #222833; --text: #e4e8ef; --muted: #939cad;
  --line: #2c3340; --accent: #6d95ff; --accent-soft: #1f2a44; --good: #4cc584; --good-soft: #17302a;
  --bad: #f07474; --bad-soft: #3a1f22; --warn-soft: #362e18; --top3: #4cc584; --top10: #6d95ff;
  --top20: #e0a43a; --rest: #939cad; --chart-impr: #33415e; --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.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .15rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .4rem; }
code, .mono { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.strong { font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Estructura ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-in { max-width: 1180px; margin: 0 auto; padding: 0 16px; height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); }
.brand svg { color: var(--accent); }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 4px; }
.topbar nav a, .topbar nav .link { color: var(--muted); padding: 6px 10px; border-radius: 7px; font-weight: 500; }
.topbar nav a:hover, .topbar nav .link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar nav a.on { color: var(--text); background: var(--surface-2); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 40px; }
.foot { max-width: 1180px; margin: 0 auto; padding: 0 16px 28px; color: var(--muted); font-size: .8rem; }
.inline { display: inline; margin: 0; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
.crumbs span { margin: 0 4px; opacity: .6; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 18px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px 20px; text-align: center; color: var(--muted); margin-bottom: 18px; }
.notice { background: var(--warn-soft); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; }

/* ---------- Mensajes ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .92rem; }
.flash-ok { background: var(--good-soft); color: var(--good); }
.flash-error { background: var(--bad-soft); color: var(--bad); }
.flash-info { background: var(--accent-soft); color: var(--accent); }

/* ---------- Formularios ---------- */
label { display: block; font-size: .88rem; font-weight: 500; }
input[type=text], input[type=password], input[type=number], select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.stack > * + * { margin-top: 12px; }
.stack { margin: 0; }
.row-form { display: flex; gap: 8px; margin-top: 8px; }
.row-form input { margin-top: 0; }
.inline-check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.narrow { max-width: 320px; }
.narrow-form { max-width: 380px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn-row form { margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; }
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 9px; padding: 12px; font-weight: 400; cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 7px; font: inherit; font-weight: 600; font-size: .9rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--bad); border-color: transparent; }
.btn.danger-ghost:hover { background: var(--bad-soft); }
.btn.small { padding: 5px 10px; font-size: .82rem; }
.btn:disabled, .btn[aria-busy=true] { opacity: .55; cursor: default; }
button.link { background: none; border: 0; font: inherit; cursor: pointer; }

.checklist { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin: 8px 0 12px; }
.checklist label { display: flex; gap: 10px; align-items: baseline; padding: 7px 10px; font-weight: 400; border-bottom: 1px solid var(--line); }
.checklist label:last-child { border-bottom: 0; }
.checklist label:hover { background: var(--surface-2); }
.check-all { display: flex; gap: 8px; align-items: center; font-weight: 500; }
details.manual { margin-top: 16px; }
details.manual summary { cursor: pointer; color: var(--muted); font-size: .88rem; }

.danger-zone { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.danger-zone form { margin: 0; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table.compact td { padding: 6px 12px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .cb { width: 34px; padding-right: 0; }
.table tr.inactive td { opacity: .6; }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--text); }
.table th[data-dir=asc]::after { content: " ↑"; }
.table th[data-dir=desc]::after { content: " ↓"; }
.page-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; }
.table-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: -8px 0 18px; }
.sticky-foot { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; margin: 0; }

.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); vertical-align: middle; margin-left: 4px; }
.tag.ok { background: var(--good-soft); color: var(--good); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }

.pos { font-weight: 700; font-variant-numeric: tabular-nums; }
.pos-top3 { color: var(--top3); }
.pos-top10 { color: var(--top10); }
.pos-top20 { color: var(--top20); }
.pos-rest, .pos-none { color: var(--rest); }
.delta { font-size: .82rem; font-weight: 600; color: var(--muted); }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

.spark { display: block; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--accent); }

/* ---------- Ficha de keyword ---------- */
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.seg a { padding: 4px 10px; border-radius: 6px; color: var(--muted); font-size: .85rem; font-weight: 500; }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.on { background: var(--accent-soft); color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat-label { font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.chart-head h2 { margin-bottom: 4px; }
.chart { position: relative; width: 100%; margin-bottom: 18px; }
.chart:last-child { margin-bottom: 0; }
.chart svg { display: block; width: 100%; overflow: visible; }
.legend { font-size: .8rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.lg { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-left: 8px; }
.lg-daily { background: var(--accent); opacity: .45; }
.lg-avg { background: var(--accent); height: 3px; }
.lg-impr { background: var(--chart-impr); height: 9px; width: 9px; }
.lg-clicks { background: var(--good); height: 9px; width: 9px; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-axis { fill: var(--muted); font-size: 11px; font-family: system-ui, sans-serif; }
.c-daily { fill: none; stroke: var(--accent); stroke-width: 1.4; opacity: .45; stroke-linejoin: round; }
.c-avg { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: var(--accent); }
.c-impr { fill: var(--chart-impr); }
.c-clicks { fill: none; stroke: var(--good); stroke-width: 2; stroke-linejoin: round; }
.c-cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.c-hit { fill: transparent; }
.tooltip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: .8rem; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; z-index: 5; }
.tooltip b { font-variant-numeric: tabular-nums; }

/* ---------- Varios ---------- */
pre.code, pre.log { background: var(--surface-2); border-radius: 7px; padding: 10px 12px; font-family: var(--mono); font-size: .82rem; overflow-x: auto; white-space: pre-wrap; word-break: break-all; margin: 6px 0; }
pre.log { max-width: 640px; max-height: 260px; }
[data-copy] { cursor: copy; }
code.copy { background: var(--surface-2); padding: 3px 7px; border-radius: 5px; display: inline-block; margin-top: 4px; word-break: break-all; }
.copied { outline: 2px solid var(--good); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }

/* ---------- Login ---------- */
body.bare .wrap { max-width: 400px; padding-top: 12vh; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin-bottom: 8px; }
.auth-logo { color: var(--accent); margin-bottom: 10px; }
.auth-card .btn { width: 100%; justify-content: center; }

@media (max-width: 860px) {
  .grid-2, .two, .three, .radio-cards { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .topbar-in { height: auto; padding-top: 8px; padding-bottom: 8px; flex-wrap: wrap; }
  .topbar nav { width: 100%; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; gap: 0; }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav a, .topbar nav .link { padding: 6px 9px; white-space: nowrap; }
  .wrap { padding-top: 16px; }
  .card { padding: 14px; }
  .row-form { flex-direction: column; }
}

/* ---------- v1.1: salud, oportunidades, indexación, resumen ---------- */
.link-stat { color: inherit; }
.link-stat:hover { text-decoration: none; border-color: var(--accent); }
.bad-text { color: var(--bad); }
.stats.inner { grid-template-columns: repeat(6, 1fr); margin: 8px 0 16px; }
.stats.inner .stat { box-shadow: none; background: var(--surface-2); border-color: transparent; padding: 10px 12px; }
.stats.inner .stat-value { font-size: 1.3rem; }
.section-title { margin: 6px 0 10px; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filters select { width: auto; margin: 0; }
.filters form { margin: 0; display: flex; gap: 8px; align-items: center; }
.url-cell { max-width: 380px; word-break: break-all; font-size: .85rem; }
.verdict { font-weight: 600; font-size: .78rem; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.verdict-PASS { background: var(--good-soft); color: var(--good); }
.verdict-NEUTRAL, .verdict-PARTIAL { background: var(--warn-soft); color: var(--top20); }
.verdict-FAIL, .verdict-ERR { background: var(--bad-soft); color: var(--bad); }
.verdict-PEND { background: var(--surface-2); color: var(--muted); }
.mail-preview { background: #f5f6f8; border-radius: var(--radius); padding: 12px; overflow-x: auto; }
@media (max-width: 860px) { .stats.inner { grid-template-columns: repeat(2, 1fr); } }
