/* ================================================================
   app.css — Design system + application shell
   Tokens (light/dark), typography, utilities, sidebar, topbar, footer.
   Se carga en todas las páginas del área autenticada.
   ================================================================ */

/* ================================================================
   1. DESIGN TOKENS — Light theme (default)
   ================================================================ */
:root {
  /* Surfaces */
  --bg-base: #f5f7fb;
  --bg-elevated: #ffffff;
  --bg-subtle: #eef2f8;
  --bg-inverse: #0b1020;

  --surface-1: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f8;
  --surface-glass: rgba(255, 255, 255, 0.72);

  /* Borders */
  --border-subtle: rgba(11, 16, 32, 0.06);
  --border-default: rgba(11, 16, 32, 0.1);
  --border-strong: rgba(11, 16, 32, 0.18);
  --border-focus: #055CB4;

  /* Text */
  --text-primary: #0b1020;
  --text-secondary: #4a5568;
  --text-tertiary: #718096;
  --text-muted: #9aa3b2;
  --text-inverse: #ffffff;

  /* Brand / semantic */
  --accent-primary: #055CB4;
  --accent-primary-hover: #044a95;
  --accent-primary-subtle: rgba(5, 92, 180, 0.08);
  --accent-primary-glow: rgba(5, 92, 180, 0.28);

  --accent-success: #10b981;
  --accent-success-subtle: rgba(16, 185, 129, 0.1);
  --accent-warning: #f59e0b;
  --accent-warning-subtle: rgba(245, 158, 11, 0.1);
  --accent-danger: #ef4444;
  --accent-danger-subtle: rgba(239, 68, 68, 0.1);
  --accent-info: #3b82f6;
  --accent-violet: #8b5cf6;
  --accent-violet-subtle: rgba(139, 92, 246, 0.1);
  --accent-green: #11D15E;
  --accent-green-subtle: rgba(17, 209, 94, 0.1);

  /* Overlays — no reaccionan al theme (siempre oscurecen) */
  --overlay-modal: rgba(0, 0, 0, 0.55);
  --overlay-image: rgba(0, 0, 0, 0.45);

  /* Gradients — futuristic aurora */
  --gradient-primary: linear-gradient(135deg, #055CB4 0%, #1a85e0 50%, #11D15E 100%);
  --gradient-violet: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --gradient-aurora:
    radial-gradient(ellipse 80% 60% at 15% 10%, rgba(5, 92, 180, 0.14), transparent 60%),
    radial-gradient(ellipse 60% 50% at 85% 40%, rgba(139, 92, 246, 0.08), transparent 60%),
    radial-gradient(ellipse 70% 60% at 50% 100%, rgba(17, 209, 94, 0.08), transparent 60%);
  --gradient-grid:
    linear-gradient(rgba(11, 16, 32, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(11, 16, 32, 0.025) 1px, transparent 1px);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(11, 16, 32, 0.04);
  --shadow-md: 0 2px 4px rgba(11, 16, 32, 0.04), 0 4px 12px rgba(11, 16, 32, 0.05);
  --shadow-lg: 0 4px 6px rgba(11, 16, 32, 0.04), 0 12px 28px rgba(11, 16, 32, 0.08);
  --shadow-xl: 0 8px 12px rgba(11, 16, 32, 0.05), 0 24px 48px rgba(11, 16, 32, 0.1);
  --shadow-glow: 0 0 0 1px var(--accent-primary-subtle), 0 8px 20px var(--accent-primary-glow);

  /* Radii */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-2xl: 28px;
  --radius-pill: 999px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;
  --space-9: 64px;
  --space-10: 96px;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;

  --text-xs: 11px;
  --text-sm: 12.5px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 30px;
  --text-4xl: 38px;
  --text-5xl: 48px;

  --leading-tight: 1.2;
  --leading-snug: 1.35;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --tracking-tight: -0.02em;
  --tracking-normal: 0em;
  --tracking-wide: 0.02em;
  --tracking-wider: 0.05em;

  /* Layout */
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 68px;
  --topbar-h: 56px;
  --content-max-w: 1400px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-instant: 80ms;
  --dur-fast: 160ms;
  --dur-base: 240ms;
  --dur-slow: 400ms;

  /* Z-index */
  --z-base: 1;
  --z-sticky: 100;
  --z-topbar: 200;
  --z-sidebar: 250;
  --z-dropdown: 500;
  --z-modal: 1000;
  --z-toast: 1200;
}

/* ================================================================
   2. DESIGN TOKENS — Dark theme
   ================================================================ */
[data-theme="dark"] {
  --bg-base: #070a14;
  --bg-elevated: #0f1424;
  --bg-subtle: #141a2e;
  --bg-inverse: #f5f7fb;

  --surface-1: #0f1424;
  --surface-2: #141a2e;
  --surface-3: #1b2240;
  --surface-glass: rgba(15, 20, 36, 0.72);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --border-focus: #60a5fa;

  --text-primary: #eef2f8;
  --text-secondary: #a8b1c4;
  --text-tertiary: #8690a5;
  --text-muted: #6b7490;
  --text-inverse: #0b1020;

  --accent-primary: #3b82f6;
  --accent-primary-hover: #60a5fa;
  --accent-primary-subtle: rgba(59, 130, 246, 0.14);
  --accent-primary-glow: rgba(59, 130, 246, 0.4);

  --accent-success: #22c55e;
  --accent-success-subtle: rgba(34, 197, 94, 0.14);
  --accent-warning: #fbbf24;
  --accent-warning-subtle: rgba(251, 191, 36, 0.14);
  --accent-danger: #f87171;
  --accent-danger-subtle: rgba(248, 113, 113, 0.14);
  --accent-info: #60a5fa;
  --accent-violet: #a78bfa;
  --accent-violet-subtle: rgba(139, 92, 246, 0.18);
  --accent-green: #22c55e;
  --accent-green-subtle: rgba(34, 197, 94, 0.14);

  --gradient-primary: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #22c55e 100%);
  --gradient-aurora:
    radial-gradient(ellipse 80% 60% at 15% 10%, rgba(59, 130, 246, 0.22), transparent 60%),
    radial-gradient(ellipse 60% 50% at 85% 40%, rgba(139, 92, 246, 0.14), transparent 60%),
    radial-gradient(ellipse 70% 60% at 50% 100%, rgba(34, 197, 94, 0.12), transparent 60%);
  --gradient-grid:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 8px 12px rgba(0, 0, 0, 0.35), 0 24px 48px rgba(0, 0, 0, 0.55);
}

/* ================================================================
   3. RESET + BASE
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}
[data-theme="dark"] { color-scheme: dark; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--dur-base) var(--ease-out),
              color var(--dur-base) var(--ease-out);
}

/* Grid texture overlay on main background (subtle) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--gradient-grid);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

a { color: var(--accent-primary); text-decoration: none; transition: color var(--dur-fast); }
a:hover { color: var(--accent-primary-hover); }

button { font-family: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }

::selection { background: var(--accent-primary-subtle); color: var(--text-primary); }

/* ================================================================
   4. TYPOGRAPHY
   ================================================================ */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}
h1 { font-size: var(--text-3xl); font-weight: 700; }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

p { margin: 0; }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent-primary); }
.text-mono { font-family: var(--font-mono); }

/* Utility de visibilidad. Antes vivía solo en wizard.css/utilities.css
   (no cargados por AppShell), por lo que el editor de CV usaba u-hidden
   en HTML sin que tuviera efecto. Promovida a tokens del design system. */
.u-hidden { display: none !important; }

/* ================================================================
   CHIP CHOICE (radios estilizados como pills)
   ================================================================
   Patrón canónico portado desde wizard.css para que el dashboard
   (drawer datos personales del PR #7, etc.) pueda usar el mismo
   componente. wizard-shell.js sincroniza .is-active automáticamente
   cuando cambia el radio anidado. */
.chip-choice {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.chip-choice__opt {
  position: relative;
  padding: 9px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1.5px solid var(--border-default);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--dur-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip-choice__opt svg { width: 14px; height: 14px; }
.chip-choice__opt:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.chip-choice__opt.is-active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-primary-glow);
}

/* Variante con radios reales: oculta input visualmente y deja la
   label estilizada. wizard-shell.js sincroniza .is-active al
   cambiar el radio. */
.chip-choice--radio .chip-choice__opt input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.chip-choice--radio .chip-choice__opt:focus-within {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ================================================================
   BANNER DE ELIMINACIÓN DE CUENTA EN CURSO (RGPD C1, MVP)
   ================================================================ */
/* Fixed (fuera del CSS grid de .app, que tiene áreas nombradas sidebar/topbar/
   main y ocultaría un hijo sin grid-area). Barra inferior visible siempre. */
.account-deletion-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 16px;
  padding: 12px 20px;
  background: var(--warning-surface, #fff4e5);
  color: var(--warning-text, #7a4b00);
  border-top: 1px solid var(--warning-border, #f0c987);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  font-size: var(--text-sm, 14px);
  line-height: 1.45;
}
.account-deletion-bar__text { flex: 1 1 320px; }
.account-deletion-bar__btn {
  flex: 0 0 auto;
  padding: 7px 16px;
  border: 1.5px solid currentColor;
  border-radius: var(--radius-pill, 999px);
  background: transparent;
  color: inherit;
  font-weight: 600;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}
.account-deletion-bar__btn:hover { background: rgba(0, 0, 0, 0.06); }
.account-deletion-bar__btn:disabled { opacity: 0.6; cursor: default; }

/* ================================================================
   TAG INPUT + SUGGEST + POPOVER
   ================================================================
   Patrón canónico portado desde wizard.css (paso 5 — competencias)
   para que el editor de CV use la misma UI: tags + popover modal
   compartido. Las 3 variantes de color (default/violet/green) se
   usan para diferenciar habilidades / conocimientos / idiomas. */
.tag-input-wrap { position: relative; }

.tag-input {
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  cursor: text;
  min-height: 48px;
}
.tag-input:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 4px var(--accent-primary-subtle);
  background: var(--surface-1);
}
.tag-input input {
  flex: 1;
  min-width: 140px;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 4px 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--text-sm);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-primary-subtle);
  color: var(--accent-primary);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--dur-fast);
}
.tag:hover { filter: brightness(0.96); }
[data-theme="dark"] .tag:hover { filter: brightness(1.08); }
.tag--violet { background: var(--accent-violet-subtle); color: var(--accent-violet); }
.tag--green  { background: var(--accent-green-subtle);  color: var(--accent-green); }

.tag__sep { opacity: 0.5; margin: 0 1px; }
.tag__years { font-weight: 500; opacity: 0.85; }
.tag__level { display: inline-flex; gap: 1px; align-items: center; }

.tag__ghost {
  font-style: italic;
  font-weight: 500;
  opacity: 0.55;
  margin-left: 4px;
  letter-spacing: 0.1px;
  transition: opacity var(--dur-fast);
}
.tag:hover .tag__ghost { opacity: 0.95; }

.tag-input-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
.tag-input-hint svg { width: 14px; height: 14px; flex: 0 0 auto; }

.tag__level-pip {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.25;
}
.tag__level-pip.is-on { opacity: 1; }

.tag__remove {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity var(--dur-fast);
}
.tag__remove:hover { opacity: 1; }

.suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  padding: 4px;
  display: none;
}
.suggest.is-open { display: block; }
.suggest__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-primary);
  transition: background var(--dur-fast);
}
.suggest__item:hover,
.suggest__item.is-focused {
  background: var(--accent-primary-subtle);
  color: var(--accent-primary);
}
.suggest__item-meta {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
.suggest__item--create {
  color: var(--accent-primary);
  font-weight: 600;
  border-top: 1px solid var(--border-subtle);
  margin-top: 2px;
  padding-top: 10px;
}
.suggest__item--create::before {
  content: "+";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.suggest__empty {
  padding: 12px;
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

/* position: fixed para que el popover se posicione respecto al viewport
   incluso si su ancestro tiene transform/filter (que crearían un nuevo
   containing block para position: absolute). El editor de CV vive en un
   .profile-drawer con transform: translateX(0) y rompía el cálculo del
   popover. El wizard sobrescribe a position: absolute en wizard.css
   porque allí no hay drawer transformado y el flujo de scroll difiere.

   z-index 1100 para quedar por encima de --z-modal (1000): el popover
   vive al nivel del <body> en el editor (fuera del drawer), así que
   compite directamente con el z-index del drawer. El wizard sobrescribe
   a 210 en wizard.css porque allí el popover convive con elementos
   normales sin modales flotantes. */
.tag-popover {
  position: fixed;
  z-index: 1100;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
  min-width: 240px;
  display: none;
}
.tag-popover.is-open { display: block; }
.tag-popover__title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-3);
  letter-spacing: var(--tracking-tight);
}
.tag-popover__title small {
  font-weight: 500;
  color: var(--text-tertiary);
  display: block;
  margin-top: 2px;
}
.tag-popover__group-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: 6px;
}
.tag-popover__levels {
  display: flex;
  gap: 6px;
  margin-bottom: var(--space-3);
}
.tag-popover__level {
  flex: 1;
  padding: 8px 0;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 700;
  font-family: inherit;
  color: var(--text-secondary);
  transition: all var(--dur-fast);
}
.tag-popover__level:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}
.tag-popover__level.is-active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}
.tag-popover__years-input {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.tag-popover__years-input input {
  width: 64px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--text-sm);
  text-align: center;
}
.tag-popover__years-input input:focus {
  outline: none;
  border-color: var(--accent-primary);
}
.tag-popover__years-input span {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
/* Select dentro del popover (idiomas) — homologado visualmente con el
   `.select` del wizard: appearance: none + arrow SVG custom + fuente
   Inter heredada. Antes el editor de CV usaba `class="profile-edit-input"`
   y mostraba la flechita nativa del navegador, que se sentía ajena al
   resto del sitio. */
.tag-popover select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: var(--surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23718096' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  padding: 10px 36px 10px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--text-base);
  margin-bottom: var(--space-3);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
}
.tag-popover select:focus {
  outline: none;
  border-color: var(--accent-primary);
  background-color: var(--surface-1);
  box-shadow: 0 0 0 4px var(--accent-primary-subtle);
}
.tag-popover select option {
  font-family: inherit;
  font-size: var(--text-base);
}
.tag-popover__actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
}
.tag-popover__clear {
  background: transparent;
  border: 0;
  color: var(--text-tertiary);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
}
.tag-popover__clear:hover { color: var(--accent-danger); }
.tag-popover__done {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-primary);
  color: #fff;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
}
.tag-popover__done:hover { background: var(--accent-primary-hover); }

/* ================================================================
   5. APP LAYOUT — Sidebar + Topbar + Main
   ================================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
  position: relative;
  z-index: var(--z-base);
  transition: grid-template-columns var(--dur-base) var(--ease-out);
}
[data-sidebar="collapsed"] .app {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* ================================================================
   6. SIDEBAR
   ================================================================ */
.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface-1);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  overflow: hidden;
  transition: width var(--dur-base) var(--ease-out);
}

.sidebar__header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-3);
  flex-shrink: 0;
}
.sidebar__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
  color: var(--text-primary);
}
.sidebar__brand-logo {
  /* Alineado con .wz-header__brand-logo del wizard (36px) para que el
     usuario perciba el mismo logo entre wizard y dashboard. */
  height: 36px;
  width: auto;
  display: block;
  max-width: 100%;
  object-fit: contain;
  transition: opacity var(--dur-fast);
}
.sidebar__brand-mark {
  /* Iguala .wz-header__brand-mark del wizard (32px) — antes 36 lo hacía
     visualmente "más grande" al colapsar el sidebar. */
  width: 32px;
  height: 32px;
  display: none;
  object-fit: contain;
  flex-shrink: 0;
}
[data-theme="dark"] .sidebar__brand-logo { content: url('/assets/images/logo-auth-dark.svg'); }
[data-theme="dark"] .sidebar__brand-mark { content: url('/assets/images/isotipo-dark.svg'); }
/* Collapsed sidebar: swap full logo for compact isotype */
[data-sidebar="collapsed"] .sidebar__brand-logo { display: none; }
[data-sidebar="collapsed"] .sidebar__brand-mark { display: block; }
[data-sidebar="collapsed"] .sidebar__brand { justify-content: center; }

.sidebar__nav {
  flex: 1;
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  position: relative;
  white-space: nowrap;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.nav-link__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: color var(--dur-fast);
}
.nav-link__icon svg { width: 18px; height: 18px; }
.nav-link__label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity var(--dur-fast);
}
[data-sidebar="collapsed"] .nav-link__label { opacity: 0; pointer-events: none; }

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.nav-link:hover .nav-link__icon { color: var(--accent-primary); }

.nav-link--active {
  background: var(--accent-primary-subtle);
  color: var(--accent-primary);
  font-weight: 600;
}
.nav-link--active .nav-link__icon { color: var(--accent-primary); }
.nav-link--active::before {
  content: "";
  position: absolute;
  left: -11px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent-primary);
  box-shadow: 0 0 12px var(--accent-primary-glow);
}

.nav-link--disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  pointer-events: none;
}
.nav-link--disabled .nav-link__icon { opacity: 0.4; }
.nav-link__tag {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-muted);
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  opacity: 1;
  transition: opacity var(--dur-fast);
}
[data-sidebar="collapsed"] .nav-link__tag { opacity: 0; pointer-events: none; }

/* Tooltip on collapsed sidebar */
[data-sidebar="collapsed"] .nav-link { position: relative; }
[data-sidebar="collapsed"] .nav-link:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-inverse);
  color: var(--text-inverse);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
  z-index: var(--z-dropdown);
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

.sidebar__footer {
  padding: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-toggle {
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.sidebar-toggle:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.sidebar-toggle__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  transition: transform var(--dur-base) var(--ease-out);
}
[data-sidebar="collapsed"] .sidebar-toggle__icon { transform: rotate(180deg); }
.sidebar-toggle__label {
  opacity: 1;
  transition: opacity var(--dur-fast);
}
[data-sidebar="collapsed"] .sidebar-toggle__label { opacity: 0; pointer-events: none; }

/* ================================================================
   7. TOPBAR
   ================================================================ */
.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: var(--surface-glass);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  z-index: var(--z-topbar);
}

.topbar__mobile-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--text-primary);
  align-items: center;
  justify-content: center;
}
.topbar__mobile-toggle svg { width: 20px; height: 20px; }

.topbar__breadcrumb {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.topbar__breadcrumb strong {
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
}
.topbar__breadcrumb-sep { opacity: 0.5; }

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Icon button base */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--dur-fast);
  position: relative;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-default);
}

/* Theme toggle: icon swap */
.theme-toggle__sun,
.theme-toggle__moon {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--dur-base), transform var(--dur-base);
}
.theme-toggle__moon { opacity: 0; transform: rotate(-90deg) scale(0.6); }
[data-theme="dark"] .theme-toggle__sun { opacity: 0; transform: rotate(90deg) scale(0.6); }
[data-theme="dark"] .theme-toggle__moon { opacity: 1; transform: rotate(0) scale(1); }

/* Lang switcher dropdown */
.lang-switcher {
  position: relative;
}
.lang-switcher__btn {
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  transition: all var(--dur-fast);
}
.lang-switcher__btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.lang-switcher__btn svg {
  width: 14px;
  height: 14px;
  transition: transform var(--dur-fast);
}
.lang-switcher[data-open="true"] .lang-switcher__btn svg { transform: rotate(180deg); }

.lang-switcher__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 140px;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: var(--z-dropdown);
}
.lang-switcher[data-open="true"] .lang-switcher__menu { display: flex; }

.lang-switcher__menu a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  transition: background var(--dur-fast);
}
.lang-switcher__menu a:hover { background: var(--surface-2); }
.lang-switcher__menu a.is-active {
  background: var(--accent-primary-subtle);
  color: var(--accent-primary);
  font-weight: 600;
}
.lang-switcher__code {
  width: 24px;
  height: 18px;
  border-radius: 3px;
  background: var(--surface-3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: var(--tracking-wider);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* User menu */
.user-menu { position: relative; }
.user-menu__btn {
  height: 36px;
  padding: 0 10px 0 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--dur-fast);
}
.user-menu__btn:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}
.user-menu__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-3);
}
.user-menu__name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu__btn svg {
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
  transition: transform var(--dur-fast);
}
.user-menu[data-open="true"] .user-menu__btn svg { transform: rotate(180deg); }

.user-menu__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: var(--z-dropdown);
}
.user-menu[data-open="true"] .user-menu__panel { display: flex; }

.user-menu__panel-header {
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 4px;
}
.user-menu__panel-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.user-menu__panel-email {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.user-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px 12px;
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: background var(--dur-fast);
}
.user-menu__item:hover { background: var(--surface-2); }
.user-menu__item svg { width: 16px; height: 16px; color: var(--text-tertiary); flex-shrink: 0; }
.user-menu__item--danger { color: var(--accent-danger); }
.user-menu__item--danger svg { color: var(--accent-danger); }
/* Deshabilitado: p.ej. "Eliminar cuenta" cuando ya hay una solicitud en curso. */
.user-menu__item:disabled,
.user-menu__item.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.user-menu__item:disabled:hover,
.user-menu__item.is-disabled:hover { background: transparent; }

/* ================================================================
   8. MAIN CONTENT AREA
   ================================================================ */
.main {
  grid-area: main;
  padding: var(--space-6) var(--space-7);
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
}

/* ================================================================
   9. FOOTER (minimalista)
   ================================================================ */
.app-footer {
  margin-top: var(--space-8);
  padding: var(--space-5) 0;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
.app-footer a { color: var(--text-secondary); }
.app-footer a:hover { color: var(--text-primary); }
.app-footer__links {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.app-footer__sep { opacity: 0.4; }

/* ================================================================
   10. UTILITY CLASSES (used across pages)
   ================================================================ */
.surface-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.surface-card--elevated { box-shadow: var(--shadow-md); }
.surface-card--glass {
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
  border: 1px solid var(--border-subtle);
  line-height: 1.4;
}
.chip svg { width: 12px; height: 12px; }
.chip--accent {
  background: var(--accent-primary-subtle);
  color: var(--accent-primary);
  border-color: transparent;
}
.chip--success {
  background: var(--accent-success-subtle);
  color: var(--accent-success);
  border-color: transparent;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--dur-fast);
  text-decoration: none;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(5, 92, 180, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
  box-shadow: 0 2px 8px rgba(5, 92, 180, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text-primary);
}

/* Scrollbar styling (subtle) */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; }

/* Focus ring */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ================================================================
   10.5 SHARED PAGE PATTERNS (inner header, preview banner, filter bar)
   ================================================================ */
.inner-page-header {
  max-width: var(--content-max-w);
  margin: 0 auto var(--space-5);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.inner-page-header__main {
  min-width: 0;
}
.inner-page-header__eyebrow {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: var(--space-1);
}
.inner-page-header__title {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}
.inner-page-header__subtitle {
  font-size: var(--text-md);
  color: var(--text-secondary);
  margin-top: var(--space-2);
}

.preview-banner {
  max-width: var(--content-max-w);
  margin: 0 auto var(--space-5);
  padding: 10px 14px;
  background: var(--accent-warning-subtle);
  border: 1px solid var(--accent-warning-subtle);
  color: var(--accent-warning);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.preview-banner strong { color: var(--accent-warning); font-weight: 700; }
.preview-banner svg { width: 16px; height: 16px; flex-shrink: 0; }

.filter-bar {
  max-width: var(--content-max-w);
  margin: 0 auto var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.filter-bar__label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  padding: 0 var(--space-2);
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur-fast);
}
.filter-chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.filter-chip--active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 6px var(--accent-primary-glow);
}
.filter-chip__count {
  font-size: 10px;
  font-weight: 700;
  opacity: 0.75;
  padding: 1px 5px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.18);
}
.filter-chip:not(.filter-chip--active) .filter-chip__count {
  background: var(--surface-3);
  color: var(--text-tertiary);
}

/* ================================================================
   11. RESPONSIVE — mobile: sidebar drawer
   ================================================================ */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 280px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
    transition: transform var(--dur-base) var(--ease-out);
  }
  [data-drawer="open"] .sidebar { transform: translateX(0); }
  [data-drawer="open"] body::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: calc(var(--z-sidebar) - 1);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  .topbar__mobile-toggle { display: inline-flex; }
  .sidebar__footer .sidebar-toggle { display: none; } /* no collapse on mobile */
  .main { padding: var(--space-4); }
  .user-menu__name { display: none; }
}

@media (max-width: 520px) {
  .topbar { padding: 0 var(--space-4); gap: var(--space-2); }
  .topbar__breadcrumb strong { font-size: var(--text-md); }
  .lang-switcher__btn { padding: 0 8px; }
}

/* ================================================================
   12. MOTION — reduce if user prefers
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
