/* ============================================================
   Buscador DOI Open Access - CyberLink Store
   Identidad del logo: azul marino, cian y nodos de circuito.
   Movil primero: las reglas base son para telefono y los
   @media (min-width) amplian hacia tableta y escritorio.
   ============================================================ */

/* ------------------------------------------------------------
   1. Tipografia y tokens
   ------------------------------------------------------------ */
@font-face {
  font-family: "Geist";
  src: url("assets/fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Geist Mono";
  src: url("assets/fonts/geist-mono.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* Marca: igual en ambos temas */
  --navy-950: #071426;
  --navy-900: #0B1B33;
  --navy-800: #102849;
  --navy-700: #17365F;
  --cyan: #2CC2F4;
  --cyan-soft: #A9E6FB;

  /* Superficies */
  --bg: #F1F4F9;
  --surface: #FDFEFF;
  --surface-2: #F3F6FA;
  --surface-3: #E5EBF3;
  --surface-inset: #F7F9FC;
  --scrim: rgb(7 20 38 / 0.5);

  /* Texto */
  --text: #0D1B30;
  --text-2: #2E3F57;
  --muted: #506176;
  --muted-2: #63748A;

  /* Lineas */
  --line: #D5DEE9;
  --line-strong: #B1C0D3;
  --line-subtle: #E5EBF3;

  /* Acciones */
  --primary: #0F3470;
  --primary-hover: #0A2858;
  --on-primary: #FFFFFF;
  --accent: #0A77A3;
  --accent-strong: #06597B;
  --accent-soft: #E2F4FB;

  /* Estados */
  --st-pdf: #0A7345;
  --st-oa: #0A6B94;
  --st-manual: #A04B06;
  --st-closed: #55657B;
  --st-imported: #3D56A6;
  --st-error: #B42B25;
  --st-pdf-soft: #E3F5EC;
  --st-manual-soft: #FBF0E4;
  --st-error-soft: #FBEAE9;

  /* 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;
  --sp-12: 48px;
  --gutter: 16px;

  /* Radios: controles 8, tarjetas 12, paneles 16 */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* Sombras teñidas con el azul de la marca */
  --shadow-sm: 0 1px 2px rgb(11 27 51 / 0.07);
  --shadow-md: 0 8px 20px -6px rgb(11 27 51 / 0.18);
  --shadow-lg: 0 20px 44px -12px rgb(11 27 51 / 0.32);

  /* Tipografia */
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;

  /* Movimiento */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --d-fast: 120ms;
  --d-base: 180ms;
  --d-sheet: 280ms;

  /* Densidad */
  --density: 1;
  --card-pad: calc(16px * var(--density));
  --grid-gap: calc(12px * var(--density));
  --touch: 44px;
  --shell: 1160px;
  --bar-h: 56px;
}

html[data-density="compact"] {
  --density: 0.72;
}

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

  --bg: #08111E;
  --surface: #0F1B2D;
  --surface-2: #142338;
  --surface-3: #1C2D47;
  --surface-inset: #0B1625;
  --scrim: rgb(3 8 16 / 0.65);

  --text: #E8EEF7;
  --text-2: #C5D2E2;
  --muted: #9BADC3;
  --muted-2: #8499B1;

  --line: #24364E;
  --line-strong: #3B516D;
  --line-subtle: #1B2A40;

  --primary: #46C6F2;
  --primary-hover: #74D6F7;
  --on-primary: #05202F;
  --accent: #46C6F2;
  --accent-strong: #8ADFFB;
  --accent-soft: #0F2A3D;

  --st-pdf: #52D596;
  --st-oa: #63C8EC;
  --st-manual: #F4A662;
  --st-closed: #9BADC3;
  --st-imported: #A1B5F3;
  --st-error: #FA8D85;
  --st-pdf-soft: #0D2A1F;
  --st-manual-soft: #2C1F10;
  --st-error-soft: #321717;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-md: 0 8px 20px -6px rgb(0 0 0 / 0.55);
  --shadow-lg: 0 20px 44px -12px rgb(0 0 0 / 0.7);
}

/* ------------------------------------------------------------
   2. Base
   ------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--bar-h) + 16px);
  background: var(--bg);
  scrollbar-color: var(--line-strong) transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}

body.is-locked {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

img,
svg {
  display: block;
  max-width: 100%;
}

h1, h2, h3, p, ul, ol {
  margin-top: 0;
}

h1, h2, h3 {
  text-wrap: balance;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
  text-underline-offset: 3px;
}

@media (hover: hover) and (pointer: fine) {
  a:hover {
    text-decoration: underline;
  }
}

::selection {
  background: var(--cyan-soft);
  color: #071426;
}

:where(a, button, input, select, textarea, summary, label.dropzone, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.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;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  padding: 10px 18px;
  border-radius: 0 0 var(--r-sm) 0;
  background: var(--navy-900);
  color: #fff;
  font-weight: 600;
}

.skip-link:focus {
  left: 0;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.muted-text {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* ------------------------------------------------------------
   3. Estructura
   ------------------------------------------------------------ */
.app-shell {
  width: min(var(--shell), 100%);
  margin: 0 auto;
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-6);
}

/* ------------------------------------------------------------
   4. Barra superior
   ------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: env(safe-area-inset-top);
  background: var(--navy-900);
  color: #fff;
}

.topbar a,
.topbar button {
  color: #fff;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  width: min(var(--shell), 100%);
  min-height: var(--bar-h);
  margin: 0 auto;
  padding: 6px max(var(--gutter), env(safe-area-inset-right)) 6px max(var(--gutter), env(safe-area-inset-left));
}

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

.topbar-brand:hover {
  text-decoration: none;
}

.topbar-logo {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  object-fit: contain;
}

.topbar-titles {
  min-width: 0;
}

.topbar h1,
.topbar-title {
  margin: 0;
  overflow: hidden;
  color: #fff;
  font-size: var(--fs-base);
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-sub {
  margin: 0;
  overflow: hidden;
  color: var(--cyan-soft);
  font-size: var(--fs-xs);
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.h1-more {
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin: 0;
}

.topbar-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-width: var(--touch);
  min-height: var(--touch);
  border: 0;
  border-radius: var(--r-sm);
  padding: 0 var(--sp-3);
  background: transparent;
  font-size: var(--fs-sm);
  font-weight: 550;
  text-decoration: none;
  transition: background-color var(--d-base) var(--ease-out), transform var(--d-fast) var(--ease-out);
}

.pill-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.pill-badge {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 18px;
  border-radius: var(--r-pill);
  padding: 0 5px;
  background: var(--cyan);
  color: #05202F;
  font-size: 0.6875rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 18px;
  text-align: center;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: #fff;
  transition: background-color var(--d-base) var(--ease-out), transform var(--d-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .topbar-pill:hover,
  .icon-button:hover {
    background: rgb(255 255 255 / 0.12);
    text-decoration: none;
  }
}

.topbar :focus-visible {
  outline-color: var(--cyan);
}

.theme-moon,
[data-theme="dark"] .theme-sun,
html[data-density="compact"] .density-comfortable,
.density-compact {
  display: none;
}

[data-theme="dark"] .theme-moon,
html[data-density="compact"] .density-compact {
  display: block;
}

/* ------------------------------------------------------------
   5. Botones
   ------------------------------------------------------------ */
.primary,
.secondary,
.text-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--touch);
  border-radius: var(--r-sm);
  padding: 0 var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
  transition:
    transform var(--d-fast) var(--ease-out),
    background-color var(--d-base) var(--ease-out),
    border-color var(--d-base) var(--ease-out),
    color var(--d-base) var(--ease-out);
}

.primary {
  position: relative;
  border: 1px solid transparent;
  background: var(--primary);
  color: var(--on-primary);
}

.primary-lg {
  min-height: 50px;
  padding: 0 var(--sp-5);
  font-size: var(--fs-base);
}

.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
}

.text-link {
  border: 1px solid transparent;
  background: transparent;
  color: var(--accent-strong);
  padding: 0 var(--sp-3);
}

.icon-only {
  width: var(--touch);
  padding: 0;
}

@media (hover: hover) and (pointer: fine) {
  .primary:hover:not(:disabled) {
    background: var(--primary-hover);
  }

  .secondary:hover:not(:disabled) {
    border-color: var(--line-strong);
    background: var(--surface-2);
    color: var(--text);
  }

  .text-link:hover:not(:disabled) {
    background: var(--accent-soft);
    text-decoration: none;
  }

  .secondary.danger-action:hover:not(:disabled),
  .text-link.danger-action:hover:not(:disabled) {
    background: var(--st-error-soft);
    border-color: var(--st-error);
    color: var(--st-error);
  }
}

.primary:active:not(:disabled),
.secondary:active:not(:disabled),
.text-link:active:not(:disabled),
.topbar-pill:active,
.icon-button:active,
.icon-button-plain:active,
.chip:active,
.fav-btn:active,
.drawer-tab:active,
.modal-close:active {
  transform: scale(0.97);
}

.danger-action {
  color: var(--st-error);
}

.secondary.danger-action {
  border-color: color-mix(in srgb, var(--st-error), transparent 60%);
}

.btn-face {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}

.is-busy .btn-face {
  opacity: 0.75;
}

.btn-kbd {
  display: none;
  border: 1px solid color-mix(in srgb, var(--on-primary), transparent 70%);
  border-radius: 5px;
  padding: 0 6px;
  color: inherit;
  font-size: 0.6875rem;
  line-height: 1.6;
  opacity: 0.8;
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 650ms linear infinite;
}

.inline-link {
  display: inline;
  border: none;
  padding: 0;
  background: none;
  color: var(--accent-strong);
  font-weight: 550;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.icon-button-plain {
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  transition: background-color var(--d-base) var(--ease-out), color var(--d-base) var(--ease-out), transform var(--d-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .icon-button-plain:hover {
    background: var(--surface-2);
    color: var(--text);
  }
}

/* ------------------------------------------------------------
   6. Formularios
   ------------------------------------------------------------ */
label,
.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-base); /* 16px: iOS no hace zoom al enfocar */
  caret-color: var(--accent);
  transition: border-color var(--d-base) var(--ease-out), box-shadow var(--d-base) var(--ease-out);
}

::placeholder {
  color: var(--muted-2);
  opacity: 1;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 72%);
  outline: none;
}

input,
select {
  height: var(--touch);
  padding: 0 var(--sp-3);
}

select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--touch);
  margin: 0;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
}

/* ------------------------------------------------------------
   7. Inicio: la tarea principal sobre la banda de circuitos
   ------------------------------------------------------------ */
.start {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-6);
}

.start-lede {
  position: relative;
  isolation: isolate;
  padding: var(--sp-6) 0 72px;
  background-color: var(--navy-900); /* Respaldo si la imagen no carga */
  color: #fff;
}

.start-lede::before {
  content: "";
  position: absolute;
  inset: 0 calc(50% - 50vw);
  z-index: -1;
  background:
    linear-gradient(180deg, rgb(11 27 51 / 0.8) 0%, rgb(11 27 51 / 0.5) 100%),
    url("assets/img/Fondo-BG-cl.webp") center 40% / cover no-repeat,
    var(--navy-900);
}

.start-lede h2 {
  margin: 0 0 var(--sp-2);
  color: #fff;
  font-size: var(--fs-2xl);
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.search-sub {
  max-width: 56ch;
  margin: 0;
  color: #D6E4F2;
  font-size: var(--fs-base);
}

.search-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
  margin-top: -72px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.start > .search-card {
  position: relative;
  z-index: 1;
}

.textarea-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-height: 28px;
}

.textarea-head label {
  margin: 0;
}

.textarea-wrap textarea {
  display: block;
  min-height: 148px;
  padding: var(--sp-3);
  resize: vertical;
  background: var(--surface-inset);
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  line-height: 1.6;
}

/* En telefono el texto de 16px evita el zoom de iOS */
@media (max-width: 767px) {
  .textarea-wrap textarea {
    font-size: 1rem;
  }
}

.counter-chip {
  color: var(--muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.counter-chip.has-dupes {
  color: var(--st-manual);
  font-weight: 550;
}

.search-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-2);
}

.search-actions .primary {
  width: 100%;
}

.search-secondary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
}

.search-secondary .secondary {
  flex: 1 1 100%;
}

.search-secondary .text-link {
  flex: 1 1 auto;
}

.local-hint {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  margin: 0;
  border-top: 1px solid var(--line-subtle);
  padding-top: var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.local-hint > .icon {
  margin-top: 2px;
  color: var(--muted-2);
}

.local-hint span {
  flex: 1;
}

.hint-dismiss {
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  margin: -10px -10px -10px 0;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted-2);
}

/* Como funciona */
.how-it-works {
  display: grid;
  gap: var(--sp-4);
  margin: 0;
  padding: 0 var(--sp-1);
  list-style: none;
}

.how-it-works li {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
}

.step-num {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  color: var(--accent-strong);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.how-it-works strong {
  display: block;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: 600;
}

.how-it-works div > span {
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* Con resultados, la consulta se pliega y deja paso a la lista */
.composer-bar {
  display: none;
}

.start.has-results {
  gap: var(--sp-2);
  padding-top: var(--sp-2);
}

.start.has-results .start-lede,
.start.has-results .how-it-works {
  display: none;
}

.start.has-results .search-card {
  margin-top: 0;
  box-shadow: var(--shadow-sm);
}

.start.has-results .composer-bar {
  display: flex;
  justify-content: flex-end;
}

.start.has-results:not(.is-open) .search-card {
  display: none;
}

.composer-toggle {
  border-color: transparent;
  background: transparent;
  color: var(--accent-strong);
}

.composer-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

/* ------------------------------------------------------------
   8. Resultados
   ------------------------------------------------------------ */
.results {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-4);
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.results-title h2 {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.results-title p {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.results-actions {
  display: flex;
  flex: 0 0 auto;
  gap: var(--sp-2);
}

/* En telefono, Limpiar es solo su icono (con nombre para lectores de pantalla) */
.clear-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

#clearBtn {
  width: var(--touch);
  padding: 0;
}

.results-actions .chevron {
  transition: transform var(--d-base) var(--ease-out);
}

[aria-expanded="true"] > .chevron {
  transform: rotate(180deg);
}

/* Boton de ZIP siempre a mano en el telefono */
#downloadAllBtn {
  position: fixed;
  left: max(var(--gutter), env(safe-area-inset-left));
  right: max(var(--gutter), env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 40;
  min-height: 52px;
  font-size: var(--fs-base);
}

body:has(.results:not([hidden]) #downloadAllBtn:not(:disabled))::before {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 34;
  height: calc(76px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

body:has(.bulk-bar:not([hidden]))::before,
body:has(.task-panel:not([hidden]))::before {
  display: none;
}

body:has(.scroll-top-btn.visible) #downloadAllBtn {
  right: calc(max(var(--gutter), env(safe-area-inset-right)) + 52px);
}

#downloadAllBtn:disabled,
body:has(.bulk-bar:not([hidden])) #downloadAllBtn,
body:has(.task-panel:not([hidden])) #downloadAllBtn {
  display: none;
}

/* Busqueda */
.toolbar {
  display: flex;
  gap: var(--sp-2);
}

.search-wrap {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  min-width: 0;
}

.search-wrap input {
  padding-left: 40px;
}

.search-icon {
  position: absolute;
  left: 13px;
  color: var(--muted-2);
  pointer-events: none;
}

.search-wrap:focus-within .search-icon {
  color: var(--accent);
}

.search-kbd {
  display: none;
  position: absolute;
  right: 12px;
  min-width: 22px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.6875rem;
  text-align: center;
  pointer-events: none;
}

.search-wrap:focus-within .search-kbd {
  opacity: 0;
}

.toolbar-controls {
  display: flex;
  flex: 0 0 auto;
  gap: var(--sp-2);
}

/* En telefono: Filtros solo con icono y sin densidad, que no aporta */
.filter-toggle-btn {
  padding: 0 var(--sp-3);
}

.filter-toggle-btn > span:not(.filter-count) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

#densityToggle {
  display: none;
}

.filter-toggle-btn[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.filter-count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  border-radius: var(--r-pill);
  padding: 0 6px;
  background: var(--accent);
  color: var(--surface);
  font-size: 0.6875rem;
  font-weight: 700;
}

/* Filtros de estado: fila deslizable en el telefono */
.chip-row {
  margin: 0 calc(-1 * var(--gutter));
}

.status-chips {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  overflow-x: auto;
  padding: 2px var(--gutter);
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
  scroll-padding-inline: var(--gutter);
}

.status-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 0 var(--sp-3);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  scroll-snap-align: start;
  transition: transform var(--d-fast) var(--ease-out), border-color var(--d-base) var(--ease-out), background-color var(--d-base) var(--ease-out), color var(--d-base) var(--ease-out);
}

.chip .icon {
  width: 15px;
  height: 15px;
}

.chip-count {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

@media (hover: hover) and (pointer: fine) {
  .chip:hover {
    border-color: var(--line-strong);
    color: var(--text);
  }
}

.chip.is-active {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
}

.chip.is-active .chip-count {
  color: inherit;
  opacity: 0.85;
}

.chip.is-active .icon {
  fill: currentColor;
}

.chip.is-empty:not(.is-active) {
  display: none;
}

.chip-sep {
  flex: 0 0 auto;
  width: 1px;
  height: 22px;
  background: var(--line);
}

/* Filtros avanzados */
.toolbar-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  background: var(--surface-2);
}

.field {
  min-width: 0;
}

.range-inputs {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--muted);
}

.toolbar-switches {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  grid-column: 1 / -1;
}

/* Barra de lista */
.list-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.list-bar {
  flex-wrap: nowrap;
}

.list-bar:has(.pager:not([hidden])) {
  flex-wrap: wrap;
}

.select-all-field {
  flex: 0 0 auto;
}

.list-controls {
  display: flex;
  flex: 1 1 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  min-width: 0;
}

#sortSelect {
  flex: 0 1 auto;
  width: auto;
  min-width: 0;
  max-width: 100%;
}

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

.pager select {
  width: auto;
}

.pager span {
  min-width: 48px;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* ------------------------------------------------------------
   9. Tarjeta de resultado
   ------------------------------------------------------------ */
.results-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--grid-gap);
}

.result-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: calc(12px * var(--density));
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--card-pad);
  background: var(--surface);
  transition: border-color var(--d-base) var(--ease-out), background-color var(--d-base) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .result-card:hover {
    border-color: var(--line-strong);
  }
}

.result-card.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft), var(--surface) 45%);
}

.result-card.is-dragover {
  border-color: var(--accent);
  border-style: dashed;
  background: var(--accent-soft);
}

.card-main {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
}

/* Area de toque de 44px alrededor de la casilla */
.card-check {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: -12px -12px 0 -12px;
}

.card-body {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 6px;
}

.card-kicker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.kicker-meta {
  min-width: 0;
}

.result-card h3 {
  margin: 0;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
  text-wrap: pretty;
  overflow-wrap: anywhere;
}

.card-authors {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.card-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.meta-doi {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  max-width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 0 6px 0 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  text-align: left;
  transition: color var(--d-base) var(--ease-out);
}

.meta-doi span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-doi .icon {
  width: 14px;
  height: 14px;
  opacity: 0.7;
}

@media (hover: hover) and (pointer: fine) {
  .meta-doi:hover {
    color: var(--accent-strong);
  }
}

.meta-doi.is-copied {
  color: var(--st-pdf);
}

/* Estado: nodo de circuito, como los del logo */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--st-closed);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: "";
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.badge.pdf { color: var(--st-pdf); }
.badge.pdf::before { background: currentColor; box-shadow: inset 0 0 0 2px var(--surface); }
.badge.oa_no_pdf { color: var(--st-oa); }
.badge.imported { color: var(--st-imported); }
.badge.closed { color: var(--st-closed); }
.badge.error { color: var(--st-error); }
.badge.manual { color: var(--st-manual); }

.dl-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  border-radius: 6px;
  padding: 0 8px;
  background: var(--st-pdf-soft);
  color: var(--st-pdf);
  font-size: var(--fs-xs);
  font-weight: 600;
}

.dl-pill .icon {
  width: 13px;
  height: 13px;
}

/* Favorito */
.fav-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: -10px -10px 0 -6px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted-2);
  transition: transform var(--d-fast) var(--ease-out), color var(--d-base) var(--ease-out);
}

.fav-btn .icon {
  width: 20px;
  height: 20px;
}

@media (hover: hover) and (pointer: fine) {
  .fav-btn:hover {
    color: var(--accent-strong);
  }
}

.fav-btn.is-active {
  color: var(--accent);
}

.fav-btn.is-active .icon {
  fill: currentColor;
}

mark.hit {
  border-radius: 3px;
  padding: 0 2px;
  background: var(--cyan-soft);
  color: #071426;
}

/* Etiquetas */
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 0;
  border-radius: var(--r-pill);
  padding: 0 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: var(--fs-xs);
  font-weight: 550;
  transition: transform var(--d-fast) var(--ease-out);
}

.tag:active {
  transform: scale(0.96);
}

/* Aviso de descarga manual */
.manual-note {
  display: grid;
  gap: var(--sp-2);
  border-radius: var(--r-sm);
  padding: var(--sp-3);
  background: var(--st-manual-soft);
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.manual-note > .icon {
  display: none;
}

.manual-note p {
  margin: 0;
}

.manual-note strong {
  color: var(--text);
}

.manual-note .note-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.manual-note .note-actions .primary {
  grid-column: 1 / -1;
}

/* Acciones: la principal arriba y el resto en fila pareja */
.card-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) var(--touch);
  align-items: center;
  gap: 6px;
}

.card-actions .primary,
.card-actions > a.secondary:first-child,
.card-actions > .text-link {
  grid-column: 1 / -1;
}

.card-actions .primary,
.card-actions .secondary,
.card-actions .text-link {
  width: 100%;
  padding: 0 var(--sp-2);
}

.card-actions .spacer {
  display: none;
}

.card-actions .organize-btn[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.organize-note {
  color: var(--muted);
  font-weight: 500;
}

.more-btn {
  padding: 0 !important;
}

.more-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* Organizador */
.organizer-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
  border-radius: var(--r-sm);
  padding: var(--sp-3);
  background: var(--surface-2);
}

.organizer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
}

.organizer-panel label {
  margin-bottom: 0;
}

.organizer-panel input {
  margin-top: 4px;
}

.notes-input {
  min-height: 84px;
  margin-top: 4px;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font);
  resize: vertical;
}

.ris-details summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--touch);
  color: var(--accent-strong);
  font-size: var(--fs-sm);
  font-weight: 550;
  cursor: pointer;
}

.ris-table {
  display: grid;
  gap: 2px;
  margin-top: var(--sp-2);
}

.ris-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: var(--sp-2);
  padding: 3px 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.ris-row strong {
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

.ris-row span {
  overflow-wrap: anywhere;
}

/* Vacio y carga */
.empty-state {
  display: grid;
  place-items: center;
  gap: var(--sp-2);
  padding: var(--sp-10) var(--sp-5);
  color: var(--muted);
  text-align: center;
}

.empty-state.compact {
  padding: var(--sp-8) var(--sp-4);
}

.empty-icon {
  width: 32px;
  height: 32px;
  margin-bottom: var(--sp-1);
  color: var(--line-strong);
  stroke-width: 1.5;
}

.empty-state strong {
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: 600;
}

.empty-state span {
  max-width: 380px;
  font-size: var(--fs-sm);
}

.empty-state .secondary {
  margin-top: var(--sp-2);
}

.skeleton-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--grid-gap);
}

.skeleton-card {
  height: 148px;
  border-radius: var(--r-md);
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}

/* ------------------------------------------------------------
   9b. Pendientes y descarga asistida
   ------------------------------------------------------------ */
.pending-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-2);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  background: var(--st-manual-soft);
}

.pending-icon {
  display: none;
  color: var(--st-manual);
}

.pending-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.pending-text strong {
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.pending-text span {
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.pending-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}

/* Importar TXT sigue disponible en "Nueva consulta" */
#pendingTxtBtn {
  display: none;
}

.modal-wide {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-4);
}

.modal-wide h3 {
  margin-bottom: 0;
}

.modal-wide .modal-actions {
  margin-top: 0;
}

.assist-steps {
  display: grid;
  gap: var(--sp-2);
  margin: 0;
  padding-left: var(--sp-5);
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.assist-steps strong {
  color: var(--text);
}

.assist-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  max-height: 44dvh;
  margin: 0;
  padding: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.assist-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--sp-3);
  background: var(--surface);
}

.assist-item.is-opened {
  border-color: color-mix(in srgb, var(--accent), transparent 45%);
}

.assist-item.is-done {
  border-color: color-mix(in srgb, var(--st-pdf), transparent 55%);
  background: var(--st-pdf-soft);
}

.assist-num {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.assist-item.is-done .assist-num {
  border-color: var(--st-pdf);
  color: var(--st-pdf);
}

.assist-item.is-done .assist-num .icon {
  width: 14px;
  height: 14px;
}

.assist-body {
  flex: 1 1 calc(100% - 46px);
  min-width: 0;
  display: grid;
  gap: 1px;
}

.assist-body strong {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.assist-body > span {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

.assist-actions {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  gap: var(--sp-1);
  padding-left: 38px;
}

.assist-actions .secondary {
  flex: 1;
}

.assist-actions .text-link {
  width: var(--touch);
  padding: 0;
}

.assist-state {
  flex: 0 0 auto;
  color: var(--text-2);
  font-weight: 600;
}

.assist-item.is-opened .assist-state {
  color: var(--accent-strong);
}

.assist-item.is-done .assist-state {
  color: var(--st-pdf);
}

.assist-drop {
  padding: var(--sp-5) var(--sp-4);
}

.assist-review {
  display: grid;
  gap: var(--sp-3);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  background: var(--st-manual-soft);
}

.review-title {
  margin: 0;
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.review-title strong {
  color: var(--text);
}

.review-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
}

.review-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-why {
  color: var(--text-2);
  font-size: var(--fs-xs);
}

.review-actions {
  display: flex;
  justify-content: flex-end;
}

.assist-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.assist-progress {
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.drop-overlay {
  position: fixed;
  top: calc(var(--bar-h) + 12px + env(safe-area-inset-top));
  left: 50%;
  z-index: 170;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: min(620px, calc(100% - 24px));
  border: 1.5px dashed var(--accent);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--text-2);
  font-size: var(--fs-sm);
  transform: translateX(-50%);
  pointer-events: none;
}

.drop-overlay .icon {
  color: var(--accent-strong);
}

.drop-overlay strong {
  color: var(--text);
}

/* ------------------------------------------------------------
   10. Menu: hoja inferior en el telefono
   ------------------------------------------------------------ */
.action-menu {
  position: fixed;
  z-index: 140;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

@media (max-width: 767px) {
  /* !important: gana a la posicion de popover que app.js fija en linea */
  .action-menu {
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    max-height: 80dvh;
    border-top: 1px solid var(--line);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: var(--sp-2) var(--sp-2) calc(var(--sp-2) + env(safe-area-inset-bottom));
    animation: sheetIn var(--d-sheet) var(--ease-drawer);
  }
}

body:has(.action-menu:not([hidden]))::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 135;
  background: var(--scrim);
  pointer-events: none;
  animation: fadeIn var(--d-base) var(--ease-out);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: var(--r-sm);
  padding: 0 var(--sp-3);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  transition: background-color var(--d-fast) var(--ease-out);
}

.menu-item .icon {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.menu-item:focus-visible {
  outline-offset: -2px;
}

@media (hover: hover) and (pointer: fine) {
  .menu-item:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
  }
}

.menu-item.is-danger,
.menu-item.is-danger .icon {
  color: var(--st-error);
}

.menu-item small {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.menu-sep {
  height: 1px;
  margin: var(--sp-1) var(--sp-2);
  background: var(--line-subtle);
}

/* ------------------------------------------------------------
   11. Mi biblioteca: hoja casi completa en el telefono
   ------------------------------------------------------------ */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: var(--scrim);
  animation: fadeIn var(--d-base) var(--ease-out);
}

.drawer {
  position: fixed;
  top: max(24px, env(safe-area-inset-top));
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 120;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateY(0);
  transition: transform var(--d-sheet) var(--ease-drawer);
}

.drawer.is-entering,
.drawer.is-leaving {
  transform: translateY(100%);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-3) var(--sp-3) var(--sp-4);
}

.drawer-head h2 {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.drawer-head p {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.drawer-tabs {
  display: flex;
  gap: var(--sp-1);
  margin: 0 var(--sp-4);
  border-bottom: 1px solid var(--line);
}

.drawer-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch);
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 550;
  transition: color var(--d-base) var(--ease-out), border-color var(--d-base) var(--ease-out);
}

.drawer-tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--text);
}

.tab-count {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-4);
}

.drawer-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-4);
  align-content: start;
}

.drawer-foot {
  display: none;
  justify-content: center;
  border-top: 1px solid var(--line-subtle);
  padding: var(--sp-2) var(--sp-5);
}

.mini-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.mini-list:empty {
  display: none;
}

.mini-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  padding: var(--sp-3) 0;
}

.mini-item + .mini-item {
  border-top: 1px solid var(--line-subtle);
}

.mini-item strong {
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.mini-item .mini-meta {
  color: var(--muted);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
}

.mini-item .card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-left: calc(-1 * var(--sp-2));
}

.mini-item .card-actions .text-link {
  width: auto;
  padding: 0 var(--sp-2);
}

.mini-kind {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 550;
}

.mini-kind .icon {
  width: 13px;
  height: 13px;
}

.mini-kind.is-linked {
  color: var(--accent-strong);
}

.dropzone {
  display: grid;
  place-items: center;
  gap: var(--sp-1);
  margin: 0;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-md);
  padding: var(--sp-6) var(--sp-4);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 400;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--d-base) var(--ease-out), background-color var(--d-base) var(--ease-out);
}

.dropzone .icon {
  width: 24px;
  height: 24px;
  color: var(--accent-strong);
}

.dropzone strong {
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: 600;
}

@media (hover: hover) and (pointer: fine) {
  .dropzone:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
}

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

.backup-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
  padding-bottom: var(--sp-5);
  border-bottom: 1px solid var(--line-subtle);
}

.backup-block:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.backup-block h3 {
  margin: 0;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: 600;
}

.backup-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.backup-actions > button {
  flex: 1 1 150px;
}

.storage-meter {
  display: grid;
  gap: 6px;
}

.storage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.storage-head strong {
  color: var(--text-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.storage-track {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.storage-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--d-sheet) var(--ease-out);
}

.storage-track span.is-high { background: var(--st-manual); }
.storage-track span.is-critical { background: var(--st-error); }

.persist-status {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.persist-status.is-on {
  color: var(--st-pdf);
  font-weight: 550;
}

/* ------------------------------------------------------------
   12. Seleccion multiple
   ------------------------------------------------------------ */
.bulk-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  padding: 0 0 env(safe-area-inset-bottom);
  background: var(--navy-900);
  box-shadow: var(--shadow-lg);
  animation: sheetIn var(--d-base) var(--ease-out);
}

.bulk-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4);
}

.bulk-count {
  flex: 0 0 auto;
  color: #D6E4F2;
  font-size: var(--fs-xs);
}

.bulk-count strong {
  display: block;
  color: #fff;
  font-size: var(--fs-lg);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.bulk-actions {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(4, minmax(0, 1fr)) var(--touch);
  align-items: center;
  gap: 4px;
}

.bulk-bar .secondary,
.bulk-bar .primary {
  width: 100%;
  padding: 0;
}

.bulk-bar .secondary span,
.bulk-bar .primary span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.bulk-bar .secondary {
  border-color: transparent;
  background: rgb(255 255 255 / 0.1);
  color: #fff;
}

.bulk-bar .primary {
  background: var(--cyan);
  color: #05202F;
}

.bulk-bar .danger-action {
  color: #FFC2BC;
}

.bulk-bar :focus-visible {
  outline-color: var(--cyan);
}

@media (hover: hover) and (pointer: fine) {
  .bulk-bar .secondary:hover:not(:disabled) {
    border-color: transparent;
    background: rgb(255 255 255 / 0.2);
    color: #fff;
  }

  .bulk-bar .primary:hover:not(:disabled) {
    background: var(--cyan-soft);
  }
}

/* ------------------------------------------------------------
   13. Progreso en segundo plano
   ------------------------------------------------------------ */
.task-panel {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 70;
  display: grid;
  gap: var(--sp-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-out);
}

@starting-style {
  .task-panel {
    opacity: 0;
    transform: translateY(12px);
  }
}

body:has(.bulk-bar:not([hidden])) .task-panel {
  bottom: calc(76px + env(safe-area-inset-bottom));
}

.task-top {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.task-spinner {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.task-text {
  flex: 1;
  min-width: 0;
  display: grid;
}

.task-text strong {
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.task-text span {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-cancel {
  flex: 0 0 auto;
}

.task-stats {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.task-stats:empty {
  display: none;
}

.task-stats b {
  font-weight: 650;
}

.task-stats .ok { color: var(--st-pdf); }
.task-stats .manual { color: var(--st-manual); }

/* Progreso: una traza de circuito con su nodo al frente */
.progress-bar {
  height: 10px;
  display: flex;
  align-items: center;
  margin-right: 5px;
  background: linear-gradient(var(--surface-3), var(--surface-3)) center / 100% 2px no-repeat;
}

.progress-bar span {
  position: relative;
  display: block;
  width: 0;
  height: 2px;
  background: var(--accent);
  transition: width var(--d-sheet) var(--ease-out);
}

.progress-bar span::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -5px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
  transform: translateY(-50%);
}

/* ------------------------------------------------------------
   14. Avisos
   ------------------------------------------------------------ */
.toast-stack {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  top: calc(var(--bar-h) + 8px + env(safe-area-inset-top));
  z-index: 160;
  display: grid;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--text);
  pointer-events: auto;
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-out);
}

@starting-style {
  .toast {
    opacity: 0;
    transform: translateY(-12px);
  }
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(-12px);
  transition-duration: 140ms;
}

.toast > .icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  color: var(--accent-strong);
}

.toast-body {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-body strong {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
}

.toast-body span {
  display: block;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.4;
}

.toast-action {
  margin-top: var(--sp-2);
  white-space: normal;
}

.toast.is-success > .icon { color: var(--st-pdf); }
.toast.is-warning > .icon { color: var(--st-manual); }
.toast.is-error > .icon { color: var(--st-error); }

.toast-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  margin: -6px -6px -6px 0;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
}

/* ------------------------------------------------------------
   15. Dialogo: hoja inferior en el telefono
   ------------------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: grid;
  align-items: end;
  background: var(--scrim);
  animation: fadeIn var(--d-base) var(--ease-out);
}

.modal {
  position: relative;
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: var(--sp-5) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: sheetIn var(--d-sheet) var(--ease-drawer);
}

.modal-close {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  transition: background-color var(--d-base) var(--ease-out), transform var(--d-fast) var(--ease-out);
}

.modal h3 {
  margin: 0 0 var(--sp-2);
  padding-right: 44px;
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.015em;
}

.modal-message {
  color: var(--muted);
  font-size: var(--fs-base);
  white-space: pre-line;
}

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

.modal-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

.modal-actions > button {
  width: 100%;
}

.modal-actions .primary.danger-action {
  background: var(--st-error);
  color: #fff;
}

[data-theme="dark"] .modal-actions .primary.danger-action {
  color: #2A0A08;
}

.shortcut-list {
  display: grid;
  gap: var(--sp-2);
  margin: var(--sp-2) 0 0;
  padding: 0;
  list-style: none;
  white-space: normal;
}

.shortcut-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.shortcut-list kbd {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 8px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

/* ------------------------------------------------------------
   16. Volver arriba y pie
   ------------------------------------------------------------ */
.scroll-top-btn {
  position: fixed;
  right: max(var(--gutter), env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 35;
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-out);
}

.scroll-top-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

body:has(.bulk-bar:not([hidden])) .scroll-top-btn,
body:has(.task-panel:not([hidden])) .scroll-top-btn {
  opacity: 0;
  pointer-events: none;
}

.app-footer {
  margin-top: var(--sp-10);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.app-footer p {
  max-width: 70ch;
  margin-bottom: var(--sp-1);
}

.app-footer .credits {
  margin-bottom: 0;
  color: var(--text-2);
  font-weight: 550;
}

/* ------------------------------------------------------------
   17. Guia de uso
   ------------------------------------------------------------ */
.guide-shell {
  --shell: 1040px;
}

.guide-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-8);
  padding-top: var(--sp-6);
}

.guide-panel {
  scroll-margin-top: calc(var(--bar-h) + 16px);
}

.guide-panel h2 {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0 0 var(--sp-3);
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.guide-panel h2 .icon {
  display: none;
}

.guide-panel p,
.guide-panel li {
  max-width: 70ch;
  color: var(--text-2);
  line-height: 1.6;
}

.guide-panel p:last-child {
  margin-bottom: 0;
}

.guide-panel ol,
.guide-panel ul {
  margin-bottom: var(--sp-3);
  padding-left: var(--sp-5);
}

.guide-panel li {
  margin-bottom: var(--sp-2);
}

.guide-panel strong {
  color: var(--text);
  font-weight: 600;
}

.guide-status {
  display: grid;
  gap: var(--sp-3);
  margin: 0;
  padding: 0 !important;
  list-style: none;
}

.guide-status li {
  display: grid;
  gap: 2px;
  margin: 0;
}

.guide-toc {
  display: flex;
  gap: var(--sp-1) var(--sp-3);
  flex-wrap: wrap;
}

.guide-toc a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  color: var(--accent-strong);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.guide-panel .shortcut-list {
  padding: 0;
}

/* ------------------------------------------------------------
   18. Panel de administracion
   ------------------------------------------------------------ */
.admin-page .topbar-inner {
  --shell: 960px;
}

.admin-shell {
  display: block;
  width: min(960px, 100%);
  margin: 0 auto;
  padding: var(--sp-5) max(var(--gutter), env(safe-area-inset-right)) calc(var(--sp-12) + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

.admin-page h1 {
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.admin-title {
  margin-top: var(--sp-5) !important;
}

.admin-card {
  margin-top: var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  background: var(--surface);
}

.admin-card h2 {
  margin: 0 0 var(--sp-3);
  font-size: var(--fs-base);
  font-weight: 600;
}

.admin-narrow {
  max-width: 440px;
  margin: var(--sp-8) auto 0;
}

.admin-form {
  display: grid;
  gap: var(--sp-4);
  margin-top: var(--sp-4);
}

.admin-card > .admin-form:first-of-type {
  margin-top: 0;
}

.admin-form label {
  margin: 0;
}

.admin-form input {
  margin-top: 6px;
}

.admin-form small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 400;
}

.admin-alert {
  margin: 0 0 var(--sp-3);
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 550;
}

.admin-alert.is-ok {
  background: var(--st-pdf-soft);
  color: var(--st-pdf);
}

.admin-alert.is-bad {
  background: var(--st-error-soft);
  color: var(--st-error);
}

.admin-tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.admin-tabs a {
  display: inline-flex;
  flex: 1 0 auto;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  padding: 0 var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 550;
}

.admin-tabs a:hover {
  text-decoration: none;
}

.admin-tabs a[aria-current="page"] {
  border-bottom-color: var(--accent);
  color: var(--text);
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4);
  margin: var(--sp-3) 0;
}

.admin-stats dt {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.admin-stats dd {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.admin-note {
  margin-top: var(--sp-3);
}

.admin-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.admin-table th {
  padding: 0 var(--sp-2) var(--sp-2) 0;
  color: var(--muted);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.admin-table td {
  padding: var(--sp-2) var(--sp-2) var(--sp-2) 0;
  border-top: 1px solid var(--line-subtle);
  color: var(--text-2);
}

.admin-table .num {
  padding-right: 0;
  padding-left: var(--sp-3);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.admin-table .host {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}

@media (max-width: 767px) {
  .admin-table-hosts thead {
    display: none;
  }

  .admin-table-hosts tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2px var(--sp-2);
    padding: var(--sp-3) 0;
    border-top: 1px solid var(--line-subtle);
  }

  .admin-table-hosts td {
    padding: 0;
    border: 0;
  }

  .admin-table-hosts .host {
    grid-column: 1 / -1;
    color: var(--text);
    font-weight: 500;
  }

  .admin-table-hosts .num {
    padding: 0;
    text-align: left;
  }

  .admin-table-hosts .num::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: var(--fs-xs);
  }
}

.admin-list {
  display: grid;
  gap: var(--sp-2);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--fs-sm);
}

.admin-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  color: var(--text-2);
}

.admin-list strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.admin-checks {
  display: grid;
  gap: var(--sp-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.admin-checks li {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: var(--sp-2);
  font-size: var(--fs-sm);
}

.admin-checks strong {
  font-weight: 500;
}

.admin-checks small {
  display: block;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.check-state {
  font-weight: 600;
}

.admin-checks .is-ok .check-state { color: var(--st-pdf); }
.admin-checks .is-warn .check-state { color: var(--st-manual); }
.admin-checks .is-bad .check-state { color: var(--st-error); }

/* ------------------------------------------------------------
   19. Animaciones
   ------------------------------------------------------------ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheetIn {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes popoverIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}

/* Telefonos muy angostos: el nombre debe leerse completo */
@media (max-width: 359px) {
  .topbar-inner,
  .topbar-brand {
    gap: var(--sp-2);
  }

  .topbar-actions {
    gap: 0;
  }

  .brand-sub {
    display: none;
  }
}

/* ------------------------------------------------------------
   20. Telefono ancho (desde 480px)
   ------------------------------------------------------------ */
@media (min-width: 480px) {
  .h1-more {
    display: inline;
  }

  .search-secondary .secondary {
    flex: 0 1 auto;
  }

  .search-secondary .text-link {
    flex: 0 1 auto;
  }

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

/* ------------------------------------------------------------
   21. Tableta (desde 768px)
   ------------------------------------------------------------ */
@media (min-width: 768px) {
  :root {
    --gutter: 24px;
    --bar-h: 60px;
    --fs-2xl: 2.125rem;
  }

  body {
    font-size: 0.9375rem;
  }

  .topbar-logo {
    width: 40px;
    height: 40px;
  }

  .topbar h1,
  .topbar-title {
    font-size: 1.0625rem;
  }

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

  .pill-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  .pill-badge {
    position: static;
  }

  .start-lede {
    padding: var(--sp-8) 0 84px;
  }

  .search-card {
    margin-top: -84px;
    padding: var(--sp-5);
  }

  .search-actions {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: var(--sp-3);
  }

  .search-actions .primary {
    width: auto;
  }

  .btn-kbd {
    display: inline-block;
  }

  .how-it-works {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--sp-5);
  }

  .results-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--sp-4);
  }

  .clear-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  #clearBtn {
    width: auto;
    padding: 0 var(--sp-4);
  }

  body:has(.results:not([hidden]) #downloadAllBtn:not(:disabled))::before {
    display: none;
  }

  #downloadAllBtn {
    position: static;
    min-height: var(--touch);
    font-size: var(--fs-sm);
    box-shadow: none;
  }

  body:has(.bulk-bar:not([hidden])) #downloadAllBtn,
  body:has(.task-panel:not([hidden])) #downloadAllBtn {
    display: inline-flex;
  }

  .filter-toggle-btn > span:not(.filter-count) {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  #densityToggle {
    display: inline-flex;
  }

  #sortSelect {
    min-width: 176px;
  }

  .search-kbd {
    display: block;
  }

  .chip-row {
    margin: 0;
  }

  .status-chips {
    flex-wrap: wrap;
    overflow: visible;
    padding: 2px 0;
  }

  .chip {
    min-height: 36px;
  }

  .toolbar-fields {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }

  /* Acciones de tarjeta en una sola linea */
  .card-actions {
    display: flex;
    flex-wrap: wrap;
  }

  .card-actions .primary,
  .card-actions .secondary,
  .card-actions .text-link {
    width: auto;
    min-height: 38px;
    padding: 0 var(--sp-3);
  }

  .card-actions .spacer {
    display: block;
    flex: 1;
  }

  .more-btn {
    width: 38px !important;
  }

  .manual-note .note-actions {
    display: flex;
  }

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

  .pending-banner {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4);
  }

  .pending-icon {
    display: block;
  }

  .pending-text strong {
    font-size: var(--fs-base);
  }

  .pending-actions {
    display: flex;
  }

  #pendingTxtBtn {
    display: inline-flex;
  }

  .manual-note .note-actions .primary {
    grid-column: auto;
  }

  /* Menu como popover junto a su boton */
  .action-menu {
    min-width: 230px;
    max-width: 300px;
    max-height: min(420px, calc(100dvh - 24px));
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--sp-1);
    transform-origin: var(--menu-origin, top right);
    animation: popoverIn 150ms var(--ease-out);
  }

  body:has(.action-menu:not([hidden]))::after {
    display: none;
  }

  .menu-item {
    min-height: 38px;
    font-size: var(--fs-sm);
  }

  /* Biblioteca como panel lateral */
  .drawer {
    top: 0;
    left: auto;
    width: 440px;
    padding-top: env(safe-area-inset-top);
    border-left: 1px solid var(--line);
    border-radius: 0;
    transform: translateX(0);
  }

  .drawer.is-entering,
  .drawer.is-leaving {
    transform: translateX(100%);
  }

  .drawer-foot {
    display: flex;
  }

  /* Seleccion como barra flotante */
  .bulk-bar {
    left: 50%;
    right: auto;
    bottom: calc(var(--sp-5) + env(safe-area-inset-bottom));
    width: min(680px, calc(100% - 32px));
    border-radius: var(--r-md);
    padding: 0;
    transform: translateX(-50%);
    animation: fadeIn var(--d-base) var(--ease-out);
  }

  .bulk-count {
    font-size: var(--fs-sm);
  }

  .bulk-count strong {
    display: inline;
    font-size: var(--fs-base);
  }

  .bulk-actions {
    display: flex;
    justify-content: flex-end;
  }

  .bulk-bar .secondary,
  .bulk-bar .primary {
    width: auto;
    padding: 0 var(--sp-3);
  }

  .bulk-bar .secondary span,
  .bulk-bar .primary span {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  .task-panel {
    right: auto;
    left: max(var(--sp-5), env(safe-area-inset-left));
    bottom: calc(var(--sp-5) + env(safe-area-inset-bottom));
    width: 400px;
  }

  body:has(.bulk-bar:not([hidden])) .task-panel {
    bottom: calc(88px + env(safe-area-inset-bottom));
  }

  .toast-stack {
    top: auto;
    left: auto;
    right: max(var(--sp-5), env(safe-area-inset-right));
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: 380px;
  }

  @starting-style {
    .toast {
      transform: translateX(14px);
    }
  }

  .toast.is-leaving {
    transform: translateX(14px);
  }

  /* Dialogo centrado */
  .modal-backdrop {
    place-items: center;
    padding: var(--sp-5);
  }

  .modal {
    width: min(480px, 100%);
    max-height: calc(100dvh - 48px);
    border-radius: var(--r-lg);
    padding: var(--sp-6);
    animation: modalIn 200ms var(--ease-out);
  }

  .modal-wide {
    width: min(760px, 100%);
  }

  .modal-actions {
    flex-direction: row;
    justify-content: flex-end;
  }

  .modal-actions > button {
    width: auto;
  }

  .assist-item {
    flex-wrap: nowrap;
  }

  .assist-body {
    flex: 1 1 auto;
  }

  .assist-actions {
    flex: 0 0 auto;
    padding-left: 0;
  }

  .assist-actions .secondary {
    flex: 0 0 auto;
  }

  .review-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    align-items: center;
  }

  .review-why {
    grid-column: 2;
  }

  .assist-foot {
    display: flex;
    align-items: center;
  }

  .assist-progress {
    margin-right: auto;
    text-align: left;
  }

  .scroll-top-btn {
    bottom: calc(var(--sp-5) + env(safe-area-inset-bottom));
  }

  .app-shell {
    padding-bottom: calc(var(--sp-12) + env(safe-area-inset-bottom));
  }

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

  .admin-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-4);
  }

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

  .admin-form-grid .span-2 {
    grid-column: 1 / -1;
  }

  .admin-tabs a {
    flex: 0 0 auto;
  }
}

/* ------------------------------------------------------------
   22. Escritorio (desde 1024px)
   ------------------------------------------------------------ */
@media (min-width: 1024px) {
  .start {
    grid-template-columns: minmax(0, 1fr) 300px;
    column-gap: var(--sp-8);
  }

  .start-lede {
    grid-column: 1 / -1;
  }

  .how-it-works {
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    padding-top: var(--sp-2);
  }

  .start.has-results {
    grid-template-columns: minmax(0, 1fr);
  }

  .composer-bar {
    grid-column: 1 / -1;
  }

  /* Guia: indice fijo a un lado */
  .guide-content {
    grid-template-columns: 200px minmax(0, 1fr);
    column-gap: var(--sp-10);
    align-items: start;
  }

  .guide-content > nav.guide-panel {
    position: sticky;
    top: calc(var(--bar-h) + 24px);
    grid-row: 1 / span 20;
  }

  .guide-content > .guide-panel:not(nav) {
    grid-column: 2;
  }

  .guide-toc {
    flex-direction: column;
    gap: 0;
  }
}

/* ------------------------------------------------------------
   23. Preferencias de la persona
   ------------------------------------------------------------ */
/* Pantallas tactiles mas alla del ancho: objetivos de 44px */
@media (pointer: coarse) {
  .chip {
    min-height: var(--touch);
  }

  .card-actions .primary,
  .card-actions .secondary,
  .card-actions .text-link {
    min-height: var(--touch);
  }

  .more-btn {
    width: var(--touch) !important;
  }

  .menu-item {
    min-height: 48px;
  }

  .meta-doi {
    min-height: 40px;
  }
}

@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;
  }

  .task-spinner,
  .btn-spinner {
    animation: spin 1.6s linear infinite !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --line: #8FA5BC;
    --line-subtle: #B9C9DA;
    --muted: #3F4F63;
  }

  [data-theme="dark"] {
    --line: #56698A;
    --line-subtle: #3B4E6B;
    --muted: #B9C7DA;
  }
}

/* ------------------------------------------------------------
   24. Impresion
   ------------------------------------------------------------ */
@media print {
  .topbar,
  .start,
  .toolbar,
  .chip-row,
  .toolbar-fields,
  .list-bar,
  .results-actions,
  .card-actions,
  .card-check,
  .fav-btn,
  .organizer-panel,
  .manual-note,
  .scroll-top-btn,
  .modal-backdrop,
  .bulk-bar,
  .task-panel,
  .toast-stack,
  .drawer,
  .drawer-backdrop,
  .action-menu,
  .pending-banner,
  .skip-link {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .result-card {
    break-inside: avoid;
    border: 1px solid #ccc;
    background: #fff !important;
  }
}
