/*!
 * Custom CSS del proyecto ICG.
 * Estilos compartidos: lookups responsive, formularios de documento,
 * y ajustes de usabilidad para tablet/móvil.
 */

/* ====================================================================
   Navegación PRO: barra de progreso superior (estilo Vercel/Linear) +
   revelado del contenido. Minimalista, rápido y sin tapar la pantalla.
   Lo controla el JS de base.html (#icg-progress + ICGNav).
   ==================================================================== */
#icg-progress {
  position: fixed;
  top: 0; left: 0;
  height: 2.5px; width: 0;
  z-index: 4000;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, #04a9f5 0%, #1de9b6 100%);
  box-shadow: 0 0 10px rgba(4, 169, 245, 0.65), 0 0 5px rgba(29, 233, 182, 0.5);
  transition: width 0.25s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.3s ease;
}
#icg-progress.active { opacity: 1; }
/* "Cometa": brillo en la cabeza de la barra */
#icg-progress::after {
  content: '';
  position: absolute;
  right: 0; top: -2px;
  height: 6.5px; width: 90px;
  border-radius: 50%;
  box-shadow: 0 0 14px 3px rgba(4, 169, 245, 0.85);
  transform: translateX(35%);
}

/* Revelado del contenido al llegar (todas las páginas) */
.pc-content { animation: icg-content-in 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) both; }
@keyframes icg-content-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}

/* Transición ESPECIAL al abrir un documento (detalle): zoom suave */
body.icg-doc-enter .pc-content { animation: icg-doc-in 0.55s cubic-bezier(0.22, 0.61, 0.36, 1) both; }
@keyframes icg-doc-in {
  from { opacity: 0; transform: scale(0.965) translateY(12px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  #icg-progress { transition: opacity 0.15s ease; }
  .pc-content, body.icg-doc-enter .pc-content { animation: none !important; }
}

/* ====================================================================
   Lookups (búsqueda de artículo / cliente / proveedor)
   ==================================================================== */
.lookup-results {
  position: absolute;
  z-index: 1050;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  max-height: 320px;
  overflow-y: auto;
  width: 100%;
  margin-top: 2px;
  -webkit-overflow-scrolling: touch;
}
.lookup-results-floating {
  position: fixed !important;
  z-index: 1090;   /* por encima de mensajes flash (1080), tooltips, cards */
}
.lookup-results .item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background-color 120ms ease;
  min-height: 44px;            /* objetivo táctil cómodo */
}
.lookup-results .item:last-child { border-bottom: 0; }
.lookup-results .item:hover,
.lookup-results .item.active { background-color: #eef5ff; }
.lookup-results .item small { color: #888; display: block; margin-top: 2px; }

/* ====================================================================
   Totales de los formularios de documento
   ==================================================================== */
.icg-totales {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 16px;
}
.icg-total-final {
  font-size: 20px;
  font-weight: 600;
}

/* ====================================================================
   Tabla de líneas (creación de documentos)
   ==================================================================== */
.table-lineas td { vertical-align: middle; }
.table-lineas input { font-size: 14px; }

/* ====================================================================
   Combobox de búsqueda remota (Tom Select) — icg-remote-select.js
   ==================================================================== */
/* Que el control ocupe el ancho de su celda/columna sin desbordar. */
.table-lineas td .ts-wrapper,
.ts-remote { min-width: 0; }
.table-lineas .ts-control { font-size: 14px; min-height: 31px; }
/* Subtítulo (ref/precio) de cada opción del desplegable remoto. */
.ts-dropdown .ts-remote-opt small { font-size: 11px; }
.ts-dropdown .ts-loading,
.ts-dropdown .no-results { padding: 8px 12px; color: #888; font-size: 13px; }

/* Chips de info fija (cabecera de requisición) */
.info-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; background: #f1f3f5; border: 1px solid #e9ecef;
  border-radius: 999px; line-height: 1.4; white-space: nowrap; font-size: 13px;
}
.info-chip .info-label { color: #6c757d; text-transform: uppercase; letter-spacing: .04em; font-size: 11px; font-weight: 500; }
.info-chip .info-value { color: #1a1a1a; font-weight: 600; font-size: 13px; }
.info-chip-accent { background: #e7f5ff; border-color: #b6e0fe; }
.info-chip-accent .info-value { color: #0b5cad; }

/* ====================================================================
   Responsive — tablet y móvil
   ==================================================================== */
@media (max-width: 767.98px) {
  /* Lookups a casi todo el ancho y opciones más grandes en móvil */
  .lookup-results-floating { width: calc(100vw - 24px) !important; }
  .lookup-results .item { padding: 12px 14px; min-height: 48px; }

  /* Inputs y botones más cómodos al tacto dentro de tablas/formularios */
  .table-lineas .form-control-sm,
  .form-control-sm, .btn-sm { min-height: 40px; }

  /* La tabla de líneas se APILA en tarjetas: cada fila es un bloque y cada
     celda muestra su etiqueta (data-label). Así el buscador y los campos
     ocupan todo el ancho y NADA se desborda ni obliga a scroll horizontal. */
  .table-lineas { min-width: 0; }
  .table-lineas thead { display: none; }
  .table-lineas, .table-lineas tbody, .table-lineas tr, .table-lineas td { display: block; width: 100%; }
  .table-lineas tr {
    border: 1px solid var(--bs-border-color, #e9ecef);
    border-radius: 10px; padding: 8px 12px; margin: 0 0 10px;
  }
  .table-lineas td {
    border: 0; padding: 5px 0;
    display: flex; align-items: center; gap: 12px;
  }
  .table-lineas td::before {
    content: attr(data-label);
    flex: 0 0 34%; max-width: 34%;
    font-size: 12px; text-transform: uppercase; letter-spacing: .02em;
    color: #6c757d; font-weight: 600;
  }
  .table-lineas td[data-label=""]::before,
  .table-lineas td[data-label="#"]::before { content: none; }
  .table-lineas td[data-label="#"] { color: #6c757d; font-size: 12px; padding: 0 0 2px; }
  .table-lineas td[data-label="Total"] { justify-content: space-between; font-size: 15px; }
  .table-lineas td[data-label=""] { justify-content: flex-end; }
  .table-lineas td .form-control,
  .table-lineas td .ts-wrapper { flex: 1 1 auto; min-width: 0; }

  /* Cabeceras de página: título y acciones se apilan limpio */
  .page-header .page-block .d-flex { row-gap: .5rem; }

  /* Botones de acción a ancho completo en pantallas muy chicas */
  .icg-actions .btn { flex: 1 1 auto; }
}

/* ====================================================================
   Overlay "Procesando…" (envío de formularios / acciones)
   ==================================================================== */
.icg-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(17, 24, 39, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(1px);
}
.icg-overlay.d-none { display: none !important; }
.icg-overlay-box {
  text-align: center;
  padding: 1.5rem 2rem;
}

/* ====================================================================
   Modal de confirmación unificado (.icg-confirm)
   ==================================================================== */
.icg-confirm .modal-content {
  border: 0;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .25);
}
.icg-confirm .modal-header {
  border-bottom: 0;
  padding: 1rem 1.25rem;
}
.icg-confirm .modal-title { font-size: 1.05rem; font-weight: 600; }
.icg-confirm .modal-body { padding: 1.25rem; font-size: .95rem; }
.icg-confirm .modal-footer { border-top: 0; padding: .75rem 1.25rem 1.25rem; }
.icg-confirm .icg-confirm-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255, 255, 255, .25);
}
.icg-confirm .icg-confirm-icon i { width: 18px; height: 18px; }

/* Variantes de color del encabezado */
.icg-confirm-danger  { background: #dc3545; color: #fff; }
.icg-confirm-warning { background: #f5a623; color: #1b1b1b; }
.icg-confirm-primary { background: #04a9f5; color: #fff; }
.icg-confirm-danger .btn-close,
.icg-confirm-primary .btn-close { filter: invert(1) grayscale(1) brightness(2); }

/* ====================================================================
   Accesibilidad: foco visible consistente
   ==================================================================== */
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.page-link:focus-visible,
a.pc-head-link:focus-visible,
.lookup-results .item:focus-visible {
  outline: 2px solid #04a9f5;
  outline-offset: 2px;
}
.lookup-results .item:focus { background: #eef6ff; }

/* ====================================================================
   Impresión: ocultar cromo (sidebar/nav/botones) y dejar el contenido
   ==================================================================== */
@media print {
  .pc-sidebar, .pc-header, #icg-overlay, .flash-stack,
  .icg-actions, .icg-list-toolbar, .card-footer,
  footer, .pc-footer, .breadcrumb, form.icg-action-form,
  #theme-toggle, .btn { display: none !important; }

  body { background: #fff !important; }
  .pc-container, .pc-content { margin: 0 !important; padding: 0 !important; }
  .card { border: 1px solid #ddd !important; box-shadow: none !important; }
  a[href]:after { content: ""; }   /* no imprimir URLs tras los enlaces */
  .table { font-size: 12px; }
}

/* En tablet, dar un poco más de aire a las celdas */
@media (min-width: 768px) and (max-width: 991.98px) {
  .table-lineas td, .table-lineas th { padding-top: .4rem; padding-bottom: .4rem; }
}

/* ====================================================================
   Homologación de listas y detalles
   ==================================================================== */
.icg-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.icg-list-toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.icg-list-toolbar .icg-search { flex: 1 1 240px; min-width: 0; }

/* ====================================================================
   Modo oscuro
   --------------------------------------------------------------------
   La plantilla (Mantis free) NO incluye el dark del "shell" (sidebar +
   header). Bootstrap 5.3 sí trae el de sus componentes bajo
   [data-bs-theme="dark"] (lo activamos en <html> desde el toggle); aquí
   oscurecemos el shell pcoded y afinamos algunas superficies propias.
   ==================================================================== */
[data-bs-theme="dark"] {
  --bs-body-bg: #0f1720;
  --bs-card-bg: #16202b;
  --bs-border-color: #243240;
}
body[data-pc-theme="dark"] { background-color: #0f1720; }

/* --- Sidebar --- */
body[data-pc-theme="dark"] .pc-sidebar {
  --pc-sidebar-background: #16202b;
  --pc-sidebar-color: #aeb8c2;
  --pc-sidebar-caption-color: #6c7681;
  background: #16202b;
  border-right: 1px solid #243240;
}
body[data-pc-theme="dark"] .pc-sidebar .pc-link { color: #aeb8c2; }
body[data-pc-theme="dark"] .pc-sidebar .pc-caption,
body[data-pc-theme="dark"] .pc-sidebar .pc-caption label { color: #6c7681; }
body[data-pc-theme="dark"] .pc-sidebar .pc-item:hover > .pc-link {
  color: #fff; background: rgba(255, 255, 255, .05);
}
body[data-pc-theme="dark"] .pc-sidebar .pc-item.active > .pc-link {
  color: #fff;
}

/* --- Header / navbar --- */
body[data-pc-theme="dark"] .pc-header {
  --pc-header-background: rgba(22, 32, 43, .92);
  --pc-header-color: #ced4da;
  background: rgba(22, 32, 43, .92);
  border-bottom: 1px solid #243240;
}
body[data-pc-theme="dark"] .pc-header .pc-head-link,
body[data-pc-theme="dark"] .pc-header .pc-head-link i { color: #ced4da; }

/* --- Superficies propias (no cubiertas por Bootstrap) --- */
body[data-pc-theme="dark"] .card { background-color: #16202b; border-color: #243240; }
body[data-pc-theme="dark"] .border,
body[data-pc-theme="dark"] .border-top,
body[data-pc-theme="dark"] .border-bottom { border-color: #243240 !important; }
body[data-pc-theme="dark"] .text-muted { color: #8a96a3 !important; }
body[data-pc-theme="dark"] .table {
  --bs-table-color: #ced4da;
  --bs-table-bg: transparent;
  --bs-table-border-color: #243240;
  --bs-table-striped-bg: rgba(255, 255, 255, .03);
  --bs-table-striped-color: #ced4da;
  --bs-table-hover-bg: rgba(255, 255, 255, .06);
  --bs-table-hover-color: #fff;
  --bs-table-active-bg: rgba(255, 255, 255, .08);
  --bs-table-active-color: #fff;
}
body[data-pc-theme="dark"] .bg-light { background-color: #1b2733 !important; color: #ced4da !important; }
/* Variantes claras de tabla (.table-light, muy usadas en thead): se oscurecen
   por VARIABLES, no por background-color — Bootstrap pinta el fondo de la celda
   con box-shadow inset de --bs-table-bg, que ignora background-color. */
body[data-pc-theme="dark"] .table-light,
body[data-pc-theme="dark"] .table-light > th,
body[data-pc-theme="dark"] .table-light > td,
body[data-pc-theme="dark"] thead.table-light,
body[data-pc-theme="dark"] thead.table-light th {
  --bs-table-color: #e9eef3;
  --bs-table-bg: #1b2733;
  --bs-table-accent-bg: #1b2733;   /* el box-shadow inset de la celda usa este */
  --bs-table-border-color: #243240;
  color: #e9eef3;
}

/* --- list-group (p. ej. el log de auditoría del dashboard, que NO es tabla) --- */
body[data-pc-theme="dark"] .list-group {
  --bs-list-group-bg: #16202b;
  --bs-list-group-color: #ced4da;
  --bs-list-group-border-color: #243240;
  --bs-list-group-action-color: #ced4da;
  --bs-list-group-action-hover-bg: #1b2733;
  --bs-list-group-action-hover-color: #fff;
  --bs-list-group-action-active-bg: #1b2733;
}
body[data-pc-theme="dark"] .list-group-item { color: #ced4da; border-color: #243240; }

/* --- Dropdowns (menú de usuario, etc.) --- */
body[data-pc-theme="dark"] .dropdown-menu {
  --bs-dropdown-bg: #16202b;
  --bs-dropdown-color: #ced4da;
  --bs-dropdown-border-color: #243240;
  --bs-dropdown-link-color: #ced4da;
  --bs-dropdown-link-hover-bg: #1b2733;
  --bs-dropdown-link-hover-color: #fff;
  --bs-dropdown-divider-bg: #243240;
}

/* --- Badges .bg-light con texto oscuro: en modo oscuro el fondo se oscurece,
       así que el texto debe ir claro para seguir siendo legible. --- */
body[data-pc-theme="dark"] .bg-light.text-dark,
body[data-pc-theme="dark"] .badge.bg-light { color: #ced4da !important; }
body[data-pc-theme="dark"] pre { background-color: #0b1118; color: #ced4da; }
body[data-pc-theme="dark"] .pc-footer { background: transparent; color: #8a96a3; }
/* Transición suave al alternar */
body, .pc-sidebar, .pc-header, .card { transition: background-color .2s ease, border-color .2s ease; }

/* =========================================================================
 * Tom Select (comboboxes con búsqueda) — ajustes sobre el tema Bootstrap 5
 * ========================================================================= */
/* El desplegable se renderiza en <body> (dropdownParent: 'body') para no
   recortarse dentro de tarjetas/tablas; hay que elevarlo por encima de
   modales (1055) y a la altura de toasts. */
.ts-dropdown { z-index: 1090; }

/* El .ts-control ocupa el ancho del contenedor, como los .form-control. */
.ts-wrapper { width: 100%; }

/* Paridad de tamaño con .form-select-sm (Tom Select copia la clase al wrapper). */
.ts-wrapper.form-select-sm .ts-control {
  min-height: calc(1.5em + .5rem + 2px);
  padding: .25rem .5rem;
  font-size: .875rem;
  border-radius: var(--bs-border-radius-sm);
}

/* En modo oscuro, el control y el desplegable siguen los tokens de la app. */
body[data-pc-theme="dark"] .ts-control,
[data-bs-theme="dark"] .ts-control {
  background-color: var(--bs-body-bg, #0b1118);
  color: var(--bs-body-color, #ced4da);
  border-color: #243240;
}
body[data-pc-theme="dark"] .ts-dropdown,
[data-bs-theme="dark"] .ts-dropdown {
  background-color: #16212c;
  color: #ced4da;
  border-color: #243240;
}
body[data-pc-theme="dark"] .ts-dropdown .active,
[data-bs-theme="dark"] .ts-dropdown .active {
  background-color: #1b2733;
  color: #fff;
}
/* Los "items" seleccionados (chips) legibles en oscuro. */
body[data-pc-theme="dark"] .ts-control .item,
[data-bs-theme="dark"] .ts-control .item { color: var(--bs-body-color, #ced4da); }

/* ============================================================
   Panel de Seguimiento de Presupuesto: tarjetas clicables
   ============================================================ */
.seg-card {
  transition: transform .12s ease, box-shadow .12s ease;
}
.seg-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .12);
}
body[data-pc-theme="dark"] .seg-card:hover,
[data-bs-theme="dark"] .seg-card:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, .45);
}
