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

html { font-size: 14px; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* [hidden] oculta siempre, aunque la clase del elemento fije su display (.btn, flex…). */
[hidden] { display: none !important; }

a { color: inherit; text-decoration: none; }

button { cursor: pointer; font-family: var(--font-body); }

input, select, textarea { font-family: var(--font-body); }

/* ══════════════════════════════════════════
   FOCUS VISIBLE — WCAG 2.4.7
   Outline global para navegación por teclado.
   Se aplica a todos los elementos interactivos
   que no tengan su propio :focus-visible.
══════════════════════════════════════════ */

:focus { outline: none; }

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

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

/* Inputs/selects/textareas usan box-shadow en lugar de outline */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.role-hidden { display: none !important; }

/* Tarea 9: icono calendario blanco en modo oscuro.
   Aplicamos color-scheme:dark al input (Chromium/Safari/Firefox lo soportan y
   pintan el indicador del datepicker en blanco automáticamente).
   No combinamos con filter:invert porque entonces lo volveríamos negro otra vez. */

body[data-theme="dark"] input[type="date"],
body[data-theme="dark"] input[type="month"],
body[data-theme="dark"] .month-filter,
body[data-theme="dark"] .filter-date,
body[data-theme="dark"] .form-input[type="date"],
body[data-theme="dark"] .form-input[type="month"] {
  color-scheme: dark;
}

body[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
body[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator,
body[data-theme="dark"] .month-filter::-webkit-calendar-picker-indicator,
body[data-theme="dark"] .filter-date::-webkit-calendar-picker-indicator,
body[data-theme="dark"] .form-input[type="date"]::-webkit-calendar-picker-indicator,
body[data-theme="dark"] .form-input[type="month"]::-webkit-calendar-picker-indicator {
  opacity: 1;
  cursor: pointer;
}

/* ══════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════ */

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 20px; text-align: center;
}

.empty-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--bg3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}

.empty-icon svg { width: 22px; height: 22px; color: var(--text3); }

.empty-title { font-size: 15px; font-weight: 500; margin-bottom: 6px; }

.empty-text { font-size: 13px; color: var(--text2); max-width: 280px; }

.empty-state-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ══════════════════════════════════════════
   BOOTSTRAP ERROR (login screen fallback)
══════════════════════════════════════════ */

.bootstrap-error-block {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  text-align: left;
}

.bootstrap-error-title {
  font-family: var(--font-display);
  font-size: 14px; font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.bootstrap-error-detail {
  font-size: 12px; color: var(--text2);
  line-height: 1.5;
  margin-bottom: 12px;
}
.bootstrap-error-tech {
  font-size: 11px; color: var(--text3);
}

.bootstrap-error-tech summary { cursor: pointer; padding: 4px 0; }

.bootstrap-error-tech pre {
  margin-top: 6px; padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono); font-size: 10px;
  white-space: pre-wrap; word-break: break-word;
  max-height: 140px; overflow-y: auto;
}

/* ══════════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════════ */

::-webkit-scrollbar { width: 4px; height: 4px; }

::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* Tooltip */

.tooltip-wrap { position: relative; display: inline-flex; }

.tooltip {
  position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%) translateY(-3px) scale(0.97);
  background: var(--bg4); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 11px; white-space: nowrap; pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity 140ms ease-out, transform 140ms ease-out, visibility 140ms ease-out;
  margin-top: 6px;
  transform-origin: top center;
  z-index: 10;
}

@media (hover: hover) and (pointer: fine) {
  .tooltip-wrap:hover .tooltip {
    opacity: 1; visibility: visible;
    transition-delay: 0s;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tooltip {
    transition-duration: 0.01s !important;
    transform: translateX(-50%) !important;
  }
}

/* Tooltip flotante para botones de icono (cabeceras, filtros, favoritos, etc.).
   Mismo estilo que .tooltip, pero posición fija (no lo recorta ningún contenedor
   con overflow) y colocado por JS. Se auto-aplica a botones solo-icono. */
.icon-tooltip {
  position: fixed; left: 0; top: 0; z-index: 3000; pointer-events: none;
  background: var(--bg4); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 11px; color: var(--text); white-space: nowrap;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--shadow-color) 25%, transparent);
  opacity: 0; visibility: hidden;
  transition: opacity 140ms ease-out;
}
.icon-tooltip.is-visible { opacity: 1; visibility: visible; }
@media (hover: none) { .icon-tooltip { display: none; } }
@media (prefers-reduced-motion: reduce) { .icon-tooltip { transition-duration: 0.01s; } }

/* ══════════════════════════════════════════
   RESPONSIVE ADICIONAL COMPONENTES
══════════════════════════════════════════ */

/* Tarjeta login adaptable a móvil */
@media (max-width: 480px) {
  .login-card {
    width: calc(100vw - 32px);
    padding: 32px 24px 28px;
  }
}

/* Tarjetas de costes: reducir fuente en grids de 3 columnas (≤ 900px) */
@media (max-width: 900px) {
  .coste-card .cc-value,
  .coste-card > div:nth-child(2) { font-size: 26px !important; }
}

/* Tarjetas de costes y stat en móvil (≤ 640px) */
@media (max-width: 640px) {
  /* Stat cards */
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 22px !important; }

  /* Coste cards: 2 columnas en modo móvil */
  .coste-card { padding: 10px 12px; min-height: 90px; }
  .coste-card .cc-label,
  .coste-card > div:first-child:not(.cc-value):not(.cc-sub) { font-size: 10px !important; margin-bottom: 4px !important; }
  .coste-card .cc-value,
  .coste-card > div:nth-child(2) { font-size: 20px !important; }
  .coste-card .cc-sub,
  .coste-card > div:nth-child(3) { font-size: 11px !important; }

  /* Tarjetas iniciativa: simplificar */
  .initiative-card { padding: 16px 16px 14px; }
  .initiative-card .card-obj { display: none; }
  .initiative-card .card-taxonomy { display: none; }
  .initiative-card .card-meta { gap: 4px; margin-bottom: 10px; }

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

  /* Modal: máximo alto en pantalla pequeña */
  .modal { max-height: 90vh; }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; }
}

/* Columna única para costes en pantallas muy estrechas (≤ 480px) */
@media (max-width: 480px) {
  /* Con 1 columna, el valor puede ser más grande */
  .coste-card .cc-value,
  .coste-card > div:nth-child(2) { font-size: 26px !important; }
}

/* Pantallas muy pequeñas (≤ 400px) */
@media (max-width: 400px) {
  .initiative-card .card-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .badge { font-size: 10px; padding: 2px 6px; }

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

/* Utilidad: celda de tabla con peso 500 (sustituye style="font-weight:500;" inline) */
.col-label { font-weight: 500; }

