/* ==========================================================================
   WPForge - sistema de diseno
   Todo local: sin CDNs, sin fuentes externas, sin dependencias.
   ========================================================================== */

/* --- Tokens --------------------------------------------------------------- */
/* El tema claro es el de partida; el oscuro se aplica con data-theme="dark".
   Definir asi los tokens evita el destello oscuro al cargar la pagina. */
:root {
  color-scheme: light;

  --bg:            #f4f6fa;
  --bg-soft:       #eef1f6;
  --surface:       #ffffff;
  --surface-2:     #f7f9fc;
  --surface-3:     #eef2f8;
  --border:        #dfe5ee;
  --border-strong: #c7d1e0;

  --text:          #16202e;
  --text-soft:     #3d4a5c;
  /* 5.01:1 en el peor de los fondos claros. Con el gris anterior (#6b7a8f)
     los textos secundarios se quedaban en 3.86:1, por debajo del minimo. */
  --muted:         #5b6879;

  --accent:        #3d5ce0;
  --accent-soft:   rgba(61, 92, 224, .10);
  --accent-line:   rgba(61, 92, 224, .28);
  --accent-text:   #2c47bd;

  --great:         #0f8f6f;
  --great-soft:    rgba(15, 143, 111, .12);
  --good:          #1f9d6f;
  --warn:          #a06a12;
  --warn-soft:     rgba(183, 121, 31, .14);
  --bad:           #c93838;
  --bad-soft:      rgba(201, 56, 56, .10);
  --info:          #0d7fb5;
  --info-soft:     rgba(13, 127, 181, .12);
  --neutral:       #5b6879;
  --neutral-soft:  rgba(91, 104, 121, .12);

  --radius:        12px;
  --radius-sm:     8px;
  --radius-lg:     18px;
  --shadow:        0 1px 2px rgba(16,32,64,.06), 0 8px 24px -14px rgba(16,32,64,.20);
  --shadow-lg:     0 24px 60px -24px rgba(16,32,64,.26);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;

  --sidebar-w: 258px;
  --header-h: 60px;
  --bottom-nav-h: 0px;

  /* Muescas y barras del sistema en moviles (iPhone, Android gestual). */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0d1117;
  --bg-soft:       #11161f;
  --surface:       #161d27;
  --surface-2:     #1c2530;
  --surface-3:     #232d3b;
  --border:        #27313f;
  --border-strong: #364354;

  --text:          #e6edf5;
  --text-soft:     #b3c0d1;
  --muted:         #7d8da0;

  --accent:        #6c8cff;
  --accent-soft:   rgba(108, 140, 255, .14);
  --accent-line:   rgba(108, 140, 255, .35);
  --accent-text:   #a5b8ff;

  --great:         #34d399;
  --great-soft:    rgba(52, 211, 153, .14);
  --good:          #7dd3a0;
  --warn:          #fbbf24;
  --warn-soft:     rgba(251, 191, 36, .14);
  --bad:           #f87171;
  --bad-soft:      rgba(248, 113, 113, .14);
  --info:          #38bdf8;
  --info-soft:     rgba(56, 189, 248, .14);
  --neutral:       #8896a8;
  --neutral-soft:  rgba(136, 150, 168, .14);

  --shadow:        0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
  --shadow-lg:     0 24px 60px -20px rgba(0,0,0,.7);
}

/* --- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: rgba(108, 140, 255, .18);
  overscroll-behavior-y: none;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
img, svg, video, canvas { max-width: 100%; }
img { height: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
code, pre, .code { font-family: var(--mono); font-size: .86em; }
::selection { background: var(--accent-soft); }

/* --- Estructura ----------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }
/* `clip` recorta sin crear un contenedor de scroll (a diferencia de `hidden`),
   asi que no rompe los elementos pegajosos. */
html, body { overflow-x: clip; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  font-weight: 700; letter-spacing: -.02em; font-size: 1.05rem; color: var(--text);
}
.sidebar__brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(140deg, var(--accent), #a05cff);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .82rem;
  box-shadow: 0 4px 14px -4px var(--accent);
}
.brand-sub { font-size: .68rem; color: var(--muted); font-weight: 500; letter-spacing: 0; }

.nav { padding: 12px 10px; flex: 1; }
.nav__label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 700; padding: 14px 10px 6px;
}
.nav__link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 500; font-size: .9rem;
  transition: background .12s, color .12s;
}
.nav__link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav__link.is-active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav__link .icon { flex: none; opacity: .85; }
.nav__badge {
  margin-left: auto; background: var(--accent); color: #fff;
  border-radius: 999px; padding: 1px 7px; font-size: .7rem; font-weight: 700;
}
.nav__client {
  display: flex; align-items: center; gap: 9px; padding: 7px 10px;
  border-radius: var(--radius-sm); color: var(--text-soft); font-size: .87rem;
}
.nav__client:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav__client.is-active { background: var(--surface-2); color: var(--text); }
.avatar {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  display: grid; place-items: center; font-size: .66rem; font-weight: 800;
  color: #fff; background: var(--accent); letter-spacing: -.02em;
  /* El color de fondo lo elige el usuario por cliente; la sombra asegura que
     las iniciales se lean sobre cualquiera de ellos. */
  text-shadow: 0 1px 2px rgba(0, 0, 0, .38);
}
.avatar--lg { width: 44px; height: 44px; border-radius: 12px; font-size: 1rem; }
.sidebar__foot { padding: 12px; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-weight: 650; font-size: 1rem; letter-spacing: -.01em;
                 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__spacer { flex: 1; }
.content { padding: 24px; max-width: 1420px; width: 100%; }
.content--narrow { max-width: 860px; }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: .82rem;
              color: var(--muted); margin-bottom: 4px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head__text { flex: 1; min-width: 240px; }
.page-head h1 { margin-bottom: 4px; }
.page-head__sub { color: var(--muted); font-size: .9rem; margin: 0; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Botones -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font: inherit; font-size: .875rem; font-weight: 550;
  cursor: pointer; transition: background .12s, border-color .12s, transform .06s;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled { opacity: .5; cursor: not-allowed; }
.btn--primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 4px 14px -6px var(--accent);
}
.btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { border-color: var(--bad); color: var(--bad); background: transparent; }
.btn--danger:hover { background: var(--bad-soft); }
.btn--sm { padding: 5px 10px; font-size: .8rem; border-radius: 7px; }
.btn--lg { padding: 11px 20px; font-size: .95rem; }
.btn--block { width: 100%; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* --- Tarjetas ------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card__head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card__head h2, .card__head h3 { margin: 0; font-size: .98rem; }
.card__head .spacer { flex: 1; }
.card__body { padding: 18px; }
.card__body--flush { padding: 0; }
.card__foot { padding: 12px 18px; border-top: 1px solid var(--border);
              background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.card--accent { border-color: var(--accent-line); }

.grid { display: grid; gap: 16px; }
/* `minmax(0, ...)` es imprescindible: con el `1fr` a secas el suelo es
   min-content y una tabla ancha desborda la pantalla en el movil. */
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.grid > * { min-width: 0; }
@media (max-width: 1100px) { .grid--sidebar { grid-template-columns: minmax(0, 1fr); } }

/* --- KPI ------------------------------------------------------------------ */
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; position: relative; overflow: hidden;
}
.kpi__label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
              color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.kpi__value { font-size: 1.85rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.kpi__meta { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.kpi--accent::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 3px; background: var(--accent);
}

/* --- Insignias ------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 650;
  border: 1px solid transparent; white-space: nowrap; line-height: 1.7;
}
.badge--great   { background: var(--great-soft);   color: var(--great);   border-color: var(--great); }
.badge--good    { background: var(--great-soft);   color: var(--good);    border-color: var(--good); }
.badge--warn    { background: var(--warn-soft);    color: var(--warn);    border-color: var(--warn); }
.badge--bad     { background: var(--bad-soft);     color: var(--bad);     border-color: var(--bad); }
.badge--info    { background: var(--info-soft);    color: var(--info);    border-color: var(--info); }
.badge--neutral { background: var(--neutral-soft); color: var(--neutral); border-color: var(--neutral); }
.badge--accent  { background: var(--accent-soft);  color: var(--accent-text); border-color: var(--accent-line); }
.badge--plain   { background: var(--surface-2); color: var(--text-soft); border-color: var(--border); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot--great { background: var(--great); }
.dot--warn  { background: var(--warn); }
.dot--bad   { background: var(--bad); }
.dot--info  { background: var(--info); box-shadow: 0 0 0 0 var(--info); animation: pulse 1.8s infinite; }
.dot--neutral { background: var(--neutral); }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(56,189,248,.5); }
  70%  { box-shadow: 0 0 0 7px rgba(56,189,248,0); }
  100% { box-shadow: 0 0 0 0 rgba(56,189,248,0); }
}

/* --- Medidor circular ----------------------------------------------------- */
.gauge { display: block; }
.gauge__track { stroke: var(--surface-3); }
.gauge__value { transition: stroke-dashoffset .6s ease; }
.gauge--great .gauge__value { stroke: var(--great); }
.gauge--good  .gauge__value { stroke: var(--good); }
.gauge--warn  .gauge__value { stroke: var(--warn); }
.gauge--bad   .gauge__value { stroke: var(--bad); }
.gauge--neutral .gauge__value { stroke: var(--neutral); }
.gauge__num { font: 700 1.45rem/1 var(--sans); fill: var(--text); }
.gauge__label { font: 600 .58rem/1 var(--sans); fill: var(--muted);
                text-transform: uppercase; letter-spacing: .08em; }

.bar { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar__fill { display: block; height: 100%; border-radius: 99px; transition: width .5s ease; }
.bar__fill--great { background: var(--great); }
.bar__fill--good  { background: var(--good); }
.bar__fill--warn  { background: var(--warn); }
.bar__fill--bad   { background: var(--bad); }
.bar__fill--neutral { background: var(--neutral); }

.score-pill {
  display: inline-flex; align-items: baseline; gap: 3px; font-weight: 750;
  padding: 3px 10px; border-radius: 8px; font-size: .85rem;
  background: var(--surface-3); color: var(--text);
}
.score-pill small { font-size: .68em; opacity: .6; font-weight: 600; }
.score-pill--great { background: var(--great-soft); color: var(--great); }
.score-pill--good  { background: var(--great-soft); color: var(--good); }
.score-pill--warn  { background: var(--warn-soft);  color: var(--warn); }
.score-pill--bad   { background: var(--bad-soft);   color: var(--bad); }
.score-pill--neutral { background: var(--neutral-soft); color: var(--neutral); }

/* --- Tablas --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
  text-align: left; font-weight: 650; font-size: .74rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); padding: 10px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
.table td {
  padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle;
  /* `break-word` y no `anywhere`: `anywhere` tambien reduce el ancho minimo
     de la columna y el navegador acaba partiendo las palabras letra a letra. */
  overflow-wrap: break-word;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .shrink { width: 1%; white-space: nowrap; }
.table__title { font-weight: 600; color: var(--text); display: block; }
.table__sub { color: var(--muted); font-size: .8rem; }
.table--compact td, .table--compact th { padding: 7px 12px; }

/* --- Formularios ---------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field > label, .label {
  display: block; font-weight: 600; font-size: .82rem; margin-bottom: 5px; color: var(--text-soft);
}
.field__help { font-size: .78rem; color: var(--muted); margin-top: 5px; line-height: 1.5; }
.field__error { font-size: .8rem; color: var(--bad); margin-top: 5px; }
input[type=text], input[type=url], input[type=email], input[type=password],
input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; font: inherit; font-size: .9rem;
  color: var(--text); background: var(--bg-soft);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type=color] { padding: 3px; height: 38px; cursor: pointer; }
textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
textarea.code { font-family: var(--mono); font-size: .82rem; line-height: 1.55; }
select {
  appearance: none; cursor: pointer; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer;
         font-size: .875rem; color: var(--text-soft); margin-bottom: 10px; }
.check input[type=checkbox], .check input[type=radio] {
  width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--accent); cursor: pointer; flex: none;
}
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
                padding-top: 6px; }
fieldset { border: 0; padding: 0; margin: 0 0 26px; }
legend { font-size: .78rem; text-transform: uppercase; letter-spacing: .07em;
         font-weight: 700; color: var(--muted); padding: 0 0 10px; }
.charcount { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.charcount.is-ok   { color: var(--great); }
.charcount.is-warn { color: var(--warn); }
.charcount.is-bad  { color: var(--bad); }

/* --- Mensajes ------------------------------------------------------------- */
.alert {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 15px; border-radius: var(--radius-sm); font-size: .88rem;
  border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 14px;
}
.alert--success { border-color: var(--great); background: var(--great-soft); color: var(--great); }
.alert--error   { border-color: var(--bad);   background: var(--bad-soft);   color: var(--bad); }
.alert--warning { border-color: var(--warn);  background: var(--warn-soft);  color: var(--warn); }
.alert--info    { border-color: var(--info);  background: var(--info-soft);  color: var(--info); }
.alert .icon { flex: none; margin-top: 2px; }
/* Los enlaces del aviso heredan su color, pero un boton dentro del aviso
   conserva el suyo: si no, queda texto verde sobre fondo azul, ilegible. */
.alert a:not(.btn) { color: inherit; text-decoration: underline; }
.alert .btn { text-decoration: none; }
.alert .btn--primary { color: #fff; }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200;
          display: flex; flex-direction: column; gap: 10px; max-width: 380px; }
.toast { background: var(--surface); border: 1px solid var(--border-strong);
         border-radius: var(--radius-sm); padding: 12px 15px; box-shadow: var(--shadow-lg);
         font-size: .88rem; animation: slidein .25s ease; }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } }

/* --- Pestanas ------------------------------------------------------------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border);
        margin-bottom: 20px; overflow-x: auto; }
.tab {
  padding: 9px 14px; font-size: .875rem; font-weight: 550; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
  cursor: pointer; background: none; border-top: 0; border-left: 0; border-right: 0;
  font-family: inherit;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--accent-text); border-bottom-color: var(--accent); }
.tab__count { font-size: .72rem; opacity: .7; margin-left: 4px; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* --- Estado vacio --------------------------------------------------------- */
.empty { text-align: center; padding: 46px 24px; color: var(--muted); }
.empty__icon {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 15px;
  display: grid; place-items: center; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--muted);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty p { max-width: 420px; margin: 0 auto 18px; font-size: .9rem; }

/* --- Utilidades ----------------------------------------------------------- */
.muted { color: var(--muted); }
.soft { color: var(--text-soft); }
.small { font-size: .82rem; }
.xs { font-size: .74rem; }
.bold { font-weight: 650; }
.mono { font-family: var(--mono); overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row--wrap { flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.col > * { min-width: 0; max-width: 100%; }
.gap-sm { gap: 6px; } .gap-lg { gap: 18px; }
.mt-0{margin-top:0}.mt-1{margin-top:8px}.mt-2{margin-top:16px}.mt-3{margin-top:24px}
.mb-0{margin-bottom:0}.mb-1{margin-bottom:8px}.mb-2{margin-bottom:16px}.mb-3{margin-bottom:24px}
.flex-1 { flex: 1; min-width: 0; }
.text-right { text-align: right; }
.icon { display: inline-block; vertical-align: -.15em; fill: none;
        stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.list-reset { list-style: none; padding: 0; margin: 0; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- Codigo y diff -------------------------------------------------------- */
pre.code-block {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; overflow-x: auto;
  font-size: .8rem; line-height: 1.55; margin: 0; color: var(--text-soft);
  max-height: 460px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.diff { font-family: var(--mono); font-size: .78rem; line-height: 1.6;
        border: 1px solid var(--border); border-radius: var(--radius-sm);
        overflow: hidden; background: var(--bg-soft); }
.diff__row { display: flex; gap: 0; padding: 1px 0; }
.diff__mark { flex: none; width: 26px; text-align: center; color: var(--muted);
              user-select: none; font-weight: 700; }
.diff__text { flex: 1; padding-right: 12px; white-space: pre-wrap; word-break: break-word; }
.diff__row--add { background: rgba(52,211,153,.10); }
.diff__row--add .diff__mark { color: var(--great); }
.diff__row--del { background: rgba(248,113,113,.10); }
.diff__row--del .diff__mark { color: var(--bad); }
.diff__row--del .diff__text { opacity: .82; }
.diff__row--skip { color: var(--muted); font-style: italic; padding: 5px 0 5px 26px;
                   background: var(--surface-2); font-size: .74rem; }

/* --- Bitacora de trabajos ------------------------------------------------- */
.joblog {
  /* La bitacora es oscura en ambos temas: se lee como un terminal. */
  background: #0f151d; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; font-family: var(--mono); font-size: .78rem; line-height: 1.65;
  color: #b9c7d8; max-height: 480px; overflow-y: auto; white-space: pre-wrap;
  word-break: break-word;
}
html[data-theme="dark"] .joblog { background: #06090e; color: #b9c7d8; }
.progress { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress__fill { height: 100%; background: linear-gradient(90deg, var(--accent), #a05cff);
                  border-radius: 99px; transition: width .4s ease; }
.progress--striped .progress__fill {
  background-image: linear-gradient(45deg, rgba(255,255,255,.16) 25%, transparent 25%,
    transparent 50%, rgba(255,255,255,.16) 50%, rgba(255,255,255,.16) 75%, transparent 75%);
  background-size: 18px 18px; animation: stripes 1s linear infinite;
}
@keyframes stripes { from { background-position: 0 0; } to { background-position: 18px 0; } }

/* --- Incidencias SEO ------------------------------------------------------ */
.issue {
  display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.issue:last-child { border-bottom: 0; }
.issue__bullet { flex: none; width: 4px; border-radius: 4px; }
.issue__bullet--critical { background: var(--bad); }
.issue__bullet--warning  { background: var(--warn); }
.issue__bullet--notice   { background: var(--info); }
.issue__bullet--info     { background: var(--neutral); }
.issue__body { flex: 1; min-width: 0; }
.issue__title { font-weight: 600; margin-bottom: 3px; display: flex; gap: 8px;
                align-items: center; flex-wrap: wrap; }
.issue__detail { color: var(--text-soft); font-size: .85rem; margin-bottom: 4px; }
.issue__fix { font-size: .83rem; color: var(--muted); display: flex; gap: 6px; }
.issue__fix b { color: var(--accent-text); font-weight: 600; flex: none; }
.issue__element { font-family: var(--mono); font-size: .76rem; color: var(--muted);
                  background: var(--surface-2); padding: 4px 8px; border-radius: 6px;
                  margin-top: 6px; word-break: break-word; }

/* --- SERP preview --------------------------------------------------------- */
.serp {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; max-width: 620px;
}
.serp__url { color: var(--great); font-size: .78rem; margin-bottom: 2px; }
.serp__title { color: #1a0dab; font-size: 1.08rem; line-height: 1.35; margin-bottom: 3px; }
html[data-theme="dark"] .serp__title { color: #8ab4f8; }
.serp__desc { color: var(--text-soft); font-size: .84rem; line-height: 1.5; }

/* --- Contenido enriquecido (vista previa embebida) ------------------------ */
.prose { line-height: 1.75; color: var(--text-soft); }
.prose h2 { font-size: 1.3rem; margin: 1.6em 0 .5em; color: var(--text); }
.prose h3 { font-size: 1.08rem; margin: 1.4em 0 .4em; color: var(--text); }
.prose ul, .prose ol { margin: 0 0 1.1em 1.2em; padding-left: .4em; }
.prose li { margin: .3em 0; }
.prose table { width: 100%; border-collapse: collapse; margin: 1.2em 0; font-size: .88rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 11px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose blockquote { margin: 1.2em 0; padding: .7em 1.1em; border-left: 3px solid var(--accent);
                    background: var(--accent-soft); border-radius: 0 8px 8px 0; }
.prose img { border-radius: 8px; }
.prose a { color: var(--accent-text); }

/* --- Filtros -------------------------------------------------------------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
           margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 150px; }
.filters input, .filters select { font-size: .85rem; padding: 7px 11px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px;
  border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface-2);
  font-size: .8rem; color: var(--text-soft); cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.chip.is-active { background: var(--accent-soft); border-color: var(--accent-line);
                  color: var(--accent-text); font-weight: 600; }

/* --- Barra de acciones en lote -------------------------------------------- */
.bulkbar {
  position: sticky; bottom: 16px; z-index: 20; margin-top: 16px;
  background: var(--surface); border: 1px solid var(--accent-line);
  border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow-lg);
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}

/* --- Login / setup -------------------------------------------------------- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(108,140,255,.16), transparent 60%),
    radial-gradient(700px 400px at 95% 110%, rgba(160,92,255,.13), transparent 60%),
    var(--bg);
}
.auth__card { width: 100%; max-width: 400px; }
.auth__brand { text-align: center; margin-bottom: 22px; }
.auth__brand .brand-mark { width: 46px; height: 46px; margin: 0 auto 12px;
                           border-radius: 14px; font-size: 1.1rem; }
.auth__brand h1 { font-size: 1.45rem; margin-bottom: 4px; }

/* --- Pasos ---------------------------------------------------------------- */
.steps { display: flex; gap: 0; margin-bottom: 24px; }
.step { flex: 1; text-align: center; position: relative; padding-top: 30px;
        font-size: .8rem; color: var(--muted); }
.step::before {
  content: attr(data-n); position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2);
  border: 1px solid var(--border-strong); display: grid; place-items: center;
  font-size: .76rem; font-weight: 700; color: var(--muted);
}
.step::after { content: ""; position: absolute; top: 12px; left: 50%; width: 100%;
               height: 1px; background: var(--border); z-index: -1; }
.step:last-child::after { display: none; }
.step.is-active { color: var(--accent-text); font-weight: 600; }
.step.is-active::before { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.is-done::before { background: var(--great); border-color: var(--great); color: #06231a; }

/* --- Responsive ----------------------------------------------------------- */
.menu-toggle { display: none; }
@media (max-width: 940px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50;
  }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 0 14px; }
  .grid--sidebar { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .page-head { flex-direction: column; }
  .page-head__actions { width: 100%; }
  .kpi__value { font-size: 1.5rem; }
}

/* --- Impresion ------------------------------------------------------------ */
@media print {
  .sidebar, .topbar, .page-head__actions, .btn, .bulkbar { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #ccc; box-shadow: none; break-inside: avoid; }
  .content { padding: 0; max-width: none; }
}

/* ==========================================================================
   Movil y PWA
   ========================================================================== */

/* --- Navegacion inferior (solo en pantallas pequenas) --------------------- */
.bottomnav {
  display: none;
  position: fixed;
  left: 0; bottom: 0;
  width: 100%;
  max-width: 100vw;
  z-index: 55;
  background: color-mix(in srgb, var(--bg-soft) 94%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.bottomnav__row { display: flex; }
.bottomnav__link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 4px 8px;
  min-height: 56px;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .01em;
  position: relative;
  text-decoration: none;
}
.bottomnav__link:hover { text-decoration: none; }
.bottomnav__link.is-active { color: var(--accent-text); }
.bottomnav__link.is-active::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 30px; height: 2px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}
.bottomnav__link .icon { width: 21px; height: 21px; }
.bottomnav__badge {
  position: absolute;
  top: 6px;
  margin-left: 20px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  min-width: 16px;
  padding: 0 4px;
  font-size: .62rem;
  line-height: 16px;
  text-align: center;
  font-weight: 700;
}

/* --- Boton de instalacion de la PWA -------------------------------------- */
.install-banner {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.install-banner.is-visible { display: flex; }
.install-banner__text { flex: 1; min-width: 0; font-size: .86rem; }
.install-banner__text b { display: block; }

/* --- Tablas que se apilan en movil --------------------------------------- */
/* Se usa en las tablas que se consultan a menudo desde el telefono. El resto
   conservan el desplazamiento horizontal, que para datos densos es mejor. */
@media (max-width: 760px) {
  .table--responsive thead { display: none; }
  .table--responsive,
  .table--responsive tbody,
  .table--responsive tr,
  .table--responsive td { display: block; width: 100%; }
  .table--responsive tr {
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
  }
  .table--responsive tr:last-child { border-bottom: 0; }
  .table--responsive tbody tr:hover { background: transparent; }
  .table--responsive td {
    border: 0;
    padding: 3px 0;
    text-align: left !important;
  }
  .table--responsive td:empty { display: none; }
  .table--responsive td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-size: .74rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-right: 6px;
  }
  .table--responsive td[data-label="_"]::before { content: none; }
  .table--responsive td.shrink { width: auto; white-space: normal; }
  /* La celda de la casilla de seleccion se ancla arriba a la derecha. */
  .table--responsive tr { position: relative; padding-right: 44px; }
  .table--responsive td.cell-check {
    position: absolute;
    top: 12px; right: 0;
    width: 34px;
    padding: 0;
  }
  .table--responsive td.cell-check::before { content: none; }
  .table--responsive .cell-actions { margin-top: 8px; }
}

/* --- Ajustes generales para pantallas pequenas --------------------------- */
@media (max-width: 940px) {
  :root { --bottom-nav-h: calc(56px + var(--safe-bottom)); }

  .bottomnav { display: block; }
  .main { padding-bottom: var(--bottom-nav-h); }

  .sidebar {
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    width: min(84vw, 300px);
    flex-basis: min(84vw, 300px);
  }
  .topbar {
    padding-top: var(--safe-top);
    height: calc(var(--header-h) + var(--safe-top));
    padding-left: max(14px, var(--safe-left));
    padding-right: max(14px, var(--safe-right));
  }
  .content {
    padding-left: max(16px, var(--safe-left));
    padding-right: max(16px, var(--safe-right));
  }

  /* Areas tactiles comodas: minimo 44 px. */
  .btn { min-height: 42px; padding: 9px 15px; }
  .btn--sm { min-height: 36px; padding: 7px 12px; }
  .nav__link, .nav__client { min-height: 44px; }
  .tab { padding: 11px 14px; min-height: 44px; }
  .check input[type=checkbox],
  .check input[type=radio] { width: 20px; height: 20px; }
  table.table td .btn--sm { min-height: 34px; }

  /* iOS hace zoom si la fuente del campo baja de 16 px. */
  input[type=text], input[type=url], input[type=email], input[type=password],
  input[type=number], input[type=search], select, textarea {
    font-size: 16px;
    padding: 11px 13px;
  }
  .filters input, .filters select { font-size: 16px; padding: 10px 12px; }

  .filters { gap: 8px; }
  .filters .field { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filters .field:first-child { flex-basis: 100%; }
  .filters > .btn { flex: 1 1 100%; justify-content: center; }
  .filters select { padding-right: 30px; }

  .page-head { gap: 12px; }
  .page-head__actions { width: 100%; }
  .page-head__actions .btn { flex: 1; justify-content: center; }
  .page-head__actions form { flex: 1; display: flex; }
  .page-head__actions form .btn { width: 100%; }

  .card__body { padding: 15px; }
  .card__head { padding: 13px 15px; flex-wrap: wrap; gap: 8px 10px; }
  .card__head > h2, .card__head > h3 { min-width: 0; }
  .card__head .btn { flex: 0 1 auto; min-width: 0; }
  .grid { gap: 13px; }
  .grid--2, .grid--3 { grid-template-columns: minmax(0, 1fr); }
  /* Los indicadores son cortos: dos por fila evitan un panel kilometrico. */
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .kpi { padding: 14px 15px; }
  .kpi__value { font-size: 1.55rem; }

  textarea { min-height: 130px; }
  textarea.code { font-size: 13px; }

  .bulkbar {
    bottom: calc(var(--bottom-nav-h) + 10px);
    flex-direction: column;
    align-items: stretch;
    gap: 9px;
  }
  .bulkbar select, .bulkbar .btn { width: 100%; }
  .bulkbar .flex-1 { display: none; }

  .diff { font-size: .72rem; }
  .diff__mark { width: 20px; }
  .joblog { font-size: .72rem; max-height: 340px; }
  .code-block { font-size: .72rem; }

  .serp { max-width: none; }
  .gauge { margin: 0 auto; }
  .sheet { padding: 24px 18px; }
}

@media (max-width: 620px) {
  .content { padding-top: 16px; }
  h1 { font-size: 1.4rem; }
  .page-head h1 { font-size: 1.35rem; }
  .avatar--lg { width: 38px; height: 38px; border-radius: 11px; font-size: .85rem; }
  .kpi__value { font-size: 1.45rem; }
  .table th, .table td { padding: 9px 11px; }
  .badge { font-size: .7rem; }
  .breadcrumb { font-size: .76rem; }
  .install-banner { flex-direction: column; align-items: stretch; }
  .install-banner .btn { width: 100%; }
}

/* --- Modo aplicacion instalada ------------------------------------------ */
@media (display-mode: standalone) {
  /* Sin barra del navegador, la cabecera propia gana peso visual. */
  .topbar { border-bottom-color: var(--border-strong); }
  /* El tirón para recargar del navegador no existe: se evita el rebote. */
  body { overscroll-behavior: none; }
}

/* --- Accesibilidad ------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Textos que solo aparecen en la version movil de las tablas apiladas. */
.only-mobile { display: none; }
@media (max-width: 760px) {
  .only-mobile { display: inline; }
  .table--responsive .cell-actions .btn { width: 100%; justify-content: center; }
}

/* --- Tablas apiladas: datos cortos en la misma linea --------------------- */
@media (max-width: 760px) {
  .table--responsive tr { display: flex; flex-wrap: wrap; gap: 2px 16px; }
  .table--responsive td { width: auto; flex: 0 0 auto; min-width: 0; }
  .table--responsive .table__title,
  .table--responsive .table__sub { overflow-wrap: anywhere; }
  /* La primera celda (titulo) siempre ocupa la fila entera. */
  .table--responsive td:first-of-type,
  .table--responsive td[data-label="_"]:first-of-type { flex: 1 1 100%; }
  .table--responsive .cell-actions { flex: 1 1 100%; }
  .table--responsive td[data-label]:not([data-label="_"]) {
    font-size: .82rem;
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
  }
}

@media (max-width: 620px) {
  .filters .field { flex: 1 1 100%; }
}

@media (max-width: 359px) {
  .grid--4 { grid-template-columns: minmax(0, 1fr); }
}

/* --- Selector de tipo de cliente ----------------------------------------- */
.modo-opciones { display: grid; gap: 8px; }
.modo-opciones label {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 11px 13px; cursor: pointer; font-size: .89rem;
  transition: border-color .12s, background .12s;
}
.modo-opciones label:hover { border-color: var(--accent-line); }
.modo-opciones input[type=radio] {
  width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--accent);
  flex: none; cursor: pointer;
}
.modo-opciones input[type=radio]:checked + span,
.modo-opciones label:has(input:checked) { color: var(--text); }
.modo-opciones label:has(input:checked) {
  border-color: var(--accent); background: var(--accent-soft);
}
