/* ===========================================================================
   Mamut — sistema de diseño

   Mismo lenguaje que EspacioOS: neutros derivados de Royal en vez de gris puro,
   profundidad por borde y cambio de fondo (la sombra se reserva para lo que de
   verdad flota), color reservado para estado, y movimiento que desacelera sin
   pedir atención.

   Reemplaza a Tailwind CDN. Todo lo que la app usa vive aquí.
=========================================================================== */

@font-face {
  font-family: 'Google Sans Flex';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('../fonts/GoogleSansFlex-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Google Sans Flex';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('../fonts/GoogleSansFlex-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --------------------------------------------------------------------------
   Tokens
-------------------------------------------------------------------------- */

:root {
  --royal: #003146;
  --nectar: #f3c7b1;
  /* El amarillo de Mamut queda como marca, no como color de interfaz: aparece
     en el logo y en nada más. Las acciones usan Royal, igual que EspacioOS. */
  --mamut: #ffc738;

  --bg: #ffffff;
  --bg-subtle: #f7f8f9;
  --bg-hover: #f1f3f5;
  --bg-sunken: #f2f4f6;
  --border: #e4e7ea;
  --border-strong: #cdd3d8;

  --text: #111111;
  --text-secondary: #5a6570;
  --text-tertiary: #8b959e;

  --accent: #003146;
  --accent-hover: #002536;
  --accent-subtle: #e8eef1;

  /* Estado. Apagados a propósito: el color significa estado y nada más. */
  --ok: #3f7d62;
  --ok-bg: #e9f3ef;
  --warn: #b06a3b;
  --warn-bg: #f9f2e3;
  --danger: #c0492b;
  --danger-bg: #fbeee9;
  --info: #17607d;
  --info-bg: #e6f0f4;

  --radius-control: 6px;
  --radius-card: 8px;
  --radius-modal: 12px;

  --shadow-float: 0 1px 2px rgb(0 49 70 / 0.04), 0 8px 24px rgb(0 49 70 / 0.08);

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-entrance: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 140ms;
  --dur-overlay: 180ms;
  --dur-rise: 260ms;

  --header-h: 52px;
  --measure: 68ch;

  --font-sans: 'Google Sans Flex', -apple-system, BlinkMacSystemFont, 'Inter',
    system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
}

/* --------------------------------------------------------------------------
   Base
-------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
  border-color: var(--border);
}

* {
  margin: 0;
}

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

body {
  background: var(--bg-subtle);
  color: var(--text);
  font-family: var(--font-sans);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 400;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.25;
}

h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
h4 { font-size: 13px; }

p { color: var(--text-secondary); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font: inherit; color: inherit; }

.tnum, time, .num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-control);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-subtle); color: var(--accent); }

.hidden { display: none !important; }

/* --------------------------------------------------------------------------
   Cáscara: barra superior y contenedor
-------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}
.brand-mark {
  font-size: 26px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.brand-name {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
}
.brand-sub {
  color: var(--text-tertiary);
  font-size: 11px;
  margin-top: -1px;
}

.topbar-spacer { flex: 1; }

/* Pestañas: subrayado, no pastilla de color */
.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
}
.tab {
  position: relative;
  height: 100%;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: color var(--dur) var(--ease);
}
.tab:hover { color: var(--text); }
.tab::after {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: transparent;
  transition: background var(--dur) var(--ease);
}
.tab-active { color: var(--text); font-weight: 500; }
.tab-active::after { background: var(--accent); }
.tab-inactive { color: var(--text-secondary); }

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}
.page-narrow { max-width: 780px; }

.page-head { margin-bottom: 20px; }
.page-title { font-size: 22px; }
.page-sub { color: var(--text-secondary); margin-top: 4px; }

/* --------------------------------------------------------------------------
   Superficies
-------------------------------------------------------------------------- */

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
}
.card + .card { margin-top: 14px; }
.card-flush { padding: 0; overflow: hidden; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-title { font-size: 14px; font-weight: 600; }
.card-hint { color: var(--text-tertiary); font-size: 12px; margin-top: 2px; }

.section { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 20px; }
.section:first-child { border-top: 0; margin-top: 0; padding-top: 0; }

/* --------------------------------------------------------------------------
   Controles
-------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:active { background: var(--bg-sunken); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg); border-color: var(--border); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-hover); }
.btn-primary:disabled:hover { background: var(--accent); border-color: var(--accent); }

.btn-quiet { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn-quiet:hover { background: var(--bg-hover); border-color: transparent; color: var(--text); }

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

/* Espera dentro del botón. Va en ::before para que app.js pueda seguir
   escribiendo textContent sin borrar el indicador. */
.btn.is-loading { pointer-events: none; }
.btn.is-loading::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  opacity: 0.85;
  animation: spin 650ms linear infinite;
  flex-shrink: 0;
}

.btn-lg { height: 38px; padding: 0 18px; font-size: 13px; }
.btn-sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-icon { width: 32px; padding: 0; }

/* Campos */
.field { display: block; }
.label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.label-hint { color: var(--text-tertiary); font-weight: 400; }

.input,
.textarea,
.select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder,
.textarea::placeholder { color: var(--text-tertiary); }
.input:hover,
.textarea:hover,
.select:hover { border-color: var(--border-strong); }
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
.input-mono { font-family: var(--font-mono); font-size: 12px; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%238b959e' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 28px;
}

/* Llaves de API en la barra superior */
.keyfield {
  display: flex;
  align-items: center;
  gap: 6px;
}
.keyfield .label { margin: 0; white-space: nowrap; font-size: 12px; }
.keyfield .input { width: 168px; height: 28px; padding: 0 9px; font-size: 12px; }

/* --------------------------------------------------------------------------
   Selector de rango de fechas
-------------------------------------------------------------------------- */

.daterange { position: relative; }

.daterange-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.daterange-trigger:hover { border-color: var(--border-strong); background: var(--bg-subtle); }
.daterange-trigger[aria-expanded='true'] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.daterange-meta { color: var(--text-tertiary); font-size: 12px; }

.daterange-pop {
  position: absolute;
  z-index: 50;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-float);
  padding: 12px;
  animation: overlay-in var(--dur-overlay) var(--ease);
}

.daterange-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-bottom: 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.daterange-nav { display: flex; align-items: center; margin-bottom: 2px; }

.daterange-cals { display: flex; gap: 20px; }

.cal { width: 208px; }
.cal-head {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-transform: capitalize;
  margin-bottom: 8px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-dow span {
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding-bottom: 4px;
}

.cal-days { row-gap: 1px; }
.cal-pad { height: 28px; }

.cal-day {
  height: 28px;
  border: 0;
  background: transparent;
  border-radius: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  cursor: pointer;
  position: relative;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.cal-day:hover:not(:disabled) { background: var(--bg-hover); }
.cal-day:disabled,
.cal-day.is-future { color: var(--text-tertiary); opacity: 0.4; cursor: default; }

/* El relleno del rango es continuo: los extremos redondean solo por fuera */
.cal-day.is-in { background: var(--accent-subtle); }
.cal-day.is-start,
.cal-day.is-end {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.cal-day.is-start { border-radius: var(--radius-control) 0 0 var(--radius-control); }
.cal-day.is-end { border-radius: 0 var(--radius-control) var(--radius-control) 0; }
.cal-day.is-start.is-end { border-radius: var(--radius-control); }

.cal-day.is-today:not(.is-start):not(.is-end)::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 3px;
  transform: translateX(-50%);
  width: 3px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.daterange-hint { margin-top: 10px; text-align: center; }

@media (max-width: 700px) {
  .daterange-cals { flex-direction: column; gap: 12px; }
  .cal { width: 100%; }
  .daterange-pop { left: 0; right: 0; }
}

/* Selector de dos vías */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-sunken);
  border-radius: var(--radius-control);
  margin-bottom: 16px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 0 14px;
  height: 30px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button.is-active {
  background: var(--bg);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgb(0 49 70 / 0.06);
}

/* Fila mientras se lee el artículo elegido */
.news-item.is-loading-row { opacity: 0.6; pointer-events: none; }
/* En el análisis se elige una sola nota, así que la acción está siempre visible */
#apNewsList .news-flags { opacity: 1; }

/* Campo de título: es lo primero que se escribe, así que pesa más */
.input-lg { height: 40px; font-size: 15px; font-weight: 500; padding: 0 12px; }

/* Tarjeta plegable */
.card-details {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}
.card-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 20px;
  cursor: pointer;
  list-style: none;
  border-radius: var(--radius-card);
}
.card-summary::-webkit-details-marker { display: none; }
.card-summary::after {
  content: '';
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--text-tertiary);
  border-bottom: 1.5px solid var(--text-tertiary);
  transform: rotate(45deg);
  margin-left: auto;
  transition: transform var(--dur) var(--ease);
}
.card-details[open] .card-summary::after { transform: rotate(-135deg); }
.card-summary:hover { background: var(--bg-subtle); }
.card-details-body { padding: 0 20px 20px; }

/* Lista de comprobación antes de generar */
.checklist { list-style: none; padding: 0; margin: 10px 0 0; }
.checklist li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
}
.checklist-mark {
  width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 10px;
  flex-shrink: 0;
}
.checklist li.is-ok { color: var(--text); }
.checklist li.is-ok .checklist-mark { background: var(--ok-bg); color: var(--ok); }
.checklist li.is-pend .checklist-mark { color: var(--text-tertiary); }
.checklist li.is-opt { color: var(--text-tertiary); }

/* Panel de llaves: se escriben una vez, así que van plegadas */
.keys { position: relative; flex-shrink: 0; }
.keys > summary { list-style: none; cursor: pointer; }
.keys > summary::-webkit-details-marker { display: none; }
.keys[open] > summary { background: var(--bg-hover); color: var(--text); }
.keys-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 320px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
  padding: 14px;
  z-index: 40;
  animation: overlay-in var(--dur-overlay) var(--ease);
}
.keys-panel .keyfield + .keyfield { margin-top: 9px; }
.keys-panel .keyfield .label { width: 48px; }
.keys-panel .keyfield .input { flex: 1; width: auto; }
.keys-panel p { margin-top: 10px; }

/* Casillas y radios */
input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}
input[type='checkbox']:disabled,
input[type='radio']:disabled { cursor: not-allowed; opacity: 0.45; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
}
.check:hover { color: var(--text); }

/* --------------------------------------------------------------------------
   Etiquetas y avisos
-------------------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.chip-accent { background: var(--accent-subtle); border-color: transparent; color: var(--accent); }
.chip-ok { background: var(--ok-bg); border-color: transparent; color: var(--ok); }
.chip-warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.chip-danger { background: var(--danger-bg); border-color: transparent; color: var(--danger); }

.dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; flex-shrink: 0; }

.note {
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--bg-subtle);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.note-ok { background: var(--ok-bg); border-color: transparent; color: var(--ok); }
.note-warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.note-danger { background: var(--danger-bg); border-color: transparent; color: var(--danger); }
.note ul { margin: 6px 0 0; padding-left: 16px; }
.note li + li { margin-top: 3px; }

/* --------------------------------------------------------------------------
   Pasos
-------------------------------------------------------------------------- */

.steps {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  font-size: 12px;
  color: var(--text-tertiary);
}
.step {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.step-num {
  width: 19px;
  height: 19px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}
.step-current .step-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.step-current { color: var(--text); font-weight: 500; }
.step-done .step-num { background: var(--accent-subtle); border-color: transparent; color: var(--accent); }
.step-done { color: var(--text-secondary); }
.step-line { flex: 1; height: 1px; background: var(--border); max-width: 44px; }

/* Barra de avance del flujo de contenido */
.progress-track {
  height: 3px;
  background: var(--bg-sunken);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 400ms var(--ease);
}

/* --------------------------------------------------------------------------
   Tarjetas seleccionables (formatos de contenido, categorías)
-------------------------------------------------------------------------- */

.pick {
  position: relative;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 13px 14px;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.pick:hover { border-color: var(--border-strong); background: var(--bg-subtle); }
.pick-title { font-weight: 500; font-size: 13px; color: var(--text); }
.pick-sub { color: var(--text-tertiary); font-size: 12px; margin-top: 2px; }

/* selected / selected-cat las escribe app.js: no cambiar los nombres */
.pick.selected,
.pick.selected-cat {
  border-color: var(--accent);
  background: var(--accent-subtle);
}
.pick.selected .pick-title,
.pick.selected-cat .pick-title { color: var(--accent); }

.checkmark {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 17px;
  height: 17px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 10px;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Lista de noticias
-------------------------------------------------------------------------- */

.category-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 22px 0 8px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.category-header:first-child { margin-top: 0; }
.category-header h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Dos columnas: la lista a la izquierda, lo elegido siempre a la vista */
.picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 268px;
  gap: 16px;
  align-items: start;
}
.picker-main { min-width: 0; }

/* Sin overflow: hidden. Con él, la tarjeta se vuelve el contenedor de scroll
   del sticky y la barra de filtros se despega 52px hacia abajo. Las esquinas
   se redondean en los hijos. */
.picker-main .card { overflow: visible; }

.picker-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  padding: 9px 12px;
}
.picker-main .news-item:last-child { border-radius: 0 0 var(--radius-card) var(--radius-card); }
.picker-filters { display: flex; flex-wrap: wrap; gap: 4px; }

.filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.filter:hover { background: var(--bg-hover); color: var(--text); }
.filter-n { color: var(--text-tertiary); font-size: 11px; }
.filter.is-active { background: var(--accent); color: #fff; }
.filter.is-active .filter-n { color: rgb(255 255 255 / 0.7); }

/* Encabezado de grupo, discreto y pegajoso */
.news-group {
  position: sticky;
  top: calc(var(--header-h) + 44px);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Fila densa: una línea de título y una de metadatos, nada más */
.news-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg);
  transition: background var(--dur) var(--ease);
}
.news-item:last-child { border-bottom: 0; }
.news-item:hover { background: var(--bg-subtle); }
.news-item.selected { background: var(--accent-subtle); }
.news-item.selected .news-title { color: var(--accent); }
.news-item.disabled-item { opacity: 0.5; }
.news-item.is-flash { animation: flash 900ms var(--ease); }
@keyframes flash {
  0%, 100% { background: var(--accent-subtle); }
  30% { background: var(--nectar); }
}

.news-item .news-select-cb { margin-top: 2px; flex-shrink: 0; }
.news-body { flex: 1; min-width: 0; }

.news-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
}
.news-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-tertiary);
}

/* Los marcadores solo aparecen donde hacen falta: al pasar el ratón o en las
   filas ya elegidas. Antes había 80 controles a la vista para marcar 4. */
.news-flags {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.news-item:hover .news-flags,
.news-item.selected .news-flags,
.news-flags:focus-within { opacity: 1; }

.flag {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-control);
  cursor: pointer;
  position: relative;
  filter: grayscale(1);
  opacity: 0.55;
  transition: background var(--dur) var(--ease), filter var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}
.flag:hover { background: var(--bg-hover); filter: grayscale(0); opacity: 1; }
.flag input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.flag input:checked ~ span { filter: none; }
.flag:has(input:checked) {
  background: var(--bg);
  border: 1px solid var(--accent);
  filter: grayscale(0);
  opacity: 1;
}

.news-open {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-control);
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 13px;
}
.news-open:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }

/* Panel espejo */
.picker-rail { position: sticky; top: calc(var(--header-h) + 16px); }
.rail { padding: 14px; }
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rail-list { margin-top: 10px; display: flex; flex-direction: column; gap: 1px; max-height: 46vh; overflow-y: auto; }

.rail-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: var(--radius-control);
  padding: 6px 7px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.35;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.rail-item:hover { background: var(--bg-hover); color: var(--text); }
.rail-item.is-main { color: var(--text); font-weight: 500; }
.rail-mark { width: 13px; flex-shrink: 0; font-size: 11px; }
.rail-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Ajustes de la edición, plegados */
.ajustes { position: relative; }
.ajustes > summary { list-style: none; cursor: pointer; }
.ajustes > summary::-webkit-details-marker { display: none; }
.ajustes-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 340px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
  padding: 14px;
  z-index: 40;
  animation: overlay-in var(--dur-overlay) var(--ease);
}

@media (max-width: 980px) {
  .picker { grid-template-columns: 1fr; }
  .picker-rail { position: static; }
  .rail-list { max-height: none; }
  .news-flags { opacity: 1; }
}

/* --------------------------------------------------------------------------
   Resultados
-------------------------------------------------------------------------- */

.output {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 380px;
  overflow-y: auto;
}
.output-mono { font-family: var(--font-mono); font-size: 12px; line-height: 1.55; }

/* Salida editable: se comporta como un campo sin dejar de leerse como texto */
.output.is-editable {
  cursor: text;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    background var(--dur) var(--ease);
}
.output.is-editable:hover { border-color: var(--border-strong); }
.output.is-editable:focus {
  outline: none;
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* Puntuación de relevancia: dato de apoyo, no protagonista */
.news-score {
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  font-size: 11px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}
.news-item.selected .news-score { background: var(--bg); }
.news-score.is-top { color: var(--accent); border-color: var(--accent-subtle); background: var(--accent-subtle); }

.thumb-preview {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  display: block;
}

/* --------------------------------------------------------------------------
   Carga
-------------------------------------------------------------------------- */

.loading { text-align: center; padding: 40px 20px; }
.spinner {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { margin-top: 14px; font-weight: 500; font-size: 13px; color: var(--text); }
.loading-sub { margin-top: 3px; font-size: 12px; color: var(--text-tertiary); }

/* --------------------------------------------------------------------------
   Modales
-------------------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgb(17 17 17 / 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in var(--dur-overlay) var(--ease);
}
.modal {
  background: var(--bg);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-float);
  width: 100%;
  max-width: 620px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  animation: overlay-in var(--dur-overlay) var(--ease);
}
.modal-wide { max-width: 820px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   Sugerencias
-------------------------------------------------------------------------- */

.suggestion {
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.suggestion + .suggestion { margin-top: 6px; }
.suggestion:hover { border-color: var(--border-strong); background: var(--bg-subtle); }
.suggestion.selected { border-color: var(--accent); background: var(--accent-subtle); color: var(--accent); }

/* --------------------------------------------------------------------------
   Utilidades de composición
-------------------------------------------------------------------------- */

.stack > * + * { margin-top: 12px; }
.stack-sm > * + * { margin-top: 7px; }
.stack-lg > * + * { margin-top: 20px; }

.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-end { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.row-wrap { flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

.muted { color: var(--text-secondary); }
.dim { color: var(--text-tertiary); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.strong { font-weight: 600; color: var(--text); }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.measure { max-width: var(--measure); }

.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-tertiary);
  font-size: 13px;
}

/* --------------------------------------------------------------------------
   Movimiento
-------------------------------------------------------------------------- */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlay-in {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-rise { animation: rise-in var(--dur-rise) var(--ease-entrance) both; }
.stagger > * {
  animation: rise-in var(--dur-rise) var(--ease-entrance) both;
  animation-delay: calc(min(var(--i, 0), 10) * 22ms);
}

@media (max-width: 860px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .keyfield .input { width: 128px; }
  .page { padding: 20px 14px 56px; }
}

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