/* =========================================================================
   CursosOnline Admin — Design System
   Un unico archivo CSS, sin build step. Organizado en:
   1. Tokens  2. Reset  3. Layout  4. Componentes  5. Utilidades
   ========================================================================= */

/* ---------- 1. Tokens ---------------------------------------------------- */

:root {
  color-scheme: light;

  /* Paleta base */
  --c-indigo-50: #eef2ff;
  --c-indigo-100: #e0e7ff;
  --c-indigo-400: #818cf8;
  --c-indigo-600: #4f46e5;
  --c-indigo-700: #4338ca;

  /* Superficies */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --surface-hover: #f4f5f7;
  --border: #e4e6eb;
  --border-strong: #d3d6dd;

  /* Texto.
     `--text-muted` es #666e7d y no un gris mas claro por una razon concreta:
     WCAG AA exige 4.5:1 para texto normal y hay que medirlo contra el fondo
     MAS OSCURO sobre el que aparece, no contra blanco. El texto atenuado vive
     sobre cuatro fondos y el peor es `--surface-hover` (#f4f5f7):
       blanco 5.13  ·  --surface-2 4.92  ·  --bg 4.75  ·  --surface-hover 4.71
     Medir solo contra blanco es lo que dejo pasar #737b8c (4.25) y luego
     #6b7280, que daba 4.83 sobre blanco pero 4.43 sobre hover. */
  --text: #16181d;
  --text-secondary: #4b5262;
  --text-muted: #666e7d;

  /* Acento.
     `--on-primary` es la tinta que va ENCIMA de un relleno `--primary`. Existe
     como token propio porque en el tema oscuro el acento se aclara a proposito
     (un acento oscuro no se lee como acento sobre un fondo oscuro) y entonces
     el blanco deja de valer: caia a 3.49:1, y a 2.80:1 en hover. */
  --primary: var(--c-indigo-600);
  --primary-hover: var(--c-indigo-700);
  --primary-soft: var(--c-indigo-50);
  --primary-ring: rgb(79 70 229 / 0.18);
  --on-primary: #ffffff;

  /* Semanticos.
     `--danger` es #c81e1e y no el #dc2626 habitual porque tiene que servir para
     dos cosas a la vez: como tinta sobre `--danger-soft` y como relleno bajo
     texto blanco. Con #dc2626 lo primero daba 4.41:1 (badges de error y
     `.alert-danger`); #c81e1e da 5.24:1 sobre el suave y 5.74:1 con blanco.
     `--on-danger` es el equivalente de `--on-primary` para los rellenos rojos. */
  --danger: #c81e1e;
  --danger-hover: #b91c1c;
  --on-danger: #ffffff;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --info: #0369a1;
  --info-soft: #f0f9ff;
  --info-border: #bae6fd;

  /* Sidebar */
  --sidebar-bg: #121420;
  --sidebar-text: #a8adbf;
  --sidebar-hover: #1e2130;
  --sidebar-border: #242737;

  /* Forma */
  --radius-sm: 6px;
  --radius: 9px;
  --radius-lg: 14px;
  --radius-full: 999px;

  /* Elevacion */
  --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.05);
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.1);
  --shadow-md: 0 4px 8px -2px rgb(16 24 40 / 0.1), 0 2px 4px -2px rgb(16 24 40 / 0.06);
  --shadow-lg: 0 12px 16px -4px rgb(16 24 40 / 0.08), 0 4px 6px -2px rgb(16 24 40 / 0.03);
  --shadow-xl: 0 24px 48px -12px rgb(16 24 40 / 0.18);

  /* Espaciado */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  /* Tipografia */
  --font-sans:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  /* Movimiento */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 180ms;

  /* Capas */
  --z-sidebar: 40;
  --z-backdrop: 80;
  --z-modal: 90;
  --z-toast: 100;

  --sidebar-w: 244px;
  --topbar-h: 60px;
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #0e1015;
  --surface: #171a21;
  --surface-2: #1c2029;
  --surface-hover: #21252f;
  --border: #282d38;
  --border-strong: #363c49;

  --text: #eceef3;
  --text-secondary: #b3b9c7;
  --text-muted: #858d9e;

  --primary: #7c7bf5;
  --primary-hover: #918ff8;
  --primary-soft: #1e1f3d;
  --primary-ring: rgb(124 123 245 / 0.28);
  /* Tinta oscura sobre el acento claro: 5.08:1 en reposo y 6.33:1 en hover. */
  --on-primary: #16181d;

  --danger: #f87171;
  --danger-hover: #fca5a5;
  /* Blanco sobre estos rojos claros daba 2.77:1, y 1.90:1 en hover. */
  --on-danger: #16181d;
  --danger-soft: #2a1618;
  --danger-border: #4c2225;
  --success: #4ade80;
  --success-soft: #12241a;
  --success-border: #1e4230;
  --warning: #fbbf24;
  --warning-soft: #2a2011;
  --warning-border: #4a3a16;
  --info: #60b8f8;
  --info-soft: #10222f;
  --info-border: #1c3e55;

  --sidebar-bg: #0a0c11;
  --sidebar-hover: #171a21;
  --sidebar-border: #21252f;

  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.4);
  --shadow-md: 0 4px 10px rgb(0 0 0 / 0.45);
  --shadow-lg: 0 12px 24px rgb(0 0 0 / 0.5);
  --shadow-xl: 0 24px 48px rgb(0 0 0 / 0.6);
}

/* ---------- 2. Reset ----------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.011em;
  line-height: 1.3;
}

p {
  margin: 0 0 var(--sp-3);
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img,
svg {
  vertical-align: middle;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* Anillo de foco unico y consistente en toda la app */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 3. Layout ---------------------------------------------------- */

/* Enlace de salto: invisible hasta que recibe el foco por teclado */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  background: var(--primary);
  color: var(--on-primary);
  padding: 10px var(--sp-4);
  border-radius: 0 0 var(--radius) 0;
  font-weight: 600;
  font-size: 13px;
}

.skip-link:focus {
  left: 0;
  text-decoration: none;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: var(--sp-5) var(--sp-3);
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: var(--z-sidebar);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: -0.02em;
  color: #fff;
  padding: var(--sp-2) var(--sp-3) var(--sp-5);
}

.sidebar-brand .brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--c-indigo-600), var(--c-indigo-700));
  color: #fff;
  font-size: 13px;
  flex-shrink: 0;
}

/* El indigo-500 de la paleta da solo 4.1:1 sobre el fondo del sidebar y este
   texto es de 15.5px, o sea texto normal: necesita 4.5:1. El indigo-400 llega
   a 6.14:1 sin perder el color de marca. */
.sidebar-brand span {
  color: var(--c-indigo-400);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px var(--sp-3);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--sidebar-text);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.sidebar-nav a svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow-sm);
}

.sidebar-nav a.active svg {
  opacity: 1;
}

.sidebar-footer {
  padding: var(--sp-3) var(--sp-3) 0;
  border-top: 1px solid var(--sidebar-border);
  margin-top: var(--sp-3);
  font-size: 12.5px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) 0 var(--sp-3);
  min-width: 0;
}

.sidebar-user .avatar {
  flex-shrink: 0;
}

.sidebar-user-meta {
  min-width: 0;
  line-height: 1.35;
}

.sidebar-user-name {
  color: #e6e8ef;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-role {
  color: var(--sidebar-text);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-6);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.content {
  padding: var(--sp-6);
  flex: 1;
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
}

/* Boton hamburguesa: solo visible en movil.
   Va cualificado con .topbar para ganar en especificidad a `.btn`, que se
   declara mas abajo con `display: inline-flex`. */
.topbar .nav-toggle {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow-xl);
  }

  .app-shell.nav-open .sidebar {
    transform: translateX(0);
  }

  .app-shell.nav-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgb(10 12 17 / 0.5);
    z-index: 35;
    animation: fade-in var(--dur) var(--ease);
  }

  .topbar .nav-toggle {
    display: inline-flex;
  }

  .content,
  .topbar {
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }
}

/* ---------- 4. Componentes ---------------------------------------------- */

/* -- Page header (titulo + descripcion + acciones) -- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

.page-header h2 {
  font-size: 18px;
  margin: 0 0 2px;
}

.page-header .page-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
  max-width: 68ch;
}

/* -- Card -- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-xs);
}

.card-flush {
  padding: 0;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

/* El nivel del encabezado es semantica (lo usan los lectores de pantalla para
   navegar) y el tamano es diseno: no deben estar acoplados. Si el tamano se
   deja al valor por defecto del navegador, corregir un `h3` que deberia ser
   `h2` lo agranda de 16px a 21px y nadie se atreve a tocarlo. Por eso los
   titulos de tarjeta declaran su tamano aqui. */
.card-header h2 {
  font-size: 14.5px;
  margin: 0;
}

.card-title {
  font-size: 16px;
}

.card-body {
  padding: var(--sp-5);
}

/* -- Grid -- */
.grid {
  display: grid;
  gap: var(--sp-4);
}

.grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

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

/* Layouts de dos columnas (contenido + panel lateral).
   Van como clases y no como `style="grid-template-columns: ..."` inline
   porque un estilo inline gana SIEMPRE a una media query: con el inline, en
   movil se mantenian las dos columnas y la pagina desbordaba en horizontal. */
.layout-main-aside {
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  align-items: start;
}

.layout-aside-main {
  grid-template-columns: minmax(260px, 1fr) minmax(0, 2fr);
  align-items: start;
}

@media (max-width: 1000px) {
  .layout-main-aside,
  .layout-aside-main {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* -- Stat card -- */
.stat-card {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
}

.stat-card .stat-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary);
  flex-shrink: 0;
}

.stat-card .stat-icon svg {
  width: 19px;
  height: 19px;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.stat-card .stat-value {
  font-size: 25px;
  font-weight: 700;
  margin-top: 2px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-trend {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.stat-trend .trend-up {
  color: var(--success);
  font-weight: 600;
}

.stat-trend .trend-down {
  color: var(--danger);
  font-weight: 600;
}

/* -- Grafico de barras (SVG propio, sin librerias)
   La CSP no permite scripts de terceros, y para una serie de 30 puntos una
   libreria de graficos seria mas peso que valor. -- */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 132px;
  padding-top: var(--sp-2);
}

.chart-bar {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  border-radius: 3px 3px 0 0;
  position: relative;
}

.chart-bar span {
  display: block;
  width: 100%;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: background var(--dur-fast) var(--ease);
}

/* Los dias sin actividad se marcan en gris para que se distingan de un dia
   con pocas descargas. */
.chart-bar.is-empty span {
  background: var(--border);
}

.chart-bar:hover span {
  background: var(--primary-hover);
}

.chart-empty {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
}

/* -- Botones -- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.btn:hover {
  text-decoration: none;
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px);
}

.btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: var(--on-danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-danger-soft {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-danger-soft:hover:not(:disabled) {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-danger);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
}

.btn-sm svg {
  width: 13px;
  height: 13px;
}

.btn-lg {
  padding: 11px 20px;
  font-size: 14.5px;
}

.btn-icon {
  padding: 7px;
  width: 32px;
  height: 32px;
}

.btn-block {
  width: 100%;
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

/* Estado de carga: sustituye el contenido por un spinner sin cambiar el ancho */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  color: inherit;
  animation: spin 0.6s linear infinite;
}

/* El spinner sigue a la tinta del boton (`--on-primary` / `--on-danger`) en vez
   de dar por hecho que es blanca: en el tema oscuro esas tintas son oscuras y
   un spinner blanco quedaria en 2.77:1 sobre el relleno. No se usa
   `currentColor` porque `.btn.is-loading` pone `color: transparent` para
   ocultar el texto y el spinner heredaria esa transparencia. */
.btn-primary.is-loading::after {
  border-color: color-mix(in srgb, var(--on-primary) 45%, transparent);
  border-top-color: var(--on-primary);
}

.btn-danger.is-loading::after {
  border-color: color-mix(in srgb, var(--on-danger) 45%, transparent);
  border-top-color: var(--on-danger);
}

.btn-secondary.is-loading::after,
.btn-ghost.is-loading::after,
.btn-danger-soft.is-loading::after {
  border-color: color-mix(in srgb, var(--text-muted) 45%, transparent);
  border-top-color: var(--text);
}

.btn-group {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

/* -- Formularios -- */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

label .required {
  color: var(--danger);
  margin-left: 2px;
}

.field {
  margin-bottom: var(--sp-4);
}

.field:last-child {
  margin-bottom: 0;
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  font-size: 12px;
  color: var(--danger);
  margin-top: 5px;
  font-weight: 500;
}

/* Aviso permanente junto a un campo (no es un error de validacion).
   Necesita clase propia y no `.field-error` en amarillo: `clearFieldError`
   borra todos los `.field-error` del campo, asi que un aviso fijo marcado como
   error desapareceria en cuanto el campo se validara una vez. */
.field-warning {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  font-size: 12px;
  color: var(--warning);
  margin-top: 5px;
  font-weight: 500;
}

.field-error svg,
.field-warning svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  margin-top: 2px;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='url'],
input[type='search'],
input[type='datetime-local'],
select,
textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.75;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666e7d' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 30px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

input[aria-invalid='true'],
select[aria-invalid='true'],
textarea[aria-invalid='true'] {
  border-color: var(--danger);
}

input[aria-invalid='true']:focus,
select[aria-invalid='true']:focus,
textarea[aria-invalid='true']:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}

.input-group {
  display: flex;
  align-items: stretch;
}

.input-group input {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.input-group .input-addon {
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}

.search-input {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-input svg {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input input {
  padding-left: 31px;
}

/* Las tres variantes declaran `display: grid` por su cuenta para poder usarse
   sueltas: como modificadores de `.form-row` era facil olvidarse de la clase
   base y que la fila se apilara en una sola columna sin avisar. */
.form-row,
.form-row-3,
.form-row-price {
  display: grid;
  gap: var(--sp-4);
}

.form-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-row-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Precio / moneda / duracion: la moneda son 3 letras y no necesita el mismo
   ancho que los demas. */
.form-row-price {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.5fr);
}

@media (max-width: 760px) {
  .form-row,
  .form-row-3,
  .form-row-price {
    grid-template-columns: minmax(0, 1fr);
  }
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding-top: var(--sp-4);
  margin-top: var(--sp-4);
  border-top: 1px solid var(--border);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.checkbox-row label {
  margin: 0;
  font-weight: 500;
  color: var(--text);
}

input[type='checkbox'],
input[type='radio'] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin: 0 0 var(--sp-4);
}

.fieldset legend {
  padding: 0 var(--sp-2);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

/* -- Tabla -- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 11px var(--sp-4);
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 650;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  z-index: 1;
}

tbody tr {
  transition: background var(--dur-fast) var(--ease);
}

tbody tr:hover {
  background: var(--surface-hover);
}

tbody tr:last-child td {
  border-bottom: none;
}

td.numeric,
th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

/**
 * El texto de una celda se recorta siempre.
 *
 * Antes cada pagina decidia por su cuenta: dos anadian `truncate` a mano y las
 * demas no, asi que el mismo dato —el correo de un administrador, el nombre de
 * una categoria— se recortaba en una tabla y desbordaba en otra. Que el
 * comportamiento dependa de si alguien se acordo de poner una clase es
 * justamente lo que produce incoherencias.
 */
.cell-title,
.cell-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-title {
  font-weight: 600;
  color: var(--text);
}

.cell-sub {
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-mono);
}

.cell-media {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.cell-thumb {
  width: 46px;
  height: 30px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.cell-thumb-placeholder {
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.cell-thumb-placeholder svg {
  width: 15px;
  height: 15px;
}

/* -- Badges y tags -- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge-draft,
.badge-archived {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
}

.badge-published,
.badge-ready,
.badge-active {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.badge-processing {
  background: var(--warning-soft);
  border-color: var(--warning-border);
  color: var(--warning);
}

.badge-failed,
.badge-revoked {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.badge-info {
  background: var(--info-soft);
  border-color: var(--info-border);
  color: var(--info);
}

.tag-list {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tag {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 8px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* El gradiente arranca en indigo-600 y no en indigo-500 porque las iniciales
   van en blanco: sobre indigo-500 el extremo claro daba 4.47:1, por debajo del
   4.5 exigido. Desde indigo-600 el peor punto del degradado es 6.29:1. Mismo
   motivo en `.sidebar-brand .brand-mark`, que usa este mismo gradiente. */
.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-indigo-600), var(--c-indigo-700));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

/* -- Toolbar -- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.toolbar-filters {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  align-items: center;
}

.toolbar-filters input,
.toolbar-filters select {
  width: auto;
  min-width: 168px;
  /* Un `<select>` se ensancha hasta caber su opcion mas larga. Con una
     categoria de nombre largo, el desplegable se comia media barra de filtros
     y empujaba al resto. Medido: 570 px de un ancho util de ~1050. El texto
     completo sigue viendose al desplegarlo. */
  max-width: 260px;
}

/* El buscador ocupa el hueco libre pero puede encogerse: con un `min-width`
   fijo, en movil desbordaba la fila de filtros. */
.toolbar-filters .search-input {
  flex: 1 1 240px;
  min-width: 0;
  max-width: 100%;
}

/* El buscador si crece: el tope de 260px es para que un `<select>` con una
   opcion larga no se coma la barra, no para encoger el campo de busqueda. */
.toolbar-filters .search-input input {
  width: 100%;
  min-width: 0;
  max-width: none;
}

@media (max-width: 620px) {
  /* En pantallas estrechas los filtros ocupan el ancho completo, apilados:
     media docena de controles a media anchura son inmanejables con el pulgar. */
  .toolbar,
  .toolbar-filters {
    width: 100%;
  }

  .toolbar-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-filters input,
  .toolbar-filters select,
  .toolbar-filters .search-input {
    width: 100%;
    min-width: 0;
  }

  .page-header .btn,
  .toolbar > .btn {
    width: 100%;
  }
}

/* -- Barra de acciones en lote -- */
.bulk-bar {
  position: sticky;
  top: calc(var(--topbar-h) + var(--sp-2));
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
  padding: 10px var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  box-shadow: var(--shadow-md);
  animation: fade-in var(--dur-fast) var(--ease);
}

.bulk-count {
  font-size: 13.5px;
  font-weight: 650;
  color: var(--primary);
}

/* La columna de casillas se queda estrecha; sin esto el `th` vacio reparte
   ancho a partes iguales con las demas columnas. */
th.col-check,
td.col-check {
  width: 1%;
  padding-right: 0;
  white-space: nowrap;
}

tbody tr.is-selected {
  background: var(--primary-soft);
}

/* -- Resumen de resultados de un lote -- */
.result-list {
  margin: var(--sp-2) 0 0;
  padding: 0;
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
  font-size: 13px;
}

.result-list li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.result-list li:last-child {
  border-bottom: none;
}

.result-list .result-title {
  font-weight: 600;
  color: var(--text);
}

.result-list .result-reason {
  color: var(--danger);
  font-size: 12.5px;
}

/* -- Alert / callout -- */
.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 13px;
  margin-bottom: var(--sp-4);
}

.alert svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 2px;
}

.alert-info {
  background: var(--info-soft);
  border-color: var(--info-border);
  color: var(--info);
}

.alert-warning {
  background: var(--warning-soft);
  border-color: var(--warning-border);
  color: var(--warning);
}

.alert-danger {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.alert-success {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.alert strong {
  font-weight: 700;
}

/* -- Dropzone -- */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: var(--sp-6);
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.dropzone:hover {
  border-color: var(--primary);
}

.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.dropzone.is-disabled {
  opacity: 0.6;
  pointer-events: none;
}

.dropzone input {
  display: none;
}

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0 auto var(--sp-2);
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.dropzone-icon svg {
  width: 19px;
  height: 19px;
}

.dropzone-title {
  font-weight: 600;
  color: var(--text);
  font-size: 13.5px;
}

.dropzone-hint {
  font-size: 12px;
  margin-top: 3px;
}

.dropzone-preview {
  margin-top: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  justify-content: center;
  flex-wrap: wrap;
}

.dropzone-preview img {
  max-height: 96px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 7px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text);
  max-width: 100%;
}

.file-chip svg {
  width: 15px;
  height: 15px;
  color: var(--primary);
  flex-shrink: 0;
}

.file-chip .file-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip .file-size {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* -- Editor de etiquetas -- */
.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: text;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.tag-input:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.tag-input [data-tag-list] {
  display: contents;
}

.tag-input input {
  flex: 1;
  min-width: 140px;
  border: none;
  outline: none;
  padding: 2px 0;
  background: transparent;
  box-shadow: none;
  width: auto;
}

.tag-input input:focus {
  border: none;
  box-shadow: none;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 9px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  max-width: 100%;
}

.tag-chip-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 3px;
  border-radius: 3px;
  opacity: 0.65;
}

.tag-chip-remove:hover {
  opacity: 1;
  background: rgb(0 0 0 / 0.08);
}

/* -- Contador de caracteres -- */
.char-counter {
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.char-counter.is-near {
  color: var(--warning);
}

.char-counter.is-over {
  color: var(--danger);
  font-weight: 600;
}

/* -- Barra de acciones fija -- */
.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin: var(--sp-5) calc(-1 * var(--sp-5)) calc(-1 * var(--sp-5));
  padding: var(--sp-3) var(--sp-5);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  flex-wrap: wrap;
}

.unsaved-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--warning);
  font-weight: 600;
}

.unsaved-dot::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* -- Progreso -- */
.progress-bar {
  width: 100%;
  height: 7px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 10px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  border-radius: inherit;
  transition: width 0.15s linear;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

/* -- Toasts -- */
#toast-container {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: var(--z-toast);
  pointer-events: none;
  max-width: min(380px, calc(100vw - 2 * var(--sp-4)));
}

/**
 * Las dos regiones `aria-live` (una urgente y otra no) viven dentro del
 * contenedor. Se apilan igual que los avisos y no ocupan sitio cuando estan
 * vacias, que es casi siempre.
 */
.toast-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast-stack:empty {
  display: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 11px var(--sp-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted);
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--dur) var(--ease);
}

.toast.is-leaving {
  animation: toast-out var(--dur-fast) var(--ease) forwards;
}

.toast .toast-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.toast .toast-icon svg {
  width: 16px;
  height: 16px;
}

.toast .toast-content {
  flex: 1;
  min-width: 0;
}

.toast .toast-title {
  font-weight: 650;
  margin-bottom: 1px;
}

.toast .toast-message {
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.toast .toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  line-height: 0;
}

.toast .toast-close:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.toast .toast-close svg {
  width: 14px;
  height: 14px;
}

.toast.success {
  border-left-color: var(--success);
}

.toast.success .toast-icon {
  color: var(--success);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.error .toast-icon {
  color: var(--danger);
}

.toast.warning {
  border-left-color: var(--warning);
}

.toast.warning .toast-icon {
  color: var(--warning);
}

.toast.info {
  border-left-color: var(--info);
}

.toast.info .toast-icon {
  color: var(--info);
}

/* -- Modal -- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgb(10 12 17 / 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  z-index: var(--z-modal);
  animation: fade-in var(--dur-fast) var(--ease);
}

.modal-overlay.is-leaving {
  animation: fade-out var(--dur-fast) var(--ease) forwards;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 470px;
  max-height: calc(100vh - 2 * var(--sp-8));
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: modal-in var(--dur) var(--ease);
}

.modal-overlay.is-leaving .modal {
  animation: modal-out var(--dur-fast) var(--ease) forwards;
}

.modal-lg {
  max-width: 640px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
}

.modal-header .modal-titles {
  flex: 1;
  min-width: 0;
}

.modal h2,
.modal-title {
  margin: 0;
  font-size: 16px;
}

.modal-subtitle {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-top: 3px;
}

.modal-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--primary-soft);
  color: var(--primary);
}

.modal-icon svg {
  width: 17px;
  height: 17px;
}

.modal-icon.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.modal-icon.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.modal-body {
  padding: 0 var(--sp-5) var(--sp-2);
  overflow-y: auto;
  color: var(--text-secondary);
  font-size: 13.5px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5) var(--sp-5);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  line-height: 0;
  flex-shrink: 0;
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.modal-close svg {
  width: 16px;
  height: 16px;
}

/* -- Skeleton -- */
.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    color-mix(in srgb, var(--border) 60%, var(--surface-2)) 37%,
    var(--surface-2) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  height: 12px;
}

.skeleton-text {
  height: 11px;
  margin: 3px 0;
}

/* -- Empty state -- */
.empty-state {
  text-align: center;
  padding: var(--sp-10) var(--sp-5);
  color: var(--text-muted);
}

.empty-state .empty-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin: 0 auto var(--sp-3);
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.empty-state .empty-icon svg {
  width: 21px;
  height: 21px;
}

.empty-state .empty-title {
  font-weight: 650;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 3px;
}

.empty-state .empty-desc {
  font-size: 13px;
  max-width: 44ch;
  margin: 0 auto;
}

/*
 * Referencia de un fallo del servidor.
 *
 * Secundaria a proposito: no le dice nada al administrador, es un dato para
 * quien vaya a mirar los logs. Pero tiene que poder leerse y seleccionarse, asi
 * que se deja en monoespaciado y con contraste suficiente en vez de esconderla.
 */
.empty-state .empty-ref {
  margin-top: var(--sp-3);
  font-size: 12px;
  color: var(--text-muted);
}

.empty-state .empty-ref code {
  user-select: all;
  font-size: 12px;
}

.empty-state .empty-action {
  margin-top: var(--sp-4);
}

/* -- Paginacion -- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.pagination .page-info {
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* -- Tabs -- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-5);
  overflow-x: auto;
  /* Necesario: cuando un eje deja de ser `visible`, el otro pasa de `visible`
     a `auto` automaticamente. Sin esto, el margen negativo de los botones
     desborda 1px en vertical y aparece una barra de scroll fantasma. */
  overflow-y: hidden;
  scrollbar-width: thin;
}

.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px var(--sp-3);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  margin-bottom: -1px;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.tabs button:hover {
  color: var(--text);
}

.tabs button[aria-selected='true'] {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* -- Codigo -- */
code {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

code.key-value {
  display: block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  word-break: break-all;
  margin-top: var(--sp-2);
  color: var(--text);
}

kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
}

.scopes-list {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.scopes-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: var(--text);
  margin: 0;
}

/* -- Login -- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: radial-gradient(ellipse at top, #1e2130 0%, #0a0c11 70%);
}

.login-card {
  width: 100%;
  max-width: 384px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--sp-8);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: var(--sp-5);
  color: var(--text);
}

.login-card h1 {
  font-size: 19px;
  margin: 0 0 3px;
}

.login-card p.text-muted {
  margin-top: 0;
  margin-bottom: var(--sp-6);
  font-size: 13px;
}

/* Estado intermedio del login mientras se intenta renovar la sesion: ocupa el
   sitio del formulario para que la tarjeta no de un salto al aparecer este. */
.session-restore {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  min-height: 132px;
  color: var(--text-secondary);
  font-size: 13.5px;
}

.session-restore .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: var(--sp-2);
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 38px;
}

.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  line-height: 0;
}

.password-toggle:hover {
  color: var(--text);
}

.password-toggle svg {
  width: 16px;
  height: 16px;
}

/* Medidor de fuerza de contrasena */
.strength-meter {
  display: flex;
  gap: 4px;
  margin-top: 7px;
}

.strength-meter span {
  flex: 1;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--border);
  transition: background var(--dur) var(--ease);
}

.strength-meter[data-score='1'] span:nth-child(1) {
  background: var(--danger);
}

.strength-meter[data-score='2'] span:nth-child(-n + 2) {
  background: var(--warning);
}

.strength-meter[data-score='3'] span:nth-child(-n + 3) {
  background: #eab308;
}

.strength-meter[data-score='4'] span {
  background: var(--success);
}

.strength-label {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- 5. Utilidades ------------------------------------------------ */

.hidden {
  display: none !important;
}

/* El atributo `hidden` solo aplica `display: none` desde la hoja del
   navegador, asi que cualquier regla propia con `display` (por ejemplo
   `.pagination { display: flex }`) lo anula silenciosamente y el elemento
   sigue visible. Esta regla le devuelve la ultima palabra. */
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/**
 * Aviso de que una peticion esta tardando.
 *
 * Discreto a proposito: no tapa nada, no roba el foco y desaparece solo. Su
 * unico trabajo es que un esqueleto gris de varios segundos no se confunda con
 * una pagina colgada.
 */
.espera-larga {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-md);
  padding: 8px var(--sp-4);
  font-size: 13px;
  pointer-events: none;
  animation: espera-larga-entra var(--dur) var(--ease);
}

@keyframes espera-larga-entra {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.text-muted {
  color: var(--text-muted);
}

.text-danger {
  color: var(--danger);
}

.text-success {
  color: var(--success);
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.text-sm {
  font-size: 12.5px;
}

.font-mono {
  font-family: var(--font-mono);
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/**
 * Para que `.truncate` sirva de algo dentro de una tabla.
 *
 * Con el reparto automatico de anchos, la celda crece hasta caber el texto
 * entero: el `text-overflow: ellipsis` esta puesto pero nunca llega a
 * activarse. Medido con un titulo de 131 caracteres: la celda se estiro a 952
 * px, la tabla a 1695, y los botones de accion de esa fila quedaron a 2122 px
 * —fuera de una pantalla de 1920—. Seguian siendo alcanzables desplazandose,
 * pero desplazarse para pulsar "Publicar" no deberia hacer falta.
 *
 * El maximo va en la celda, no en `.truncate`: el `overflow` solo recorta si
 * el ancho esta acotado por algun ancestro.
 *
 * OJO con el alcance de esto: con `table-layout: auto`, un `max-width` en un
 * `<td>` es una SUGERENCIA que el navegador ignora al repartir el ancho
 * sobrante. Comprobado en la pagina de actividad: la celda tenia el maximo
 * aplicado y media 459 px igualmente. Solo funciona cuando el contenido
 * excede tanto el maximo que el reparto no da mas de si, que es el caso de un
 * titulo de 131 caracteres pero no el de una tabla con espacio libre.
 *
 * Por eso el limite se pone TAMBIEN en el contenido: un `div` o un `span`
 * dentro de la celda si respeta su `max-width` pase lo que pase con el
 * reparto.
 */
td:has(> .cell-media),
td:has(> .cell-title),
/* En algunas tablas la clase va en el propio `td` en vez de en un hijo. */
td.cell-title {
  max-width: 380px;
}

/* El contenido si obedece: es un elemento de bloque normal, no una celda. */
td > .cell-title,
td > .cell-sub,
td > .cell-media {
  max-width: 380px;
}

/* Y dentro de `.cell-media` (miniatura + textos), el bloque de texto. */
.cell-media > div {
  min-width: 0;
}

/* Un `td.cell-title` es a la vez celda y texto: necesita recortar el suyo. */
td.cell-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sin `:has` (navegadores antiguos): al menos la tabla no crece sin freno. */
@supports not selector(td:has(*)) {
  .table-wrap table {
    table-layout: fixed;
  }
}

.flex {
  display: flex;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.flex-wrap {
  flex-wrap: wrap;
}

.gap-1 {
  gap: var(--sp-1);
}

.gap-2 {
  gap: var(--sp-2);
}

.gap-3 {
  gap: var(--sp-3);
}

.gap-4 {
  gap: var(--sp-4);
}

.mt-0 {
  margin-top: 0;
}

.mt-2 {
  margin-top: var(--sp-2);
}

.mt-4 {
  margin-top: var(--sp-4);
}

.mt-5 {
  margin-top: var(--sp-5);
}

.mb-0 {
  margin-bottom: 0;
}

.mb-4 {
  margin-bottom: var(--sp-4);
}

.w-full {
  width: 100%;
}

/* ---------- Animaciones -------------------------------------------------- */

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modal-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(6px) scale(0.99);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(16px);
  }
}

/* ---------- Impresion ---------------------------------------------------- */

@media print {
  .sidebar,
  .topbar,
  .toolbar,
  #toast-container,
  .modal-overlay {
    display: none !important;
  }

  .content {
    padding: 0;
  }

  .card {
    box-shadow: none;
    border-color: #ccc;
  }
}
