/* ==========================================================================
   F-eCX UI — capa transversal de presentación
   1) Header (topbar) con gradiente verde institucional
   2) Sidebar colapsable tipo "mini-rail" (solo iconos)
   Se aplica sobre las páginas existentes mediante clases que agrega
   /static/js/fecx-ui.js (.fecx-topbar / .fecx-sidebar / .fecx-main).
   ========================================================================== */

.fecx-sidebar { transition: width .3s ease; overflow-x: hidden; }
.fecx-main    { transition: margin-left .3s ease; }
.fecx-topbar  {
  transition: left .3s ease;
  background: linear-gradient(90deg, #00531f 0%, #006d31 45%, #1f9d4d 100%) !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  box-shadow: 0 2px 14px rgba(0, 64, 24, .18);
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

/* Texto e iconos del header en blanco para contraste sobre el verde */
.fecx-topbar h1,
.fecx-topbar h2,
.fecx-topbar h3,
.fecx-topbar p,
.fecx-topbar span,
.fecx-topbar a,
.fecx-topbar .material-symbols-outlined { color: #ffffff !important; }

/* El divisor vertical y los hovers se aclaran sobre el verde */
.fecx-topbar [class*="bg-slate-200"] { background-color: rgba(255, 255, 255, .35) !important; }
.fecx-topbar button:hover { background-color: rgba(255, 255, 255, .15) !important; }

/* Campos de búsqueda dentro del header conservan texto/icono oscuro legible */
.fecx-topbar input { color: #0f3d22; }
.fecx-topbar input::placeholder { color: rgba(15, 61, 34, .6); }
.fecx-topbar .relative .material-symbols-outlined { color: #0f3d22 !important; }

/* Botón de colapso del sidebar (vive dentro del header verde) */
.fecx-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 9999px;
  color: #ffffff;
  margin-right: .5rem;
  flex: 0 0 auto;
  transition: background-color .2s ease;
}
.fecx-toggle:hover { background-color: rgba(255, 255, 255, .15); }

/* -------- Estado colapsado: mini-rail (solo iconos) -------- */
body.fecx-collapsed .fecx-sidebar { width: 5rem !important; }
body.fecx-collapsed .fecx-main    { margin-left: 5rem !important; }
body.fecx-collapsed .fecx-topbar  { left: 5rem !important; }

/* Centrar los iconos y ocultar las etiquetas de texto al colapsar */
body.fecx-collapsed .fecx-sidebar a {
  justify-content: center;
  padding-left: .5rem;
  padding-right: .5rem;
}
body.fecx-collapsed .fecx-sidebar a span:not(.material-symbols-outlined),
body.fecx-collapsed .fecx-sidebar p,
body.fecx-collapsed .fecx-sidebar .fecx-hide-collapsed { display: none !important; }

/* ==========================================================================
   Tablas con más vida: píldoras de estado vívidas + zebra + filas animadas
   ========================================================================== */

/* Píldora de estado reutilizable (con punto indicador y latido en activos) */
.fecx-st {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .25rem .6rem;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  border: 1px solid transparent;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.fecx-st::before {
  content: "";
  width: .45rem;
  height: .45rem;
  border-radius: 9999px;
  flex: 0 0 auto;
  background: var(--dot, currentColor);
}

.fecx-st--ok      { --dot: #16a34a; background: #dcfce7; color: #15803d; border-color: #86efac; }
.fecx-st--pending { --dot: #f59e0b; background: #fef3c7; color: #b45309; border-color: #fcd34d; }
.fecx-st--review  { --dot: #ef4444; background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.fecx-st--cancel  { --dot: #94a3b8; background: #eef2f7; color: #64748b; border-color: #cbd5e1; }
.fecx-st--info    { --dot: #3b82f6; background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.fecx-st--wait    { --dot: #94a3b8; background: #f1f5f9; color: #64748b; border-color: #e2e8f0; }

/* Latido solo en los estados que requieren atención */
.fecx-st--pending::before,
.fecx-st--review::before { animation: fecxPulse 1.6s ease-in-out infinite; }

@keyframes fecxPulse {
  0%, 100% { transform: scale(1);   box-shadow: 0 0 0 0 var(--dot); }
  50%      { transform: scale(1.25); box-shadow: 0 0 0 3px transparent; }
}

/* Zebra muy sutil + transición de fondo en el hover de las filas */
.fecx-main tbody tr:nth-child(even) { background-color: rgba(15, 61, 34, .018); }
.fecx-main tbody tr { transition: background-color .2s ease, box-shadow .2s ease; }

@media (prefers-reduced-motion: reduce) {
  .fecx-st--pending::before,
  .fecx-st--review::before { animation: none; }
}

/* ==========================================================================
   Loader de transición entre páginas — elimina el "flash blanco" del reload
   (Tailwind CDN recompila al cargar). Visible por defecto; el JS lo oculta
   apenas la página está lista. La animación de seguridad lo retira si el JS
   fallara.
   ========================================================================== */
#fecx-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #00531f 0%, #006d31 55%, #1f9d4d 100%);
  opacity: 1;
  visibility: visible;
  transition: opacity .45s ease, visibility .45s ease;
  animation: fecxLoaderAuto 0s linear 4s forwards;
}
body.fecx-ready #fecx-loader { opacity: 0; visibility: hidden; }

#fecx-loader .fecx-loader-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
}
#fecx-loader .fecx-spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: #fff;
  animation: fecxSpin .8s linear infinite;
}
#fecx-loader .fecx-loader-text {
  color: rgba(255, 255, 255, 0.85);
  font: 700 0.7rem/1 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  padding-left: 0.32em;
}
@keyframes fecxSpin { to { transform: rotate(360deg); } }
@keyframes fecxLoaderAuto { to { opacity: 0; visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  #fecx-loader .fecx-spinner { animation-duration: 1.6s; }
}

/* ==========================================================================
   F-eCX — Capa de pulido visual (gradientes + profundidad)
   Todo lo de abajo es transversal: vive en el CSS compartido para que las
   7 páginas de empresa/aduanas se vean igual de cuidadas sin tocar su HTML.
   Paleta de marca: verde institucional #006d31 → #1f9d4d, brillo #71fe95.
   ========================================================================== */

:root {
  --fecx-green-900: #00531f;
  --fecx-green-700: #006d31;
  --fecx-green-500: #1f9d4d;
  --fecx-green-300: #52e07c;
  --fecx-green-100: #71fe95;
  --fecx-ink: #0b1f14;
}

* { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
html { scroll-behavior: smooth; }

/* --- Fondo ambiental: malla de auroras verdes muy tenues detrás de todo ---
   Se pinta con un pseudo-elemento fijo a z-index -1: queda por encima del
   color sólido del body (sea cual sea la utilidad Tailwind de cada página)
   y por debajo del contenido en flujo. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(680px 520px at 12% -8%, rgba(31, 157, 77, 0.10), transparent 60%),
    radial-gradient(720px 600px at 108% 8%, rgba(16, 101, 139, 0.07), transparent 55%),
    radial-gradient(900px 720px at 50% 116%, rgba(82, 224, 124, 0.08), transparent 60%),
    linear-gradient(180deg, #f6f9f6 0%, #f1f5f4 100%);
}

/* Selección y barra de scroll con identidad de marca */
::selection { background: rgba(31, 157, 77, 0.22); color: var(--fecx-ink); }
* { scrollbar-width: thin; scrollbar-color: rgba(0, 109, 49, 0.35) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(0, 109, 49, 0.45), rgba(31, 157, 77, 0.45));
  border-radius: 9999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(0, 109, 49, 0.7), rgba(31, 157, 77, 0.7));
  background-clip: padding-box;
}

/* --- Sidebar: degradado sutil + borde de luz + ítem activo con acento --- */
body .fecx-sidebar {
  background: linear-gradient(185deg, #ffffff 0%, #eef3ee 55%, #e8efe9 100%) !important;
  border-right: 1px solid rgba(0, 109, 49, 0.10);
  box-shadow: 1px 0 24px rgba(11, 31, 20, 0.05);
}
/* Barra de acento verde SOLO en el enlace activo (el que ya viene resaltado en
   blanco). Se excluye la variante hover:bg-white/hover:bg-emerald porque el
   selector de substring [class*="bg-white"] también matchea "hover:bg-white/50"
   de los enlaces inactivos, marcándolos como si estuvieran activos. */
.fecx-sidebar a[class*="bg-white"]:not([class*="hover:bg-white"]),
.fecx-sidebar a[class*="bg-emerald"]:not([class*="hover:bg-emerald"]) {
  position: relative;
  background: linear-gradient(120deg, #ffffff 0%, #f3fbf5 100%) !important;
  box-shadow: 0 6px 16px rgba(0, 109, 49, 0.12) !important;
}
.fecx-sidebar a[class*="bg-white"]:not([class*="hover:bg-white"])::before,
.fecx-sidebar a[class*="bg-emerald"]:not([class*="hover:bg-emerald"])::before {
  content: "";
  position: absolute;
  left: 0; top: 18%; bottom: 18%;
  width: 3px;
  border-radius: 9999px;
  background: linear-gradient(180deg, var(--fecx-green-500), var(--fecx-green-100));
}
body.fecx-collapsed .fecx-sidebar a[class*="bg-white"]:not([class*="hover:bg-white"])::before,
body.fecx-collapsed .fecx-sidebar a[class*="bg-emerald"]:not([class*="hover:bg-emerald"])::before { left: -2px; }

/* --- Header: brillo radial + línea de acento brillante en el borde inferior --- */
.fecx-topbar { position: fixed; overflow: hidden; }
.fecx-topbar > * { position: relative; z-index: 1; }
.fecx-topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(420px 160px at 18% -40%, rgba(255, 255, 255, 0.28), transparent 70%),
    radial-gradient(520px 200px at 100% 140%, rgba(0, 0, 0, 0.10), transparent 70%);
}
.fecx-topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(113, 254, 149, 0.85) 50%, transparent);
}

/* --- Tarjetas / paneles: micro-gradiente + sombra y borde unificados ---
   Aplica a todas las superficies blancas (.bg-surface-container-lowest) para
   homogeneizar páginas planas (certificado) con las que ya tenían relieve. */
.fecx-main .bg-surface-container-lowest {
  background: linear-gradient(180deg, #ffffff 0%, #fbfdfb 100%);
  border-color: rgba(0, 109, 49, 0.08);
  box-shadow: 0 10px 30px rgba(11, 31, 20, 0.06);
}

/* --- Botones primarios: gradiente + glow + lift coherentes ---
   Cubre tanto los planos (bg-primary) como los que ya traen gradiente. */
.fecx-main a.bg-primary,
.fecx-main button.bg-primary {
  background: linear-gradient(120deg, var(--fecx-green-700) 0%, var(--fecx-green-300) 100%) !important;
  border-radius: 0.6rem !important;
  box-shadow: 0 6px 18px rgba(0, 109, 49, 0.28);
  transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
}
.fecx-main a.bg-primary:hover,
.fecx-main button.bg-primary:hover,
.fecx-main a[class*="from-primary"]:hover,
.fecx-main button[class*="from-primary"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(0, 109, 49, 0.34);
  filter: saturate(1.05);
}
.fecx-main a[class*="from-primary"],
.fecx-main button[class*="from-primary"] {
  transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
}
/* Botón flotante de ayuda (chat) con glow de marca */
.fecx-main + button.fixed.bg-primary,
button.fixed.bottom-8.bg-primary {
  background: linear-gradient(135deg, var(--fecx-green-700), var(--fecx-green-500)) !important;
  box-shadow: 0 12px 30px rgba(0, 109, 49, 0.45) !important;
}

/* --- Foco de campos: anillo verde coherente en toda la app --- */
.fecx-main input:focus,
.fecx-main select:focus,
.fecx-main textarea:focus {
  outline: none;
  border-color: var(--fecx-green-500) !important;
  box-shadow: 0 0 0 3px rgba(31, 157, 77, 0.18) !important;
}

/* --- Encabezado de página (el "héroe" de cada vista): degradado verde --- */
.fecx-main h1 {
  background: linear-gradient(100deg, #0b3d22 0%, #0e7a39 55%, #1f9d4d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #0b3d22;            /* fallback si no hay soporte de clip */
  letter-spacing: -0.015em;
}

/* --- Encabezado de tabla con leve degradado para separar del cuerpo --- */
.fecx-main thead {
  background: linear-gradient(180deg, rgba(0, 109, 49, 0.06), rgba(0, 109, 49, 0.02)) !important;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .fecx-main a.bg-primary,
  .fecx-main button.bg-primary,
  .fecx-main a[class*="from-primary"],
  .fecx-main button[class*="from-primary"] { transition: none; }
}
