/* ============================================================================
   BrandTracker — sistema visual "audio intelligence".
   Self-contained (sin CDNs: el panel vive en una NAS sin internet garantizado).
   Tema claro/oscuro por tokens; identidad verde señal + acentos VU/corte.
   ============================================================================ */

/* ------------------------------------------------------------------ tokens */
:root {
  --bg:            #eef1f0;
  --surface:       #ffffff;
  --surface-2:     #f5f8f6;
  --surface-hover: #eef3f0;
  --border:        #e4e8e6;
  --border-strong: #d3dad6;
  --text:          #14211d;
  --text-muted:    #5b6a63;
  --text-faint:    #8a978f;
  --brand:         #0f7b5f;
  --brand-ink:     #0c6650;
  --brand-tint:    #e6f1ec;
  --amber:         #b47b16;
  --amber-tint:    #f7edd8;
  --danger:        #c23b2e;
  --danger-tint:   #fbe9e7;
  --info:          #33527e;
  --info-tint:     #e8eef8;

  --shadow-sm: 0 1px 2px rgba(20, 33, 29, .06), 0 1px 3px rgba(20, 33, 29, .05);
  --shadow-md: 0 4px 12px rgba(20, 33, 29, .08), 0 2px 4px rgba(20, 33, 29, .05);
  --shadow-lg: 0 12px 32px rgba(20, 33, 29, .14);

  --radius:    14px;
  --radius-sm: 9px;
  --radius-xs: 6px;
  --pill:      999px;

  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --side-w: 250px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg:            #0d1310;
  --surface:       #141c18;
  --surface-2:     #1a231e;
  --surface-hover: #1f2a24;
  --border:        #26322c;
  --border-strong: #35443b;
  --text:          #e7efea;
  --text-muted:    #9fb0a8;
  --text-faint:    #71837a;
  --brand:         #33bd97;
  --brand-ink:     #45cca6;
  --brand-tint:    #12271f;
  --amber:         #daa441;
  --amber-tint:    #2b2210;
  --danger:        #f0776a;
  --danger-tint:   #2b1512;
  --info:          #8fb0e6;
  --info-tint:     #16202f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0d1310;
    --surface:       #141c18;
    --surface-2:     #1a231e;
    --surface-hover: #1f2a24;
    --border:        #26322c;
    --border-strong: #35443b;
    --text:          #e7efea;
    --text-muted:    #9fb0a8;
    --text-faint:    #71837a;
    --brand:         #33bd97;
    --brand-ink:     #45cca6;
    --brand-tint:    #12271f;
    --amber:         #daa441;
    --amber-tint:    #2b2210;
    --danger:        #f0776a;
    --danger-tint:   #2b1512;
    --info:          #8fb0e6;
    --info-tint:     #16202f;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 3px; }
svg { width: 1em; height: 1em; flex: 0 0 auto; vertical-align: -.15em; }
code { font-family: var(--mono); font-size: .86em; background: var(--surface-2); border: 1px solid var(--border); padding: .05em .35em; border-radius: var(--radius-xs); }
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ layout */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column; gap: .4rem;
  padding: 1.1rem .8rem 1rem; background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand { padding: .3rem .5rem 1rem; }
.onair {
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: var(--mono); font-size: .62rem; letter-spacing: .18em; font-weight: 600;
  color: var(--brand); background: var(--brand-tint);
  padding: .2rem .5rem; border-radius: var(--pill);
}
.onair .dot { width: .45rem; height: .45rem; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 0 var(--brand); animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 55%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .onair .dot { animation: none; } }
.wordmark { font-size: 1.32rem; font-weight: 800; letter-spacing: .02em; margin: .55rem 0 .1rem; }
.wordmark .sep { color: var(--brand); }
.tagline { margin: 0; color: var(--text-muted); font-size: .74rem; letter-spacing: .02em; }

.nav { display: flex; flex-direction: column; gap: .15rem; }
.nav-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .7rem; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 550; font-size: .92rem;
  text-decoration: none; position: relative; transition: background .13s, color .13s;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--brand-tint); color: var(--brand-ink); }
.nav-link.active::before { content: ""; position: absolute; left: -0.8rem; top: 20%; bottom: 20%; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.nav-link svg { width: 19px; height: 19px; flex: 0 0 auto; opacity: .9; }
.nav-link .count { margin-left: auto; font-family: var(--mono); font-size: .7rem; color: var(--text-faint); background: var(--surface-2); border: 1px solid var(--border); padding: .02rem .4rem; border-radius: var(--pill); }
.nav-link.active .count { color: var(--brand-ink); background: var(--surface); border-color: color-mix(in srgb, var(--brand) 25%, var(--border)); }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; padding-top: .6rem; border-top: 1px solid var(--border); }
.side-note { color: var(--text-faint); font-size: .68rem; line-height: 1.4; padding: 0 .5rem; }

.theme-toggle {
  display: flex; align-items: center; gap: .5rem; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
  padding: .5rem .7rem; border-radius: var(--radius-sm); font: inherit; font-size: .82rem; font-weight: 550;
  transition: background .13s, color .13s;
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: inline; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theme-toggle .moon { display: inline; } :root:not([data-theme="light"]) .theme-toggle .sun { display: none; } }

/* ------------------------------------------------------------------ main */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 1rem 1.6rem; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border);
}
.topbar .page-title { font-size: 1.28rem; font-weight: 750; }
.topbar .page-sub { margin: .1rem 0 0; color: var(--text-muted); font-size: .84rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.livepill {
  display: inline-flex; align-items: center; gap: .45rem;
  font-family: var(--mono); font-size: .74rem; font-weight: 600; letter-spacing: .02em;
  padding: .34rem .7rem; border-radius: var(--pill);
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
}
.livepill .led { width: .5rem; height: .5rem; border-radius: 50%; background: var(--text-faint); transition: background .3s; }
.livepill.on { color: var(--brand-ink); border-color: color-mix(in srgb, var(--brand) 30%, var(--border)); }
.livepill.on .led { background: var(--brand); animation: pulse 1.8s ease-out infinite; }

/* Fluido: ocupa toda la pantalla disponible, sin franjas muertas */
.content { padding: 1.4rem 1.8rem 3rem; width: 100%; }
.section-title { display: flex; align-items: baseline; gap: .6rem; margin: 1.9rem 0 .9rem; }
.section-title h2 { font-size: 1.02rem; font-weight: 700; letter-spacing: .01em; }
.section-title .muted { color: var(--text-faint); font-size: .82rem; font-weight: 500; }
.section-title:first-child { margin-top: .2rem; }

/* ------------------------------------------------------------------ KPI cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: .8rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi .kpi-top { display: flex; align-items: center; gap: .5rem; color: var(--text-muted); }
.kpi .kpi-ico { display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius-xs); background: var(--surface-2); color: var(--text-muted); }
.kpi .kpi-ico svg { width: 17px; height: 17px; }
.kpi .kpi-label { font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; font-weight: 600; }
.kpi .kpi-val { font-size: 1.85rem; font-weight: 750; letter-spacing: -.02em; margin-top: .4rem; font-variant-numeric: tabular-nums; }
.kpi .kpi-val small { font-size: .9rem; font-weight: 600; color: var(--text-faint); }
.kpi.accent { border-color: color-mix(in srgb, var(--brand) 30%, var(--border)); }
.kpi.accent .kpi-ico { background: var(--brand-tint); color: var(--brand); }
.kpi.live .kpi-val { color: var(--text-faint); transition: color .3s; }
.kpi.live.on { background: linear-gradient(180deg, var(--brand-tint), var(--surface)); border-color: color-mix(in srgb, var(--brand) 34%, var(--border)); }
.kpi.live.on .kpi-val { color: var(--brand-ink); }
.kpi.live.on .kpi-ico { background: var(--brand); color: #fff; }
.kpi .kpi-val.bad { color: var(--danger); }
.kpi.warn.has .kpi-ico { background: var(--amber-tint); color: var(--amber); }

/* ------------------------------------------------------------------ panels */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel-pad { padding: 1.1rem 1.2rem 1.2rem; }
.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: .9rem; align-items: start; }
/* Dos paneles al mismo peso: analítica y rendimiento comparan dos listas. */
.grid-even { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; align-items: start; }
/* Barra de proporción dentro de una tabla (la fila más alta llena el ancho).
   Nombre propio: `.meter` es el medidor de límites de plan, que es otra cosa. */
.ratio { display: block; height: 7px; border-radius: var(--pill); background: var(--surface-2); overflow: hidden; }
.ratio-fill { display: block; height: 100%; border-radius: var(--pill); background: var(--brand); }
/* Selector de periodo: el activo se queda marcado. */
.periods { display: inline-flex; gap: .35rem; }
.periods .chip { text-decoration: none; background: var(--surface-2); color: var(--text-muted); }
.periods .chip.on { background: var(--brand); color: #fff; }
@media (max-width: 940px) { .grid-2, .grid-even { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ chart */
.chart { --gap: 3px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: .9rem; }
.chart-head h3 { font-size: .95rem; font-weight: 700; }
.chart-head .hint { color: var(--text-faint); font-size: .76rem; }
.bars { display: flex; align-items: flex-end; gap: var(--gap); height: 148px; padding-top: 14px; }
.bar-col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; min-width: 0; }
.bar {
  width: 100%; max-width: 26px; min-height: 3px; height: var(--h, 3px);
  background: var(--brand); border-radius: 4px 4px 2px 2px;
  transition: filter .12s, transform .12s; transform-origin: bottom;
}
.bar-col:hover .bar { filter: brightness(1.08); }
.bar-col.empty .bar { background: var(--border-strong); opacity: .5; }
.bar-tip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%) translateY(4px);
  background: var(--text); color: var(--surface); font-size: .72rem; font-weight: 600; white-space: nowrap;
  padding: .28rem .5rem; border-radius: var(--radius-xs); box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none; transition: opacity .12s, transform .12s; z-index: 5;
}
.bar-tip b { font-family: var(--mono); }
.bar-col:hover .bar-tip { opacity: 1; transform: translateX(-50%) translateY(0); }
.bars-axis { display: flex; justify-content: space-between; margin-top: .5rem; color: var(--text-faint); font-size: .68rem; font-family: var(--mono); }

/* pipeline panel */
.pipe { list-style: none; margin: .3rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.pipe li { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.pipe li b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.pipe-foot { margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--border); color: var(--text-muted); font-size: .82rem; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

/* barras de progreso de transcripción */
.proc + .proc { margin-top: .9rem; }
.proc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .38rem; }
.proc-title { font-weight: 600; font-size: .9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proc-meta { color: var(--text-muted); font-family: var(--mono); font-size: .75rem; white-space: nowrap; flex: 0 0 auto; }
.proc-meta b { color: var(--brand-ink); }
.bar-track { height: 9px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--pill); overflow: hidden; }
.bar-fill { height: 100%; min-width: 4px; border-radius: var(--pill); background: linear-gradient(90deg, color-mix(in srgb, var(--brand) 78%, #fff 0%), var(--brand)); transition: width .6s cubic-bezier(.4, 0, .2, 1); }
.bar-fill.indet { width: 34%; background: linear-gradient(90deg, transparent, var(--brand), transparent); animation: indet 1.25s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -34%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .bar-fill.indet { animation: none; margin-left: 0; } }
.proc-idle { color: var(--text-faint); font-size: .86rem; margin: .2rem 0; }

/* ------------------------------------------------------------------ mentions */
.mentions { display: flex; flex-direction: column; gap: .6rem; list-style: none; margin: 0; padding: 0; }
.mention {
  display: flex; gap: .9rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow-sm);
  transition: box-shadow .13s, border-color .13s;
}
.mention:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.wave { flex: 0 0 6px; border-radius: var(--pill); background: linear-gradient(var(--brand), color-mix(in srgb, var(--brand) 45%, transparent)); }
.mbody { min-width: 0; flex: 1; }
.mline { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: 0 0 .3rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; font-weight: 650; font-size: .82rem; color: var(--brand-ink); background: var(--brand-tint); padding: .12rem .55rem; border-radius: var(--pill); }
.who { color: var(--text-muted); font-size: .84rem; }
.snippet { margin: .1rem 0 .45rem; color: var(--text); font-size: .93rem; }
.msrc { margin: 0 0 .25rem; color: var(--text-muted); font-size: .8rem; font-weight: 600; }
.snippet strong em { font-weight: 750; font-style: italic; color: var(--brand-ink); background: var(--brand-tint); padding: 0 .15em; border-radius: 3px; }
.mmeta { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; color: var(--text-faint); font-size: .74rem; font-family: var(--mono); }

/* menciones agrupadas por episodio */
.mgroup { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 1rem; overflow: hidden; }
.mgroup-head { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.mgroup-ico { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-xs); background: var(--brand-tint); color: var(--brand); flex: 0 0 auto; }
.mgroup-ico svg { width: 18px; height: 18px; }
.mgroup-titles { min-width: 0; flex: 1; }
.mgroup-ep { margin: 0; font-weight: 700; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mgroup-src { margin: 0; color: var(--text-muted); font-size: .78rem; }
.mgroup-count { flex: 0 0 auto; font-family: var(--mono); font-size: .72rem; font-weight: 600; color: var(--brand-ink); background: var(--brand-tint); padding: .18rem .55rem; border-radius: var(--pill); }
.mentions.grouped { padding: .7rem; gap: .5rem; }
.mentions.grouped .mention { border: 0; border-left: 3px solid var(--brand-tint); border-radius: var(--radius-xs); box-shadow: none; background: transparent; padding: .4rem .8rem; }
.mentions.grouped .mention:hover { background: var(--surface-hover); box-shadow: none; }
.mmeta .sep-dot::before { content: "·"; margin-right: .5rem; }

/* selector compacto del estado de revisión de una mención */
.mstatus { margin-left: auto; flex: 0 0 auto; }
.mstatus-sel {
  font: inherit; font-size: .76rem; font-weight: 600; cursor: pointer;
  padding: .2rem .4rem; border-radius: var(--radius-xs);
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.mstatus-sel:hover { border-color: var(--border-strong); color: var(--text); }
.badge-ok { color: var(--brand-ink); }
.badge-mut { color: var(--text-faint); }

/* ------------------------------------------------------------------ tables */
/* Sin scroll lateral y columnas DINÁMICAS (layout automático):
   - columnas cortas (c-xs/sm/md, c-act-*): width:1% + nowrap global → se ciñen
     exactamente a su contenido, que se ve SIEMPRE completo (IDs, fechas…);
   - columnas de texto (c-main principal, c-lg secundaria): se reparten el
     resto y truncan con elipsis; max-width:0 impide que un título largo
     ensanche la tabla. c-main/c-lg deben ir en el <th> Y en los <td>.
   En pantallas estrechas las columnas secundarias (hide-*) se ocultan. */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
table.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { text-align: left; font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 650; color: var(--text-muted); padding: .7rem .9rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table th, .table td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table td { padding: .65rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover td { background: var(--surface-hover); }
.table .mono { font-family: var(--mono); font-size: .82rem; color: var(--text-muted); }
.table .url { color: var(--text-muted); font-family: var(--mono); font-size: .78rem; }
.table .strong { font-weight: 600; color: var(--text); }
/* el wrap ya no recorta (overflow visible para los popovers): redondea celdas extremas */
.table thead tr:first-child th:first-child { border-top-left-radius: calc(var(--radius) - 1px); }
.table thead tr:first-child th:last-child { border-top-right-radius: calc(var(--radius) - 1px); }
.table tr:last-child td:first-child { border-bottom-left-radius: calc(var(--radius) - 1px); }
.table tr:last-child td:last-child { border-bottom-right-radius: calc(var(--radius) - 1px); }
/* columnas ceñidas al contenido: nunca se cortan */
.table .c-xs, .table .c-sm, .table .c-md,
.table .c-act-1, .table .c-act-2, .table .c-act-3 { width: 1%; }
/* columnas de texto flexibles: absorben el resto y truncan con elipsis */
.table .c-main { width: 62%; max-width: 0; }
.table .c-lg { width: 38%; max-width: 0; }
.table td.cell-vis { overflow: visible; }  /* celdas con popover (motivo de fallo) */
@media (max-width: 1100px) { .table .hide-md { display: none; } }
@media (max-width: 720px) { .table .hide-sm { display: none; } }
.key code { font-size: .74rem; word-break: break-all; }
.keyrow { display: flex; align-items: center; gap: .5rem; }

/* filtro por columna + ordenación de tablas (inyectados por JS) */
.table-toolbar { display: flex; justify-content: flex-end; margin: 0 0 .4rem; }
.table-toolbar .tcount { color: var(--text-faint); font-size: .74rem; font-family: var(--mono); }
.table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.sortable:hover { color: var(--text); }
.table th.sortable::after { content: "↕"; opacity: .35; margin-left: .35rem; }
.table th.sortable.asc::after { content: "↑"; opacity: 1; color: var(--brand-ink); }
.table th.sortable.desc::after { content: "↓"; opacity: 1; color: var(--brand-ink); }
.table thead .filter-row th { padding: .35rem .5rem .55rem; background: var(--surface); }
.filter-row input {
  font: inherit; font-size: .76rem; width: 100%; min-width: 3.2rem; padding: .3rem .45rem;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-xs);
}
.filter-row input:focus { outline: none; border-color: var(--brand); background: var(--surface); }
.table td.empty-cell { text-align: center; color: var(--text-faint); padding: 1.2rem; white-space: normal; }

/* paginador */
.pager { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; margin: .8rem 0 0; }
.pnum {
  display: inline-block; min-width: 2rem; text-align: center; padding: .3rem .55rem;
  font-family: var(--mono); font-size: .78rem; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xs); text-decoration: none;
}
a.pnum:hover { border-color: var(--brand); color: var(--brand-ink); text-decoration: none; }
.pnum.current { background: var(--brand); color: #fff; border-color: var(--brand); }
.pnum.off { opacity: .4; }
.pdots { color: var(--text-faint); padding: 0 .1rem; }
.ptotal { margin-left: auto; color: var(--text-faint); font-size: .74rem; font-family: var(--mono); }

/* configuración: bloques editables a la izquierda, información a la derecha */
.config-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); gap: .9rem; align-items: start; }
.config-forms { display: flex; flex-direction: column; gap: .9rem; min-width: 0; }
.config-info { position: sticky; top: 5.5rem; min-width: 0; }
.save-row { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.save-row .hint { color: var(--text-faint); font-size: .78rem; }
@media (max-width: 1000px) { .config-grid { grid-template-columns: 1fr; } .config-info { position: static; } }

/* configuración: info del sistema */
.sysinfo { margin: 0; }
.sysrow { display: flex; justify-content: space-between; gap: 1rem; padding: .42rem 0; border-bottom: 1px dashed var(--border); }
.sysrow:last-child { border-bottom: 0; }
.sysinfo dt { color: var(--text-muted); font-size: .85rem; }
.sysinfo dd { margin: 0; font-family: var(--mono); font-size: .82rem; }

/* status pills */
.pill { display: inline-flex; align-items: center; gap: .35rem; font-size: .72rem; font-weight: 650; padding: .16rem .5rem; border-radius: var(--pill); font-family: var(--mono); letter-spacing: .01em; }
.pill::before { content: ""; width: .42rem; height: .42rem; border-radius: 50%; background: currentColor; }
.pill.done { color: var(--brand-ink); background: var(--brand-tint); }
.pill.queued, .pill.pending { color: var(--amber); background: var(--amber-tint); }
.pill.processing { color: var(--info); background: var(--info-tint); }
/* descargando: paso previo a la cola, aún sin audio en disco */
.pill.downloading { color: var(--info); background: var(--info-tint); opacity: .85; }
.pill.failed { color: var(--danger); background: var(--danger-tint); }
.pill.prio { color: var(--amber); background: var(--amber-tint); }
.pill.prio::before { display: none; }  /* el rayo ya hace de indicador */

/* popover del motivo de fallo */
.pop { position: relative; display: inline-block; }
.pop > summary { list-style: none; cursor: pointer; user-select: none; }
.pop > summary::-webkit-details-marker { display: none; }
.pop > summary svg { width: 12px; height: 12px; transition: transform .15s; }
.pop[open] > summary svg { transform: rotate(180deg); }
.pop-body {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; width: min(340px, 70vw);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: .7rem .85rem; font-size: .8rem; white-space: normal;
}
.pop-title { margin: 0 0 .3rem; font-weight: 700; color: var(--danger); display: flex; align-items: center; gap: .35rem; }
.pop-text { margin: 0; color: var(--text); font-family: var(--mono); font-size: .75rem; word-break: break-word; max-height: 9rem; overflow-y: auto; }
.pop-hint { margin: .45rem 0 0; color: var(--text-faint); font-size: .72rem; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; white-space: nowrap;
  font: inherit; font-size: .85rem; font-weight: 600; line-height: 1;
  padding: .55rem .9rem; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  transition: background .12s, border-color .12s, transform .06s, box-shadow .12s;
}
.btn:hover { background: var(--surface-hover); border-color: var(--text-faint); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-mini { padding: .34rem .6rem; font-size: .76rem; border-radius: var(--radius-xs); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.inline-form { display: inline; margin: 0; }
.row-actions { display: flex; gap: .35rem; flex-wrap: nowrap; justify-content: flex-end; }

/* ------------------------------------------------------------------ forms / disclosure */
/* tarjeta genérica (barras de filtros de menciones y episodios) */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card.form-grid { padding: 1rem 1rem 1.1rem; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .9rem; }
.adder { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; box-shadow: var(--shadow-sm); overflow: hidden; }
.adder > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem;
  padding: .8rem 1rem; font-weight: 650; font-size: .9rem; color: var(--brand-ink); user-select: none;
}
.adder > summary::-webkit-details-marker { display: none; }
.adder > summary .chev { margin-left: auto; transition: transform .18s; color: var(--text-faint); display: inline-flex; }
.adder[open] > summary .chev { transform: rotate(180deg); }
.adder > summary svg { width: 18px; height: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .9rem; padding: 0 1rem 1.1rem; align-items: end; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label, .field > span.lbl { font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; font-weight: 650; color: var(--text-muted); }
/* Los checkboxes/radios quedan FUERA a propósito: heredar width:100% +
   padding + borde los estiraba y empujaba las opciones fuera del dropdown. */
.field input:not([type="checkbox"]):not([type="radio"]), .field select {
  font: inherit; font-size: .9rem; padding: .55rem .65rem; width: 100%;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.field input:not([type="checkbox"]):not([type="radio"]):focus, .field select:focus { outline: none; border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px var(--brand-tint); }
.field.span-2 { grid-column: span 2; }
.field .check { display: flex; align-items: center; gap: .45rem; text-transform: none; letter-spacing: 0; font-size: .86rem; font-weight: 500; color: var(--text); }
.field .check input { width: auto; accent-color: var(--brand); }
.field.actions { align-self: end; }
.field-hint { grid-column: 1 / -1; color: var(--text-faint); font-size: .76rem; margin: -.3rem 0 0; }

/* dropdown con checkboxes (filtro de estados fijos).
   El ancho se adapta al contenido (la opción más larga manda), no a la rejilla. */
.dd { position: relative; width: max-content; min-width: 8rem; }
.dd > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: space-between; gap: .7rem;
  font: inherit; font-size: .9rem; padding: .55rem .65rem;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.dd > summary::-webkit-details-marker { display: none; }
.dd > summary .chev { display: inline-flex; transition: transform .15s; color: var(--text-faint); }
.dd[open] > summary .chev { transform: rotate(180deg); }
.dd[open] > summary { border-color: var(--brand); background: var(--surface); }
.dd-panel {
  position: absolute; z-index: 45; top: calc(100% + 4px); left: 0;
  width: max-content; min-width: 100%;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: .45rem; display: flex; flex-direction: column; gap: .15rem;
}
.dd-opt {
  display: flex; align-items: center; justify-content: flex-start; text-align: left;
  gap: .5rem; padding: .3rem .45rem; border-radius: var(--radius-xs); cursor: pointer;
  font-size: .85rem; white-space: nowrap;
}
.dd-opt:hover { background: var(--surface-hover); }
.dd-opt input { accent-color: var(--brand); margin: 0; flex: 0 0 auto; }
.input-row { display: flex; gap: .5rem; align-items: stretch; }
.input-row input { flex: 1; min-width: 0; }
.input-row .btn { flex: 0 0 auto; }

/* resultado de verificación de feed */
.verify-box { grid-column: 1 / -1; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem .9rem; font-size: .85rem; background: var(--surface-2); }
.verify-box.loading { color: var(--text-muted); }
.verify-box.ok { border-color: color-mix(in srgb, var(--brand) 40%, var(--border)); background: var(--brand-tint); }
.verify-box.err { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: var(--danger-tint); }
.verify-box .v-head { margin-bottom: .25rem; }
.verify-box .v-meta { color: var(--text-muted); font-size: .8rem; line-height: 1.5; }
.verify-box .v-warn { color: var(--amber); }
.verify-box .v-sample { margin: .5rem 0 0; padding-left: 1.1rem; color: var(--text-muted); font-size: .8rem; }
.verify-box .v-sample li { margin: .12rem 0; }

/* ------------------------------------------------------------------ empty state */
.empty { display: grid; place-items: center; gap: .6rem; text-align: center; padding: 2.6rem 1.5rem; color: var(--text-muted); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty .empty-ico { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--surface-2); color: var(--text-faint); }
.empty .empty-ico svg { width: 24px; height: 24px; }
.empty strong { color: var(--text); font-size: 1rem; }
.empty p { margin: 0; font-size: .88rem; max-width: 42ch; }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 60; max-width: 340px;
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-left: 4px solid var(--brand); border-radius: var(--radius-sm);
  padding: .8rem 1rem; box-shadow: var(--shadow-lg); font-size: .88rem; font-weight: 550;
  animation: toast-in .25s cubic-bezier(.2, .8, .2, 1);
}
.toast.err { border-left-color: var(--danger); }
.toast svg { width: 18px; height: 18px; color: var(--brand); flex: 0 0 auto; }
.toast.err svg { color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.toast.hide { opacity: 0; transform: translateY(10px); transition: opacity .3s, transform .3s; }
.toast-close {
  margin-left: .35rem; flex: 0 0 auto; cursor: pointer; line-height: 1;
  font: inherit; font-size: 1.05rem; color: var(--text-faint);
  background: none; border: 0; padding: .1rem .3rem; border-radius: var(--radius-xs);
}
.toast-close:hover { color: var(--text); background: var(--surface-hover); }

/* spinner de acciones en curso (formularios data-busy) */
.spin {
  display: inline-block; width: .85em; height: .85em; vertical-align: -.1em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; opacity: .5; } }

/* ------------------------------------------------------------------ login */
.login-body {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(900px 420px at 50% -8%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 62%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; padding: 2.1rem 1.9rem 1.6rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.login-brand { text-align: center; margin-bottom: 1.6rem; }
.login-brand .bt-logo { display: block; margin: 0 auto .5rem; }
.login-brand .wordmark { font-size: 1.3rem; font-weight: 800; letter-spacing: .03em; margin: 0; }
.login-brand .wordmark .sep { color: var(--brand); }
.login-brand .tagline { margin: .25rem 0 0; color: var(--text-muted); font-size: .76rem; }
.login-form { display: flex; flex-direction: column; gap: .9rem; }
.login-submit { justify-content: center; width: 100%; padding: .7rem; font-size: .92rem; }
.login-error {
  display: none; margin: 0; padding: .6rem .75rem; border-radius: var(--radius-sm);
  background: var(--danger-tint); border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  color: var(--danger); font-size: .82rem; font-weight: 600; text-align: center;
}
.login-error.show { display: block; }
.login-setup { display: flex; flex-direction: column; gap: .7rem; }
.login-hint { margin: 0; color: var(--text-muted); font-size: .8rem; line-height: 1.5; text-align: center; }
.login-foot { margin: 1.4rem 0 0; text-align: center; color: var(--text-faint); font-size: .7rem; }

/* sesión abierta: usuario y salida en el pie de la barra lateral */
.session-row { display: flex; align-items: center; gap: .5rem; padding: 0 .2rem; }
.session-user {
  display: flex; align-items: center; gap: .45rem; min-width: 0;
  color: var(--text-muted); font-size: .8rem; font-weight: 600;
}
.session-user svg { width: 16px; height: 16px; flex: 0 0 auto; }
.session-user b { color: var(--text); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-row form { margin-left: auto; }
.btn-logout { padding: .3rem .5rem; font-size: .74rem; color: var(--text-muted); border-color: var(--border); background: transparent; }
.btn-logout:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

/* ------------------------------------------------------------------ usuarios, planes y límites */
.backlink { margin: 0 0 .8rem; font-size: .85rem; }
.backlink a { color: var(--text-muted); }
.table .sub { color: var(--text-faint); font-size: .76rem; margin-top: .15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role {
  display: inline-block; font-size: .72rem; font-weight: 650; padding: .14rem .5rem; white-space: nowrap;
  border-radius: var(--pill); font-family: var(--mono); background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.role-admin { color: var(--brand-ink); background: var(--brand-tint); border-color: transparent; }
.role-viewer { color: var(--info); background: var(--info-tint); border-color: transparent; }
.role-help { margin: 0; display: grid; gap: .35rem; font-size: .82rem; }
.role-help dd { margin: 0 0 .5rem; color: var(--text-muted); }
.plan-badge {
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap;
  font-size: .7rem; font-weight: 750; letter-spacing: .04em; text-transform: uppercase;
  padding: .18rem .55rem; border-radius: var(--pill);
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
}
.plan-badge code { font-size: .68rem; text-transform: none; color: var(--text-faint); }
.plan-badge.plan-pro, .plan-badge.plan-agency { color: var(--brand-ink); background: var(--brand-tint); border-color: transparent; }
.plan-badge.plan-enterprise { color: var(--surface); background: var(--text); border-color: transparent; }
.plan-badge.plan-enterprise code { color: inherit; opacity: .7; }
.acct-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .9rem; }
.acct-head h2 { margin: 0 .3rem 0 0; font-size: 1.25rem; }
.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .9rem; margin-bottom: .9rem; }
.meters.stacked { grid-template-columns: 1fr; gap: .55rem; }
.meter { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .9rem; box-shadow: var(--shadow-sm); }
.meters.stacked .meter { box-shadow: none; background: var(--surface-2); }
.meter-head { display: flex; justify-content: space-between; gap: .5rem; font-size: .8rem; color: var(--text-muted); margin-bottom: .45rem; }
.meter-head b { color: var(--text); font-size: .9rem; }
.meter.full .bar-fill { background: var(--danger); }
.meter.full .meter-head b { color: var(--danger); }
.meter.unlimited .bar-track { opacity: .45; }
.plan-bar { display: flex; align-items: center; justify-content: flex-end; gap: .8rem; flex-wrap: wrap; margin: .7rem 0 0; }
.plan-note { display: inline-flex; align-items: center; gap: .35rem; color: var(--text-muted); font-size: .8rem; }
.plan-note svg, .feat svg { width: 14px; height: 14px; flex: 0 0 auto; }
.plan-note.locked { color: var(--text-faint); }
.feat-list { list-style: none; margin: .2rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; }
.feat { display: inline-flex; align-items: center; gap: .45rem; }
.feat.on svg { color: var(--brand); }
.feat.off { color: var(--text-faint); }
.limits-wrap { overflow-x: auto; }
.limits-table { width: 100%; }
.limits-table td, .limits-table th { vertical-align: middle; }
.limits-table input[type="number"], .limits-table select {
  font: inherit; font-size: .85rem; padding: .35rem .5rem; width: 8rem;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-xs);
}
.limits-table input[type="checkbox"] { accent-color: var(--brand); }
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .45rem; font-size: .85rem; }
.member-list li { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: column; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: .2rem .5rem .7rem; }
  .nav { flex-direction: row; overflow-x: auto; gap: .3rem; padding-bottom: .3rem; }
  .nav-link { flex: 0 0 auto; }
  .nav-link.active::before { display: none; }
  .nav-link .count { display: none; }
  .side-foot { flex-direction: row; align-items: center; border-top: 0; padding-top: 0; }
  .side-note { display: none; }
  .theme-toggle { margin-left: auto; }
  .content { padding: 1.1rem 1rem 3rem; }
  .topbar { padding: .9rem 1rem; }
}
