/* =====================================================================
   🎨 CSS/UI-RESPONSIVE.CSS — Contraste (tema claro/oscuro) y diseño móvil
   =====================================================================
   Se carga DESPUÉS del <style> de index.html. No depende de que Tailwind
   genere clases concretas: los componentes nuevos (.ui-chip, .rtable…)
   definen su propio color en ambos temas.
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. FONDO: imagen optimizada (antes iba incrustada en base64, 10 MB)
   --------------------------------------------------------------------- */
#bgWallpaper picture,
#bgWallpaper img { display: block; width: 100%; height: 100%; }
#bgWallpaper img { object-fit: cover; object-position: center; }

/* ---------------------------------------------------------------------
   2. CHIPS NEUTRAS (Tipo, Diseñador, Responsable, Estado, "N Proyectos")
   --------------------------------------------------------------------- */
body .ui-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.15;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.10);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.18);
}
body .ui-chip--muted { color: #cbd5e1; }
body .ui-chip--wrap { white-space: normal; text-align: left; }

body.theme-light-white .ui-chip {
  background: #f1f5f9 !important;
  color: #1e293b !important;
  border: 1px solid #cbd5e1 !important;
}
body.theme-light-white .ui-chip--muted { color: #475569 !important; }

/* ---------------------------------------------------------------------
   3. CONTRASTE — TEMA CLARO: colores que no tenían ajuste
   --------------------------------------------------------------------- */
body.theme-light-white .text-rose-300,
body.theme-light-white .text-rose-400 { color: #be123c !important; font-weight: 700 !important; }
body.theme-light-white .text-sky-200 { color: #075985 !important; }
body.theme-light-white .text-indigo-300 { color: #3730a3 !important; }
body.theme-light-white .text-amber-200,
body.theme-light-white .text-amber-300\/80,
body.theme-light-white .text-amber-400\/90 { color: #92400e !important; }
body.theme-light-white .text-slate-500 { color: #475569 !important; }

body.theme-light-white .bg-rose-500\/10,
body.theme-light-white .bg-rose-500\/20 { background-color: #fff1f2 !important; border-color: #fecdd3 !important; }
body.theme-light-white .bg-sky-500\/10 { background-color: #f0f9ff !important; border-color: #bae6fd !important; }
body.theme-light-white .bg-purple-500\/10 { background-color: #faf5ff !important; border-color: #e9d5ff !important; }

body.theme-light-white input::placeholder,
body.theme-light-white textarea::placeholder { color: #64748b !important; opacity: 1; }

/* Modales en tema claro: panel blanco sólido (antes 85 % blanco sobre el velo oscuro = gris) */
body.theme-light-white .fixed.inset-0.z-50 > .glass-panel,
body.theme-light-white .fixed.inset-0.z-50 > .glass-panel:hover {
  background: #ffffff !important;
  border-color: #e2e8f0 !important;
}
body.theme-light-white #modalRightPanel { background: #f8fafc !important; }

/* Pie del menú lateral (tenía bg-black/40 también en tema claro) */
body.theme-light-white #sidebarDrawer .bg-black\/40 {
  background: #f8fafc !important;
  border-top-color: #e2e8f0 !important;
}

/* ---------------------------------------------------------------------
   4. CONTRASTE — TEMA OSCURO: grises demasiado tenues sobre fondo oscuro
   --------------------------------------------------------------------- */
body:not(.theme-light-white) .text-slate-500 { color: #94a3b8; }
body:not(.theme-light-white) input::placeholder,
body:not(.theme-light-white) textarea::placeholder { color: #94a3b8; opacity: 1; }

/* ---------------------------------------------------------------------
   5. ENCABEZADO DEL DETALLE DE PROYECTO: tipo como etiqueta, no círculo
   --------------------------------------------------------------------- */
#modalProjectType.modal-type-chip {
  width: auto;
  height: auto;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------
   6. TARJETAS KPI: carrusel horizontal en móvil
   --------------------------------------------------------------------- */
@media (max-width: 639px) {
  .kpi-grid {
    display: flex !important;
    gap: 12px !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 2px 12px 10px;
    scrollbar-width: none;
  }
  .kpi-grid::-webkit-scrollbar { display: none; }
  .kpi-grid { align-items: flex-start; }
  .kpi-grid > * {
    flex: 0 0 86%;
    height: auto !important;
    scroll-snap-align: center;
  }
}

/* ---------------------------------------------------------------------
   7. FILTROS PLEGABLES EN MÓVIL
   --------------------------------------------------------------------- */
.filters-toggle { display: none; }
@media (max-width: 639px) {
  .filters-toggle { display: flex; }
  .filters-panel:not(.is-open) { display: none !important; }
  .filters-panel { grid-template-columns: 1fr !important; gap: 8px !important; }
  .flex.flex-wrap > .filter-box { flex: 1 1 100% !important; }
  .filters-panel .filter-box { height: auto; min-height: 50px; }
  .filters-panel .filter-box select { font-size: 12px; text-overflow: ellipsis; }
}
.filters-toggle .filters-chevron { transition: transform .2s ease; }
.filters-toggle[aria-expanded="true"] .filters-chevron { transform: rotate(180deg); }

/* ---------------------------------------------------------------------
   8. TABLAS → TARJETAS EN MÓVIL  (tablas con clase .rtable)
      Las etiquetas (data-label) las pone js/ui-responsive.js desde el <thead>.
   --------------------------------------------------------------------- */
@media (max-width: 767px) {
  table.rtable { min-width: 0 !important; border-collapse: separate !important; }
  table.rtable thead { display: none; }
  table.rtable,
  table.rtable tbody { display: block; width: 100%; }
  table.rtable tbody { border: 0 !important; }

  table.rtable tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px 14px;
    margin: 0 0 12px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.04);
  }
  body.theme-light-white table.rtable tbody tr {
    background: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  }
  table.rtable tbody tr:hover,
  body.theme-light-white table.rtable tbody tr:hover { backdrop-filter: none; }

  table.rtable tbody td {
    display: flex !important;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 3px;
    width: auto;
    padding: 0 !important;
    text-align: left !important;
    white-space: normal !important;
    border: 0 !important;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  table.rtable tbody td > div { justify-content: flex-start; }
  table.rtable .ui-chip { white-space: normal; }

  table.rtable tbody td::before {
    content: attr(data-label);
    text-align: left;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: #94a3b8;
  }
  body.theme-light-white table.rtable tbody td::before { color: #64748b; }

  /* Celda principal (nombre de la tarea): arriba, grande y sin etiqueta */
  table.rtable tbody td[data-cell-title] {
    order: -2;
    grid-column: 1 / -1;
    display: block !important;
    font-size: 14px;
    padding-bottom: 8px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10) !important;
  }
  body.theme-light-white table.rtable tbody td[data-cell-title] { border-bottom-color: #f1f5f9 !important; }
  table.rtable tbody td[data-cell-wide] { grid-column: 1 / -1; }
  table.rtable tbody td[data-cell-title]::before { display: none; }

  /* Acciones: al final, ancho completo */
  table.rtable tbody td[data-cell-actions] {
    order: 10;
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: flex-end;
    padding-top: 10px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.10) !important;
  }
  body.theme-light-white table.rtable tbody td[data-cell-actions] { border-top-color: #f1f5f9 !important; }
  table.rtable tbody td[data-cell-actions]::before { display: none; }
  table.rtable tbody td[data-cell-actions] > * { justify-content: flex-end; flex-wrap: wrap; }
  table.rtable tbody td[data-cell-actions] select { min-height: 40px; }

  /* Celdas vacías o filas de mensaje (colspan) */
  table.rtable tbody td[data-cell-empty] { display: none !important; }
  table.rtable tbody td[data-cell-full] { display: block !important; grid-column: 1 / -1; text-align: center !important; }
  table.rtable tbody td[data-cell-full]::before { display: none; }
  table.rtable tbody tr:has(> td[data-cell-full]) { background: transparent; border-style: dashed; }

  /* Subtareas desplegadas debajo de su tarea madre */
  table.rtable tbody tr.bg-white\/5 {
    margin-left: 14px;
    border-left: 3px solid rgba(245, 158, 11, 0.7);
  }

  /* Botones táctiles */
  table.rtable button,
  table.rtable select { min-height: 36px; }

  /* Columnas de historial ocultas por el usuario siguen ocultas */
  table.rtable tbody td.hidden { display: none !important; }
}

/* ---------------------------------------------------------------------
   9. ENCABEZADO EN MÓVIL
   --------------------------------------------------------------------- */
@media (max-width: 639px) {
  header .header-title { min-width: 0; }
  header .header-title h1 { font-size: 15px; }
  #headerRoleBadge { display: none !important; }
  #btnNewProject { padding: 8px 10px; }
}

/* ---------------------------------------------------------------------
   10. MODALES EN MÓVIL: alto completo con scroll interno
   --------------------------------------------------------------------- */
@media (max-width: 639px) {
  .fixed.inset-0.z-50:not(#sidebarOverlay) {
    padding: 8px !important;
    align-items: flex-end !important;
  }
  .fixed.inset-0.z-50 > .glass-panel {
    max-height: calc(100dvh - 16px) !important;
    overflow-y: auto;
    padding: 16px !important;
    border-radius: 20px !important;
  }
  /* El detalle de proyecto ya tiene su propio scroll interno */
  #dualProjectModal > .glass-panel { overflow: hidden; display: flex; }
  #dualProjectModal #activityFeedContainer { max-height: 220px; min-height: 120px; }
  #dualProjectModal #modalRightPanel { min-height: 0; }
  /* Grillas de 2 columnas fijas dentro de modales → 1 columna */
  .fixed.inset-0.z-50 .grid.grid-cols-2 { grid-template-columns: 1fr; }
  /* Pie de modales: botones apilados si no entran */
  .fixed.inset-0.z-50 .glass-panel > .flex.items-center.justify-between.pt-3 { flex-wrap: wrap; }
}

/* ---------------------------------------------------------------------
   11. MENÚ LATERAL: alto real del dispositivo (barra del navegador móvil)
   --------------------------------------------------------------------- */
#sidebarDrawer { height: 100vh; height: 100dvh; }

/* ---------------------------------------------------------------------
   12. AJUSTES GENERALES EN MÓVIL
   --------------------------------------------------------------------- */
@media (max-width: 639px) {
  .glass-panel { border-radius: 18px; }
  /* Paginación: botones táctiles */
  #tablePaginationContainer button,
  #tablePaginationContainer select { min-height: 36px; }
  /* Evita el zoom automático de iOS al enfocar campos (requiere 16px) */
  input[type="text"], input[type="search"], input[type="email"], input[type="password"],
  input[type="url"], input[type="number"], input[type="date"], input[type="datetime-local"],
  select, textarea { font-size: 16px !important; }
}

/* ---------------------------------------------------------------------
   13. FILTRO "RANGO DE FECHAS" del listado
   --------------------------------------------------------------------- */
.date-range-box input[type="date"] { cursor: pointer; }
body:not(.theme-light-white) .date-range-box input[type="date"] { color-scheme: dark; }
body.theme-light-white .date-range-box input[type="date"] { color-scheme: light; }
.date-range-box label span { opacity: .85; }
.date-range-box { position: relative; }
.date-range-box input[type="date"] { min-width: 0; }
@media (max-width: 639px) {
  /* En móvil las dos fechas van una debajo de la otra; la ✕ queda arriba a la derecha */
  .date-range-box { height: auto !important; padding-top: 8px; padding-bottom: 8px; }
  .date-range-box > .flex { flex-wrap: wrap; row-gap: 6px; }
  .date-range-box > .flex > span { display: none; }
  .date-range-box input[type="date"] { flex: 1 1 100% !important; }
  .date-range-box button { position: absolute; top: 6px; right: 8px; min-height: 28px; }
}

/* ---------------------------------------------------------------------
   14. AVISO "ENVIADO HACE MÁS DE 72 H HÁBILES" y CAMPANA DE AVISOS
   --------------------------------------------------------------------- */
body .sent-alert-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 9999px;
  font-size: 10px; font-weight: 800; white-space: nowrap;
  background: rgba(244, 63, 94, 0.16); color: #fda4af; border: 1px solid rgba(244, 63, 94, 0.45);
}
body.theme-light-white .sent-alert-chip { background: #fff1f2 !important; color: #be123c !important; border-color: #fecdd3 !important; }

#btnAlerts { position: relative; }
#alertsCount {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9999px; background: #e11d48; color: #fff; font-size: 10px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
  border: 2px solid #0f172a;
}
body.theme-light-white #alertsCount { border-color: #ffffff; }
#alertsPanel {
  position: absolute; right: 0; top: calc(100% + 10px); width: min(420px, calc(100vw - 24px));
  max-height: min(70vh, 520px); overflow-y: auto; z-index: 60;
  background: #0f172a; color: #e2e8f0; border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
}
body.theme-light-white #alertsPanel { background: #ffffff; color: #0f172a; border-color: #e2e8f0; box-shadow: 0 20px 40px -12px rgba(15, 23, 42, 0.2); }
#alertsPanel .alert-item { display: block; width: 100%; text-align: left; padding: 10px 14px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
body.theme-light-white #alertsPanel .alert-item { border-top-color: #f1f5f9; }
#alertsPanel .alert-item:hover { background: rgba(255, 255, 255, 0.06); }
body.theme-light-white #alertsPanel .alert-item:hover { background: #f8fafc; }
#alertsPanel .alert-meta { color: #94a3b8; font-size: 11px; }
body.theme-light-white #alertsPanel .alert-meta { color: #475569; }
@media (max-width: 639px) {
  #alertsPanel { position: fixed; left: 12px; right: 12px; top: 64px; width: auto; }
}

/* Tarjeta de duración promedio por estado */
.status-duration-bar { height: 6px; border-radius: 9999px; background: linear-gradient(90deg, #f59e0b, #ea580c); }

/* ---------------------------------------------------------------------
   15. Tipo de densidad de subtareas (A / B / C) — ambos temas
   --------------------------------------------------------------------- */
body .density-chip { font-weight: 800; min-width: 1.9rem; justify-content: center; }
body .density-a { background: rgba(16, 185, 129, .16); border-color: rgba(16, 185, 129, .45); color: #6ee7b7; }
body .density-b { background: rgba(245, 158, 11, .16); border-color: rgba(245, 158, 11, .45); color: #fcd34d; }
body .density-c { background: rgba(244, 63, 94, .16); border-color: rgba(244, 63, 94, .45); color: #fda4af; }
body.theme-light-white .density-a { background: #d1fae5 !important; border-color: #6ee7b7 !important; color: #065f46 !important; }
body.theme-light-white .density-b { background: #fef3c7 !important; border-color: #fcd34d !important; color: #92400e !important; }
body.theme-light-white .density-c { background: #ffe4e6 !important; border-color: #fda4af !important; color: #9f1239 !important; }
