/* ============================================================
   MODUGAL - espacios renovados
   Tema Light Mode corporativo (Stripe / Apple) · Corporate Clean
   ------------------------------------------------------------
   Paleta:
     --bg        #f8fafc  → slate-50  (fondo principal)
     --surface   #ffffff  → tarjetas
     --border    #e2e8f0  → slate-200
     --text      #0f172a  → slate-900
     --muted     #64748b  → slate-500
     --brand     #dc2626  → red-600 (marca)
     --success   #059669  → emerald-600 (éxitos/completados)
     --warning   #d97706  → amber-600 (alertas)
     --danger    #dc2626  → red-600 (alertas/urgencia)
   ============================================================ */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #dc2626;
  --brand-dark: #b91c1c;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

/* Utilidad de ocultamiento (vistas / subpestañas / modales) */
.is-hidden { display: none !important; }

/* Scrollbar horizontal fina para tabs / kanban */
.scrollbar-hide { -ms-overflow-style: none; scrollbar-width: none; }
.scrollbar-hide::-webkit-scrollbar { display: none; }

/* ============================================================
   STEPPER DE 6 FASES (PRODUCTION_PHASES)
   ============================================================ */
.stepper { display: flex; width: 100%; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; position: relative; }
.step::before { content: ''; position: absolute; top: 13px; left: -50%; width: 100%; height: 3px; background: var(--border); }
.step:first-child::before { display: none; }
.step.done::before { background: var(--success); }
.step .dot {
  width: 27px; height: 27px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border);
  z-index: 1; display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--muted); font-weight: 700;
}
.step.done .dot { background: var(--success); border-color: var(--success); color: #fff; }
.step.current .dot { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.15); }
.step.blocked .dot { background: var(--danger); border-color: var(--danger); color: #fff; box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.18); }
.step .label { font-size: 10px; margin-top: 6px; color: var(--muted); font-weight: 600; text-align: center; }
.step.done .label { color: var(--success); }
.step.current .label { color: var(--brand); font-weight: 800; }
.step.blocked .label { color: var(--danger); font-weight: 800; }
.step.todo .label { color: var(--muted); }

/* ============================================================
   TARJETAS KPI
   ============================================================ */
.kpi-card.kpi-alert { border-color: #fecaca; background: #fef2f2; }
.kpi-card.kpi-success { border-color: #a7f3d0; background: #ecfdf5; }
.kpi-card { border-radius: var(--radius); }
.kpi-value { font-size: 2rem; font-weight: 800; color: var(--text); line-height: 1.1; }
.kpi-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* ============================================================
   TARJETA DE PROYECTO (TABLERO PRODUCCIÓN)
   ============================================================ */
.proyecto-card { border-radius: var(--radius-lg); }
.render-hd { height: 120px; border-radius: var(--radius); background: linear-gradient(135deg, #334155, #0f172a); position: relative; overflow: hidden; }
.render-hd::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 30% 20%, rgba(220,38,38,.25), transparent 60%); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; padding: 3px 8px; border-radius: 999px; }
.badge-en_proceso { background: #fef2f2; color: var(--brand); border: 1px solid #fecaca; }
.badge-detencion { background: #fffbeb; color: var(--warning); border: 1px solid #fde68a; }
.badge-completado { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }

.alerta { border-radius: var(--radius); padding: 10px 12px; font-size: 12px; font-weight: 600; }
.alerta-material { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alerta-bloqueo { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* ============================================================
   KANBAN COMERCIAL
   ============================================================ */
.kanban-board { display: flex; gap: 0.75rem; align-items: flex-start; }
.kanban-col { flex: 0 0 300px; width: 300px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0.6rem; }
.kanban-col-titulo { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0 0.25rem 0.5rem; display:flex; justify-content: space-between; }
.kanban-card-comercial { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand); border-radius: var(--radius); padding: 0.65rem; box-shadow: var(--shadow-sm); margin-bottom: 0.6rem; }

/* ============================================================
   CHAT IA / WHATSAPP
   ============================================================ */
.chat-widget { position: fixed; right: 0; bottom: 0; z-index: 90; display: flex; flex-direction: column; align-items: flex-end; }
.chat-panel { position: fixed; right: 1rem; bottom: 8.5rem; width: min(92vw, 380px); height: min(68vh, 540px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); display: none; flex-direction: column; overflow: hidden; }
.chat-panel.open { display: flex; }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 0.8rem 0.9rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.chat-header-info { display: flex; align-items: center; gap: 0.6rem; }
.chat-avatar { width: 38px; height: 38px; border-radius: 12px; background: #fef2f2; color: var(--brand); display: flex; align-items: center; justify-content: center; font-size: 1.15rem; }
.chat-title { margin: 0; font-size: 0.9rem; font-weight: 800; color: var(--text); }
.chat-status { margin: 0.1rem 0 0; font-size: 0.68rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 0.35rem; }
.chat-status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); animation: sync-pulse 1.8s ease-out infinite; }
.chat-close { background: var(--surface); border: 1px solid var(--border); color: var(--muted); width: 30px; height: 30px; border-radius: 9px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.chat-close:hover { color: var(--text); }
.chat-messages { flex: 1; overflow-y: auto; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.6rem; background: var(--bg); }
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
.chat-msg { max-width: 85%; padding: 0.6rem 0.8rem; border-radius: 14px; font-size: 0.83rem; line-height: 1.45; white-space: pre-line; word-break: break-word; animation: pop-in 0.18s ease; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg--bot { align-self: flex-start; }
.chat-msg--user { align-self: flex-end; background: var(--brand); color: #fff; font-weight: 600; border-bottom-right-radius: 4px; }
.chat-quick { display: flex; gap: 0.45rem; padding: 0.6rem 0.75rem; overflow-x: auto; border-top: 1px solid var(--border); background: var(--surface); scrollbar-width: none; }
.chat-quick::-webkit-scrollbar { display: none; }
.chat-chip { flex: 0 0 auto; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: 0.74rem; font-weight: 700; padding: 0.45rem 0.75rem; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.chat-chip:hover { color: var(--brand); border-color: var(--brand); }
.chat-input-row { display: flex; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid var(--border); background: var(--surface); }
.chat-input-row input { flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 12px; padding: 0.6rem 0.8rem; font-size: 0.85rem; outline: none; }
.chat-input-row input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }
.chat-send { background: var(--brand); color: #fff; border: 0; border-radius: 12px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto; }
.chat-send:hover { background: var(--brand-dark); }
.chat-fab { position: fixed; right: 1rem; bottom: 1.25rem; z-index: 95; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 1.35rem; display: flex; align-items: center; justify-content: center; box-shadow: 0 12px 28px rgba(220, 38, 38, 0.35); cursor: pointer; }
.chat-fab-pulse { position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--brand); opacity: 0.6; animation: sync-pulse 1.8s ease-out infinite; }

/* ============================================================
   MODALES COMUNES
   ============================================================ */
.modal-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center; animation: fade-in 0.18s ease; }
.modal-overlay.desktop { align-items: center; padding: 1.25rem; }
.modal { background: var(--surface); width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 1.1rem; animation: slide-up 0.22s ease; }
.modal-overlay.desktop .modal { border-radius: var(--radius-lg); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.9rem; }
.modal-title { font-size: 1.05rem; font-weight: 800; color: var(--text); margin: 0; }
.modal-close { background: var(--bg); border: 1px solid var(--border); color: var(--muted); width: 32px; height: 32px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { color: var(--text); }

.field { margin-bottom: 0.85rem; }
.field label { display: block; font-size: 0.7rem; font-weight: 800; color: var(--muted); margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.05em; }
.field input, .field select, .field textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 0.6rem 0.7rem; font-size: 0.88rem; outline: none; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }
.field textarea { resize: vertical; min-height: 64px; }

.form-row { display: grid; grid-template-columns: 1fr; gap: 0.85rem; }
@media (min-width: 480px) { .form-row { grid-template-columns: 1fr 1fr; } }

.modal-actions { display: flex; gap: 0.6rem; margin-top: 0.4rem; }
.modal-actions .btn { flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem; border: 1px solid transparent; border-radius: 12px; font-weight: 700; font-size: 0.85rem; padding: 0.65rem 1rem; cursor: pointer; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--border); }

/* ============================================================
   ANIMACIONES
   ============================================================ */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(26px); opacity: 0.5; } to { transform: translateY(0); opacity: 1; } }
@keyframes pop-in { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes sync-pulse { 0% { transform: scale(0.6); opacity: 0.9; } 70% { transform: scale(1.3); opacity: 0; } 100% { transform: scale(1.3); opacity: 0; } }

.mg-tab { display: inline-block; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 700; font-size: 0.75rem; padding: 0.5rem 0.25rem; margin-bottom: -1px; white-space: nowrap; background: transparent; border-top: 0; border-left: 0; border-right: 0; cursor: pointer; }
.mg-tab.active { border-bottom-color: var(--brand); color: var(--brand); }

/* ============================================================
   UTILIDADES
   ============================================================ */
.tab-panel { padding-bottom: 2rem; }

.btn-dark { background: #0f172a; color: #ffffff; }
.btn-dark:hover { background: #1e293b; }

.f-chip {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; border: 1px solid transparent;
  padding: 0.375rem 0.875rem; min-height: 2rem;
  font-size: 0.75rem; line-height: 1rem; font-weight: 700; white-space: nowrap;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.f-chip:hover { background: var(--surface); color: var(--text); }
.f-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 2px 6px rgba(220, 38, 38, 0.25); }
.f-chip:focus-visible, .vista-toggle button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Indicador de sincronización (header) */
.mg-sync { display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.375rem 0.625rem; border-radius: 0.75rem; border: 1px solid; font-size: 0.7rem; font-weight: 800; white-space: nowrap; cursor: default; }
.mg-sync.hidden { display: none; }
.mg-sync--ok { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.mg-sync--trabajando { background: #f8fafc; border-color: #e2e8f0; color: #475569; }
.mg-sync--alerta { background: #fffbeb; border-color: #fde68a; color: #b45309; }
.mg-sync--error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; cursor: pointer; }
.mg-sync--error:hover { background: #fee2e2; }

/* Historial del proyecto */
.hist-item { position: relative; padding-left: 1.75rem; }
.hist-item::before { content: ''; position: absolute; left: 0.6rem; top: 1.6rem; bottom: -0.9rem; width: 2px; background: var(--border); }
.hist-item:last-child::before { display: none; }
.hist-dot { position: absolute; left: 0; top: 0.15rem; width: 1.25rem; height: 1.25rem; border-radius: 999px; display: flex; align-items: center; justify-content: center; font-size: 0.6rem; color: #fff; }

/* Selector de vista: tarjetas / lista */
.vista-toggle { display: inline-flex; padding: 0.25rem; gap: 0.25rem; background: #f1f5f9; border: 1px solid var(--border); border-radius: 0.75rem; }
.vista-toggle button { width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center; border-radius: 0.5rem; color: var(--muted); font-size: 0.8rem; background: transparent; border: 0; cursor: pointer; }
.vista-toggle button:hover { color: var(--text); }
.vista-toggle button.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
.f-subtab { padding: 0.75rem 1rem; font-size: 0.75rem; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; background: transparent; border-top: 0; border-left: 0; border-right: 0; cursor: pointer; white-space: nowrap; }
.f-subtab.active { color: var(--brand); border-bottom-color: var(--brand); background: var(--surface); }

/* ============================================================
   FICHA DE PROYECTO · COMPLETITUD Y DOCUMENTACIÓN
   ============================================================ */
.ficha-completitud { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem; }
.ficha-completitud-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.ficha-completitud-bar > div { height: 100%; background: var(--success); border-radius: 999px; transition: width .3s ease; }
.ficha-completitud-alerta { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: var(--radius); padding: 0.7rem 0.9rem; font-size: 12px; font-weight: 600; }

.dropbox-archivo-item { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.6rem 0.75rem; font-size: 0.8rem; }
.dropbox-visual { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); min-height: 240px; display: flex; align-items: center; justify-content: center; padding: 1rem; text-align: center; }
.dropbox-visual img { width: 100%; max-height: 420px; object-fit: contain; border-radius: var(--radius); }
.dropbox-visual iframe { width: 100%; height: 420px; border: 0; border-radius: var(--radius); background: #fff; }
.dropbox-visual .visor-3d { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.8rem; font-weight: 600; }

.btn-avanza { background: var(--success); color: #fff; border: 0; }
.btn-avanza:hover { background: #047857; }

/* ============================================================
   TABLA GENERAL DE PROYECTOS (VISTA EXCEL)
   ============================================================ */
.tabla-general th, .tabla-general td { padding: 0.65rem 0.85rem; }
.tabla-general tbody tr { transition: background .15s; }
.tabla-general tbody tr:hover { background: var(--bg); }

/* ============================================================
   PENDIENTES UNIFICADOS · SINCRONIZACIÓN GLOBAL
   ============================================================ */
.pendientes-box {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
}
.pendientes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.pendientes-title {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.pendientes-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.65rem;
  padding: 0 0.3rem;
}
.pendientes-add {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  font-size: 0.64rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.pendientes-add:hover { background: var(--brand-dark); }
.pendientes-list { display: flex; flex-direction: column; gap: 0.35rem; padding: 0.5rem; }
.pendientes-box--compact .pendientes-list { max-height: 9.5rem; overflow-y: auto; }
.pendiente-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.4rem 0.45rem;
  font-size: 0.72rem;
}
.pendiente-text { flex: 1; min-width: 0; color: var(--text); font-weight: 600; line-height: 1.25; }
.pendiente-tipo {
  flex: 0 0 auto;
  font-size: 0.55rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 0.18rem 0.4rem;
  border: 1px solid transparent;
}
.pendiente-tipo--material { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.pendiente-tipo--requerimiento { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.pendiente-tipo--bloqueo { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.pendiente-tipo--otro { background: var(--bg); color: var(--muted); border-color: var(--border); }
.pendiente-prio { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.pendiente-prio--alta { background: var(--danger); box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15); }
.pendiente-prio--media { background: var(--warning); }
.pendiente-prio--baja { background: var(--success); }
.pendiente-actions { display: inline-flex; align-items: center; gap: 0.15rem; flex: 0 0 auto; }
.pendiente-actions button {
  width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: 0.6rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.pendiente-actions button:hover { color: var(--brand); border-color: var(--brand); }
.pendiente-empty {
  margin: 0; padding: 0.45rem; text-align: center; color: var(--muted);
  font-size: 0.68rem; font-weight: 600;
}
.pendiente-empty i { color: var(--success); margin-right: 0.25rem; }


/* ============================================================
   CONTROLES DE FASE · TAREAS
   ============================================================ */
.fase-btn {
  width: 24px; height: 24px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 0.62rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s ease;
}
.fase-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.fase-btn--next { background: var(--success); border-color: var(--success); color: #fff; }
.fase-btn--next:hover:not(:disabled) { background: #047857; border-color: #047857; color: #fff; }
.fase-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.task-icon-btn {
  width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: 0.6rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.task-icon-btn:hover { color: var(--brand); border-color: var(--brand); }
.task-icon-btn--danger:hover { color: #fff; background: var(--danger); border-color: var(--danger); }

/* ============================================================
   KANBAN COMERCIAL · DRAG & DROP
   ============================================================ */
.comercial-card { will-change: transform; }
.comercial-detalle {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.comercial-card.dragging { opacity: 0.45; transform: rotate(1.5deg); }
[data-stage-col] { transition: border-color .15s ease, background .15s ease; }
[data-stage-col].drag-over { border-color: var(--brand); background: rgba(220, 38, 38, 0.07); }
[data-stage-col].drag-over .comercial-card { pointer-events: none; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  left: 1rem;
  bottom: 1.25rem;
  z-index: 130;
  max-width: min(92vw, 420px);
  background: #0f172a;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.35);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ============================================================
   DOCUMENTOS (v8)
   ============================================================ */
.doc-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 0.75rem; }
.doc-item--sin-archivo { border-style: dashed; border-color: #fcd34d; background: #fffbeb; }
.doc-icono { width: 1.25rem; text-align: center; color: var(--brand); font-size: 1.05rem; flex-shrink: 0; }
.doc-btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.25rem; min-width: 2rem; height: 2rem; padding: 0 0.6rem; border-radius: 0.5rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 0.68rem; font-weight: 800; cursor: pointer; text-decoration: none; }
.doc-btn:hover { border-color: var(--brand); color: var(--brand); }
.doc-btn--dark { background: #0f172a; border-color: #0f172a; color: #fff; }
.doc-btn--dark:hover { background: #1e293b; color: #fff; }
.doc-btn--peligro:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.doc-contador { display: inline-flex; align-items: center; justify-content: center; min-width: 1.4rem; height: 1.4rem; padding: 0 0.35rem; border-radius: 999px; background: #e2e8f0; color: #334155; font-size: 0.65rem; font-weight: 800; }

/* ============================================================
   APP MÓVIL · áreas seguras (notch, barra de estado, gestos)
   --safe-area-inset-* lo inyecta Capacitor (SystemBars) en Android;
   en iOS y en la PWA se usa env(). En escritorio todo vale 0.
   ============================================================ */
:root {
  --sat: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --sab: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --sal: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --sar: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
}
#mg-header { padding-top: var(--sat); padding-left: var(--sal); padding-right: var(--sar); }
#mg-tabs { top: calc(5rem + var(--sat)); }
#mg-main { padding-top: calc(5rem + var(--sat)); padding-bottom: var(--sab); }
#login-screen { padding-top: calc(1rem + var(--sat)); padding-bottom: calc(1rem + var(--sab)); }
.chat-fab { bottom: calc(1.25rem + var(--sab)); }
.modal { padding-bottom: calc(1.1rem + var(--sab)); }
.modal-overlay.desktop .modal { padding-bottom: 1.1rem; }
/* En el celular, sin resaltado gris al tocar y sin zoom al enfocar campos */
html.app-nativa, html.app-nativa body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
@media (max-width: 640px) {
  html.app-nativa input, html.app-nativa select, html.app-nativa textarea { font-size: 16px; }
}
#modal-ficha, [id$="-modal"].fixed { padding-top: calc(1rem + var(--sat)); padding-bottom: calc(1rem + var(--sab)); }
.toast { bottom: calc(1.25rem + var(--sab)); }

/* ============================================================
   VENTANAS (login, ficha y modales): nunca se cortan arriba.
   Si el contenido es más alto que la pantalla, la capa hace scroll
   y la ventana queda centrada cuando cabe (margin:auto).
   ============================================================ */
#login-screen, #modal-ficha, [id$="-modal"].fixed {
  align-items: flex-start !important;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#login-screen > div, #modal-ficha > div, [id$="-modal"].fixed > div {
  margin-top: auto !important;
  margin-bottom: auto !important;
}

/* Login / registro más compacto, con aire arriba y abajo */
#login-screen { padding-top: calc(1.5rem + var(--sat)); padding-bottom: calc(1.5rem + var(--sab)); }
#login-card input, #login-card select { padding: 0.6rem 0.8rem; font-size: 0.875rem; }
#login-card label { margin-bottom: 0.2rem; }
#login-card #login-submit { padding-top: 0.7rem; padding-bottom: 0.7rem; }

/* Ficha del proyecto: cabecera y pestañas fijas; solo el contenido se desplaza */
#ficha-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem - var(--sat) - var(--sab));
  max-height: calc(100dvh - 2rem - var(--sat) - var(--sab));
}
#ficha-cabecera, #ficha-subtabs, #ficha-pie { flex-shrink: 0; }
#ficha-cuerpo { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
@media (max-width: 640px) {
  #modal-ficha { padding: calc(0.5rem + var(--sat)) 0.5rem calc(0.5rem + var(--sab)) !important; }
  #ficha-panel { max-height: calc(100vh - 1rem - var(--sat) - var(--sab)); max-height: calc(100dvh - 1rem - var(--sat) - var(--sab)); }
  #ficha-cabecera { padding: 0.85rem 1rem; }
  #ficha-nombre { font-size: 1.15rem; line-height: 1.3; }
  #ficha-cuerpo { padding: 1rem; }
  #ficha-pie { padding: 0.6rem 1rem; }
  #ficha-subtabs { padding-left: 1rem; padding-right: 1rem; }
  #ficha-editar { padding: 0.5rem 0.65rem; }
  /* Modales con formulario largo: el formulario se desplaza dentro */
  [id$="-modal"].fixed { padding: calc(0.5rem + var(--sat)) 0.5rem calc(0.5rem + var(--sab)) !important; }
}
#proyecto-modal > div { display: flex; flex-direction: column; max-height: calc(100dvh - 2rem - var(--sat) - var(--sab)); }
#proyecto-form { max-height: none !important; flex: 1 1 auto; min-height: 0; }

/* Buscador de ciudades */
.ciudad-combo { position: relative; }
.ciudad-combo__icono { position: absolute; right: 0.85rem; top: 0.95rem; color: #94a3b8; font-size: 0.8rem; pointer-events: none; }
.ciudad-combo__lista { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 15rem; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 0.75rem; box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18); padding: 0.25rem; }
.ciudad-combo__op { padding: 0.55rem 0.7rem; border-radius: 0.5rem; cursor: pointer; display: flex; align-items: baseline; }
.ciudad-combo__op:hover, .ciudad-combo__op.activa { background: #fef2f2; }
.ciudad-combo__nota { padding: 0.55rem 0.7rem; font-size: 0.7rem; color: #94a3b8; }

/* Proyecto nuevo */
.badge-nuevo { display: inline-flex; align-items: center; padding: 0.15rem 0.5rem; border-radius: 999px; background: #dc2626; color: #fff; font-size: 0.6rem; font-weight: 900; letter-spacing: 0.08em; box-shadow: 0 2px 6px rgba(220, 38, 38, 0.35); vertical-align: middle; }
.tarjeta-recien-creada { box-shadow: 0 0 0 3px #dc2626, 0 12px 28px rgba(220, 38, 38, 0.2) !important; animation: mg-pulso 1.2s ease-in-out 3; }
@keyframes mg-pulso { 50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.35), 0 12px 28px rgba(220, 38, 38, 0.2); } }

/* Botón eliminar proyecto (Gerencia) */
.btn-eliminar-proyecto { display: inline-flex; align-items: center; justify-content: center; background: #fff; color: #b91c1c; border: 1px solid #fecaca; transition: background 0.15s, color 0.15s; }
.btn-eliminar-proyecto:hover { background: #dc2626; color: #fff; border-color: #dc2626; }
/* Registro: contraseña y confirmación lado a lado para que la tarjeta sea más baja */
.grid-claves { display: grid; gap: 0.75rem; }
@media (min-width: 480px) {
  .grid-claves:has([data-solo-registro]:not(.hidden)) { grid-template-columns: 1fr 1fr; }
  #login-card:has([data-solo-registro]:not(.hidden)) { max-width: 26rem; }
}
#login-card label { font-size: 0.68rem; }
#login-card .space-y-3 > * + * { margin-top: 0.6rem; }
#login-card:has([data-solo-registro]:not(.hidden)) #login-forgot { display: none; }
/* El botón flotante del asistente no tapa las ventanas abiertas */
body:has(#login-screen:not(.is-hidden)) .chat-fab,
body:has(#modal-ficha:not(.is-hidden)) .chat-fab,
body:has([id$="-modal"].fixed:not(.is-hidden)) .chat-fab { display: none; }

/* Pestañas principales: sin íconos, más aire y repartidas a lo ancho */
.mg-tabs-fila { gap: 1.25rem; }
.mg-tab { font-size: 0.8rem; padding: 0.85rem 0.35rem; letter-spacing: 0.01em; transition: color 0.15s, border-color 0.15s; }
.mg-tab:hover { color: var(--text); }
.mg-tab.active { font-weight: 800; }
@media (min-width: 1024px) {
  /* Cada pestaña crece por igual: quedan repartidas sin cortarse si no caben */
  .mg-tabs-fila { gap: 0.25rem; }
  .mg-tab { flex: 1 0 auto; text-align: center; font-size: 0.85rem; padding-left: 0.75rem; padding-right: 0.75rem; }
}
.mg-tab.hidden { display: none; }

/* ============================================================
   TIEMPOS (tareas) Y ESTADÍSTICAS
   ============================================================ */
.tiempo-trabajo { display: flex; align-items: center; gap: 0.35rem; margin-top: 0.4rem; font-size: 0.68rem; font-weight: 700; color: #475569; }
.tiempo-trabajo i { color: #94a3b8; }
.tiempo-trabajo--ok { color: #047857; }
.tiempo-trabajo--ok i { color: #10b981; }
.tiempo-trabajo--alerta { color: #b91c1c; }
.tiempo-trabajo--alerta i { color: #ef4444; }

.stat-etapas { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.stat-etapa { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; padding: 1.1rem 1.1rem 1rem; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05); }
.stat-etapa__num { position: absolute; top: 0.9rem; right: 1rem; width: 1.6rem; height: 1.6rem; border-radius: 999px; background: #f1f5f9; color: #475569; font-size: 0.75rem; font-weight: 900; display: flex; align-items: center; justify-content: center; }
.stat-etapa__curso { display: inline-block; margin-top: 0.5rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; font-size: 0.65rem; font-weight: 800; }
.stat-bloque { background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; padding: 1.1rem; }
.stat-bloque h3 { font-weight: 900; color: var(--text); font-size: 0.95rem; }
.stat-bloque > p { font-size: 0.72rem; color: #64748b; margin: 0.15rem 0 0.75rem; }
.stat-scroll { overflow-x: auto; }
.stat-tabla { width: 100%; border-collapse: collapse; font-size: 0.75rem; min-width: 640px; }
.stat-tabla th { text-align: left; font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; font-weight: 800; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.stat-tabla td { padding: 0.6rem; border-bottom: 1px solid #f1f5f9; vertical-align: top; color: var(--text); }
.stat-tabla tr:last-child td { border-bottom: 0; }
.stat-barra { height: 4px; background: #f1f5f9; border-radius: 999px; margin-top: 0.35rem; overflow: hidden; }
.stat-barra span { display: block; height: 100%; background: #334155; border-radius: 999px; }
.stat-chip-curso { display: inline-block; padding: 0.1rem 0.45rem; border-radius: 999px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; font-size: 0.65rem; font-weight: 800; white-space: nowrap; }

/* ============================================================
   FORMULARIOS: teléfono +57, ayudas y errores
   ============================================================ */
.campo-telefono { position: relative; }
.campo-telefono__prefijo { position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%); font-weight: 800; color: #475569; font-size: 0.8rem; pointer-events: none; }
.campo-ayuda { font-size: 0.65rem; color: #94a3b8; margin-top: 0.25rem; }
.campo-error { font-size: 0.68rem; color: #b91c1c; font-weight: 700; margin-top: 0.25rem; }
.campo-invalido { border-color: #dc2626 !important; background: #fef2f2 !important; box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }
.form-errores { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 0.75rem; padding: 0.75rem 0.9rem; font-size: 0.72rem; }
.form-errores ul { margin-top: 0.35rem; padding-left: 1.1rem; list-style: disc; }
.form-errores li + li { margin-top: 0.2rem; }
.form-errores button { text-align: left; text-decoration: underline; text-underline-offset: 2px; color: inherit; }

/* Documentos agrupados por subcarpeta */
.doc-grupo { border: 1px solid var(--border); border-radius: 0.9rem; padding: 0.75rem; background: #f8fafc; }
.doc-grupo + .doc-grupo { margin-top: 0.75rem; }
.doc-grupo__cab { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; }
.doc-grupo__cab h6 { display: flex; align-items: center; gap: 0.45rem; font-weight: 900; color: var(--text); font-size: 0.8rem; }
.doc-grupo__cab h6 i { color: var(--brand); }
.doc-grupo__vacio { font-size: 0.7rem; color: #94a3b8; padding: 0.4rem 0.2rem; }

/* Equipo en lista */
.equipo-tabla td { vertical-align: middle; }

/* ============================================================
   TEMA OSCURO v2 (nov 2026) · activado con .tema-oscuro en <html>
   ------------------------------------------------------------
   Grafito neutro en lugar del azul marino anterior: menos
   contraste duro, superficies por capas (pozo < fondo < tarjeta
   < elevado), bordes translúcidos y estados en tintes suaves.
   El rojo de marca se aclara un poco para no "vibrar" en negro.
     --bg        #0e0f11  fondo de la app
     --sunken    #0a0b0c  pozos dentro de tarjetas, campos
     --surface   #16171a  tarjetas, modales
     --raised    #1e2024  chips, hover, filas activas
     --raised-2  #282a2f  botones neutros, barras
     --text      #ededef  /  --text-2 #b9bbc2  /  --muted #8e919a
     --brand     #e5484d  (hover #f0575c)
   ============================================================ */
html.tema-oscuro {
  color-scheme: dark;
  --bg: #0e0f11;
  --sunken: #0a0b0c;
  --surface: #16171a;
  --raised: #1e2024;
  --raised-2: #282a2f;
  --border: rgba(255, 255, 255, 0.08);
  --border-soft: rgba(255, 255, 255, 0.05);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #ededef;
  --text-2: #b9bbc2;
  --muted: #8e919a;
  --faint: #676a73;
  --brand: #e5484d;
  --brand-dark: #f0575c;
  --brand-tint: rgba(229, 72, 77, 0.12);
  --brand-line: rgba(229, 72, 77, 0.32);
  --success: #3dd68c;
  --success-solid: #26a269;
  --success-tint: rgba(61, 214, 140, 0.11);
  --success-line: rgba(61, 214, 140, 0.28);
  --warning: #ffc53d;
  --warning-tint: rgba(255, 197, 61, 0.10);
  --warning-line: rgba(255, 197, 61, 0.28);
  --danger: #ff6369;
  --info: #70b8ff;
  --info-tint: rgba(112, 184, 255, 0.11);
  --info-line: rgba(112, 184, 255, 0.28);
  --violet: #d19dff;
  --violet-tint: rgba(209, 157, 255, 0.11);
  --violet-line: rgba(209, 157, 255, 0.28);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 16px 40px rgba(0, 0, 0, 0.5);
}
html.tema-oscuro body { background-color: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
html.tema-oscuro ::selection { background: rgba(229, 72, 77, 0.35); color: #fff; }

/* Barras de desplazamiento discretas */
html.tema-oscuro * { scrollbar-color: #2e3036 transparent; }
html.tema-oscuro ::-webkit-scrollbar { width: 10px; height: 10px; }
html.tema-oscuro ::-webkit-scrollbar-thumb { background: #2e3036; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
html.tema-oscuro ::-webkit-scrollbar-track { background: transparent; }

/* ---------- Fondos (utilidades Tailwind) ---------- */
html.tema-oscuro .bg-slate-50 { background-color: var(--bg); }
html.tema-oscuro .bg-white { background-color: var(--surface); }
html.tema-oscuro .bg-white\/95 { background-color: rgba(22, 23, 26, 0.85); -webkit-backdrop-filter: saturate(140%) blur(14px); backdrop-filter: saturate(140%) blur(14px); }
html.tema-oscuro .bg-white\/50 { background-color: rgba(255, 255, 255, 0.03); }
html.tema-oscuro .bg-gray-50,
html.tema-oscuro .bg-slate-100,
html.tema-oscuro .bg-slate-100\/50 { background-color: var(--raised); }
html.tema-oscuro .bg-gray-100,
html.tema-oscuro .bg-slate-200,
html.tema-oscuro .bg-slate-200\/60 { background-color: var(--raised-2); }
html.tema-oscuro .bg-slate-300 { background-color: #34373d; }
html.tema-oscuro .bg-slate-500 { background-color: #5b5e66; }
/* Botones/etiquetas oscuros del tema claro → gris elevado (el texto blanco sigue legible) */
html.tema-oscuro .bg-slate-900 { background-color: #2a2c31; }
html.tema-oscuro .bg-slate-800 { background-color: #33363c; }
/* Fondos detrás de los modales: negro translúcido, no azul */
html.tema-oscuro .bg-slate-900\/60,
html.tema-oscuro .bg-slate-900\/50 { background-color: rgba(0, 0, 0, 0.62); }
html.tema-oscuro .from-slate-950\/70 { --tw-gradient-from: rgba(0, 0, 0, 0.72) var(--tw-gradient-from-position, ); --tw-gradient-to: rgba(0, 0, 0, 0) var(--tw-gradient-to-position, ); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); }

html.tema-oscuro .bg-red-50 { background-color: rgba(229, 72, 77, 0.08); }
html.tema-oscuro .bg-red-50\/50,
html.tema-oscuro .bg-red-50\/40 { background-color: rgba(229, 72, 77, 0.06); }
html.tema-oscuro .bg-red-100 { background-color: rgba(229, 72, 77, 0.18); }
html.tema-oscuro .bg-red-500,
html.tema-oscuro .bg-red-600 { background-color: var(--brand); }
html.tema-oscuro .bg-red-700 { background-color: #d13d42; }

html.tema-oscuro .bg-emerald-50,
html.tema-oscuro .bg-emerald-50\/60,
html.tema-oscuro .bg-emerald-100 { background-color: var(--success-tint); }
html.tema-oscuro .bg-emerald-500,
html.tema-oscuro .bg-emerald-600 { background-color: var(--success-solid); }
html.tema-oscuro .bg-emerald-700 { background-color: #1f8a59; }

html.tema-oscuro .bg-amber-50,
html.tema-oscuro .bg-amber-50\/60,
html.tema-oscuro .bg-amber-100,
html.tema-oscuro .bg-yellow-50,
html.tema-oscuro .bg-orange-50 { background-color: var(--warning-tint); }
html.tema-oscuro .bg-amber-600 { background-color: #c98a00; }

html.tema-oscuro .bg-blue-50,
html.tema-oscuro .bg-blue-100,
html.tema-oscuro .bg-sky-50 { background-color: var(--info-tint); }
html.tema-oscuro .bg-blue-600 { background-color: #3b82f6; }
html.tema-oscuro .bg-violet-50 { background-color: var(--violet-tint); }

/* ---------- Hover (deben ganarle a las reglas de arriba) ---------- */
html.tema-oscuro .hover\:bg-slate-50:hover,
html.tema-oscuro .hover\:bg-slate-100:hover { background-color: var(--raised); }
html.tema-oscuro .hover\:bg-slate-200:hover { background-color: var(--raised-2); }
html.tema-oscuro .hover\:bg-slate-300:hover { background-color: #3a3d44; }
html.tema-oscuro .hover\:bg-slate-800:hover,
html.tema-oscuro .hover\:bg-slate-900:hover { background-color: #3a3d44; }
html.tema-oscuro .hover\:bg-red-700:hover { background-color: var(--brand-dark); }
html.tema-oscuro .hover\:bg-red-50:hover { background-color: var(--brand-tint); }
html.tema-oscuro .hover\:bg-emerald-50:hover { background-color: var(--success-tint); }
html.tema-oscuro .hover\:bg-emerald-700:hover { background-color: #2fb878; }
html.tema-oscuro .hover\:text-slate-900:hover { color: var(--text); }
html.tema-oscuro .hover\:text-red-600:hover { color: var(--danger); }
html.tema-oscuro .hover\:border-slate-300:hover { border-color: var(--border-strong); }
html.tema-oscuro .hover\:border-red-300:hover { border-color: var(--brand-line); }

/* ---------- Texto ---------- */
html.tema-oscuro .text-slate-900 { color: var(--text); }
html.tema-oscuro .text-slate-800 { color: #e2e3e6; }
html.tema-oscuro .text-slate-700 { color: var(--text-2); }
html.tema-oscuro .text-slate-600 { color: #a3a6ae; }
html.tema-oscuro .text-slate-500,
html.tema-oscuro .text-gray-500 { color: var(--muted); }
html.tema-oscuro .text-slate-400 { color: var(--faint); }
html.tema-oscuro .text-slate-300,
html.tema-oscuro .text-slate-200 { color: var(--text-2); }

html.tema-oscuro .text-red-500,
html.tema-oscuro .text-red-600 { color: var(--danger); }
html.tema-oscuro .text-red-700 { color: #ff8589; }
html.tema-oscuro .text-red-800,
html.tema-oscuro .text-red-900 { color: #ffb1b3; }
html.tema-oscuro .text-emerald-600,
html.tema-oscuro .text-emerald-700 { color: var(--success); }
html.tema-oscuro .text-emerald-800,
html.tema-oscuro .text-emerald-900,
html.tema-oscuro .text-teal-800 { color: #8ee8bb; }
html.tema-oscuro .text-amber-600,
html.tema-oscuro .text-amber-700 { color: var(--warning); }
html.tema-oscuro .text-amber-800,
html.tema-oscuro .text-amber-900,
html.tema-oscuro .text-yellow-800,
html.tema-oscuro .text-orange-800 { color: #ffdb85; }
html.tema-oscuro .text-blue-600 { color: var(--info); }
html.tema-oscuro .text-sky-800,
html.tema-oscuro .text-blue-900,
html.tema-oscuro .text-blue-950 { color: #b3d8ff; }
html.tema-oscuro .text-violet-800 { color: var(--violet); }

/* ---------- Bordes ---------- */
html.tema-oscuro .border-slate-200,
html.tema-oscuro .border-slate-200\/80 { border-color: var(--border); }
html.tema-oscuro .border-slate-100 { border-color: var(--border-soft); }
html.tema-oscuro .border-slate-300 { border-color: var(--border-strong); }
html.tema-oscuro .divide-slate-200 > :not([hidden]) ~ :not([hidden]) { border-color: var(--border); }
html.tema-oscuro .border-red-100,
html.tema-oscuro .border-red-200,
html.tema-oscuro .border-red-300 { border-color: var(--brand-line); }
html.tema-oscuro .border-red-600 { border-color: var(--brand); }
html.tema-oscuro .border-emerald-100,
html.tema-oscuro .border-emerald-200,
html.tema-oscuro .border-emerald-300 { border-color: var(--success-line); }
html.tema-oscuro .border-amber-100,
html.tema-oscuro .border-amber-200,
html.tema-oscuro .border-yellow-200,
html.tema-oscuro .border-orange-200 { border-color: var(--warning-line); }
html.tema-oscuro .border-blue-100,
html.tema-oscuro .border-blue-200,
html.tema-oscuro .border-sky-200 { border-color: var(--info-line); }
html.tema-oscuro .border-violet-200 { border-color: var(--violet-line); }
html.tema-oscuro .ring-red-600 { --tw-ring-color: var(--brand); }

/* ---------- Sombras: en oscuro la profundidad la dan las capas ---------- */
html.tema-oscuro .shadow-sm { box-shadow: var(--shadow-sm); }
html.tema-oscuro .shadow-md,
html.tema-oscuro .shadow-lg { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 20px rgba(0, 0, 0, 0.35); }
html.tema-oscuro .shadow-xl,
html.tema-oscuro .shadow-2xl { box-shadow: var(--shadow); }

/* ---------- Campos de formulario ---------- */
html.tema-oscuro input,
html.tema-oscuro select,
html.tema-oscuro textarea { background-color: var(--sunken); color: var(--text); border-color: var(--border); }
html.tema-oscuro input[type="checkbox"],
html.tema-oscuro input[type="radio"] { accent-color: var(--brand); }
html.tema-oscuro input::placeholder,
html.tema-oscuro textarea::placeholder { color: var(--faint); }
html.tema-oscuro input:hover,
html.tema-oscuro select:hover,
html.tema-oscuro textarea:hover { border-color: var(--border-strong); }
html.tema-oscuro input:focus,
html.tema-oscuro select:focus,
html.tema-oscuro textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.22); outline: none; }
html.tema-oscuro .field label { color: var(--muted); }
html.tema-oscuro .field input,
html.tema-oscuro .field select,
html.tema-oscuro .field textarea { background: var(--sunken); }
html.tema-oscuro .campo-telefono__prefijo { color: var(--muted); }
html.tema-oscuro .campo-invalido { background: rgba(229, 72, 77, 0.08) !important; border-color: var(--brand) !important; }
html.tema-oscuro .form-errores { background: var(--brand-tint); border-color: var(--brand-line); color: #ffb1b3; }

/* ---------- Botones y chips ---------- */
html.tema-oscuro .btn-ghost { background: var(--raised); color: var(--text); border-color: var(--border); }
html.tema-oscuro .btn-ghost:hover { background: var(--raised-2); }
html.tema-oscuro .btn-dark,
html.tema-oscuro .doc-btn--dark { background: var(--text); border-color: var(--text); color: #111214; }
html.tema-oscuro .btn-dark:hover,
html.tema-oscuro .doc-btn--dark:hover { background: #ffffff; color: #111214; }
html.tema-oscuro .f-chip:hover { background: var(--raised); color: var(--text); }
html.tema-oscuro .f-chip.active { box-shadow: none; }
html.tema-oscuro .vista-toggle { background: var(--sunken); border-color: var(--border); }
html.tema-oscuro .vista-toggle button.active { background: var(--raised-2); color: var(--text); }
html.tema-oscuro .btn-eliminar-proyecto { background: transparent; border-color: var(--brand-line); color: #ff8589; }
html.tema-oscuro .btn-eliminar-proyecto:hover { background: var(--brand); border-color: var(--brand); color: #fff; }
html.tema-oscuro .badge-nuevo { box-shadow: none; }
html.tema-oscuro .chat-fab { box-shadow: 0 10px 26px rgba(229, 72, 77, 0.28); }

/* ---------- Pestañas ---------- */
html.tema-oscuro .mg-tab { color: var(--muted); }
html.tema-oscuro .mg-tab:hover { color: var(--text); }
html.tema-oscuro .mg-tab.active { color: var(--text); border-bottom-color: var(--brand); }

/* ---------- Tarjetas, KPI, estados ---------- */
html.tema-oscuro .kpi-card.kpi-alert { background: var(--surface); border-color: var(--brand-line); box-shadow: inset 3px 0 0 var(--brand); }
html.tema-oscuro .kpi-card.kpi-success { background: var(--surface); border-color: var(--success-line); box-shadow: inset 3px 0 0 var(--success); }
html.tema-oscuro .render-hd { background: linear-gradient(135deg, #24262b, #121316); }
html.tema-oscuro .badge-en_proceso { background: var(--brand-tint); color: #ff8589; border-color: var(--brand-line); }
html.tema-oscuro .badge-detencion { background: var(--warning-tint); color: var(--warning); border-color: var(--warning-line); }
html.tema-oscuro .badge-completado { background: var(--success-tint); color: var(--success); border-color: var(--success-line); }
html.tema-oscuro .alerta-material { background: var(--warning-tint); border-color: var(--warning-line); color: #ffdb85; }
html.tema-oscuro .alerta-bloqueo { background: var(--brand-tint); border-color: var(--brand-line); color: #ffb1b3; }
html.tema-oscuro .step.current .dot { box-shadow: 0 0 0 4px rgba(229, 72, 77, 0.2); }
html.tema-oscuro .step.blocked .dot { box-shadow: 0 0 0 4px rgba(255, 99, 105, 0.2); }

/* Indicador de sincronización */
html.tema-oscuro .mg-sync--ok { background: var(--success-tint); border-color: var(--success-line); color: var(--success); }
html.tema-oscuro .mg-sync--trabajando { background: var(--raised); border-color: var(--border); color: var(--text-2); }
html.tema-oscuro .mg-sync--alerta { background: var(--warning-tint); border-color: var(--warning-line); color: var(--warning); }
html.tema-oscuro .mg-sync--error { background: var(--brand-tint); border-color: var(--brand-line); color: #ff8589; }
html.tema-oscuro .mg-sync--error:hover { background: rgba(229, 72, 77, 0.18); }

/* Pendientes */
html.tema-oscuro .pendiente-tipo--material { background: var(--warning-tint); color: var(--warning); border-color: var(--warning-line); }
html.tema-oscuro .pendiente-tipo--requerimiento { background: var(--info-tint); color: var(--info); border-color: var(--info-line); }
html.tema-oscuro .pendiente-tipo--bloqueo { background: var(--brand-tint); color: #ff8589; border-color: var(--brand-line); }
html.tema-oscuro [data-stage-col].drag-over { background: var(--brand-tint); }

/* Tabla general y listas */
html.tema-oscuro .tabla-general tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

/* Avisos (toast): superficie elevada con acento, no un bloque rojo */
html.tema-oscuro .toast { background: #f2f2f4; color: #111214; box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); }

/* Chat */
html.tema-oscuro .chat-avatar { background: var(--brand-tint); }
html.tema-oscuro .chat-msg--user { color: #fff; }

/* Modales */
html.tema-oscuro .modal-overlay { background: rgba(0, 0, 0, 0.62); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
html.tema-oscuro .modal { background: var(--surface); border-color: var(--border); }
html.tema-oscuro .modal-close { background: var(--raised); border-color: var(--border); color: var(--muted); }

/* Documentos */
html.tema-oscuro .doc-grupo { background: var(--sunken); border-color: var(--border-soft); }
html.tema-oscuro .doc-grupo__vacio { color: var(--faint); }
html.tema-oscuro .doc-item--sin-archivo { background: var(--warning-tint); border-color: var(--warning-line); }
html.tema-oscuro .doc-contador { background: var(--raised-2); color: var(--text-2); }

/* Ciudades */
html.tema-oscuro .ciudad-combo__op:hover,
html.tema-oscuro .ciudad-combo__op.activa { background: var(--brand-tint); }

/* Estadísticas y tiempos */
html.tema-oscuro .stat-etapa__num,
html.tema-oscuro .stat-barra { background: var(--raised-2); color: var(--text-2); }
html.tema-oscuro .stat-barra span { background: var(--brand); }
html.tema-oscuro .stat-tabla td { border-bottom-color: var(--border-soft); }
html.tema-oscuro .stat-bloque > p { color: var(--muted); }
html.tema-oscuro .stat-etapa__curso,
html.tema-oscuro .stat-chip-curso { background: var(--warning-tint); border-color: var(--warning-line); color: var(--warning); }
html.tema-oscuro .tiempo-trabajo { color: var(--muted); }

/* Transición suave al cambiar de tema */
html.cambiando-tema *, html.cambiando-tema *::before, html.cambiando-tema *::after { transition: background-color .25s ease, border-color .25s ease, color .2s ease !important; }
