/* CHP - Tema de la aplicación */
/* Personaliza aquí los colores de la empresa */

:root {
    --color-primario: #2F5496;
    --color-secundario: #1a365d;
    --color-acento: #ed8936;
}

/* Transiciones suaves para interactividad */
.transition-smooth {
    transition: all 0.2s ease-in-out;
}

/* Animación de entrada suave para cards */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in-up {
    animation: fadeInUp 0.4s ease-out forwards;
}

/* Dashboard - Animaciones dinámicas */
@keyframes dashboardSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes dashboardPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.dashboard-card {
    animation: dashboardSlideIn 0.5s ease-out forwards;
}

.dashboard-card:nth-child(1) { animation-delay: 0.05s; }
.dashboard-card:nth-child(2) { animation-delay: 0.1s; }
.dashboard-card:nth-child(3) { animation-delay: 0.15s; }
.dashboard-card:nth-child(4) { animation-delay: 0.2s; }

.dashboard-card:hover .dashboard-icon {
    animation: float 2s ease-in-out infinite;
}

.dashboard-quick-link {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dashboard-quick-link:hover {
    transform: translateY(-4px) scale(1.02);
}

.dashboard-vendedor-item {
    transition: all 0.25s ease;
}

.dashboard-vendedor-item:hover {
    transform: translateX(6px);
}

/* CeCo - Centros de Operación - Animaciones dinámicas */
@keyframes cecoSlideIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes cecoGlow {
    0%, 100% { box-shadow: 0 0 20px rgba(47, 84, 150, 0.15); }
    50% { box-shadow: 0 0 30px rgba(47, 84, 150, 0.25); }
}

@keyframes cecoKpiPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.ceco-card {
    animation: cecoSlideIn 0.5s ease-out forwards;
}

.ceco-card:nth-child(1) { animation-delay: 0.03s; }
.ceco-card:nth-child(2) { animation-delay: 0.06s; }
.ceco-card:nth-child(3) { animation-delay: 0.09s; }
.ceco-card:nth-child(4) { animation-delay: 0.12s; }
.ceco-card:nth-child(5) { animation-delay: 0.15s; }
.ceco-card:nth-child(6) { animation-delay: 0.18s; }
.ceco-card:nth-child(7) { animation-delay: 0.21s; }
.ceco-card:nth-child(8) { animation-delay: 0.24s; }
.ceco-card:nth-child(9) { animation-delay: 0.27s; }

.ceco-kpi-card:hover {
    animation: cecoKpiPulse 0.6s ease-in-out;
}

.ceco-quick-action {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ceco-quick-action:hover {
    transform: translateY(-2px);
}

.ceco-row-animate {
    animation: cecoSlideIn 0.4s ease-out forwards;
}

/* Facturas - Animaciones dinámicas */
@keyframes facturasSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes facturasPulse {
    0%, 100% { border-color: rgba(47, 84, 150, 0.3); }
    50% { border-color: rgba(47, 84, 150, 0.6); }
}

.facturas-card {
    animation: facturasSlideIn 0.5s ease-out forwards;
}

.facturas-upload-zone {
    transition: all 0.3s ease;
}

.facturas-upload-zone:hover {
    border-color: rgba(47, 84, 150, 0.5);
    background: rgba(47, 84, 150, 0.03);
}

.facturas-upload-zone.dragover {
    border-color: #2F5496;
    background: rgba(47, 84, 150, 0.08);
}

/* Scrollbar invisible (funcionalidad mantiene, barra oculta) */
.scrollbar-hide {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}
.scrollbar-hide::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Sidebar - Diseño dinámico */
.sidebar-nav-link {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-nav-link:hover {
    transform: translateX(4px);
}

.sidebar-nav-link.active {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar-sub-link {
    transition: all 0.2s ease;
}

.sidebar-sub-link:hover {
    transform: translateX(6px);
}

.sidebar-module summary {
    transition: all 0.25s ease;
}

.sidebar-module summary:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Organización - Paneles dinámicos */
.org-panel-card {
    animation: dashboardSlideIn 0.5s ease-out forwards;
}

.org-panel-card:nth-child(1) { animation-delay: 0.05s; }
.org-panel-card:nth-child(2) { animation-delay: 0.1s; }
.org-panel-card:nth-child(3) { animation-delay: 0.15s; }
.org-panel-card:nth-child(4) { animation-delay: 0.2s; }

.org-table-row {
    transition: all 0.2s ease;
}

.org-table-row:hover {
    background: rgba(47, 84, 150, 0.05) !important;
}

/* Sobre pedidos y Directos - Botones tipo plantilla (Contado/Crédito) */
@keyframes btnTipoIconPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1.05); }
}

.btn-tipo-plantilla[data-disponible="true"] {
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-tipo-plantilla[data-disponible="true"]:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 12px 28px -8px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.btn-tipo-plantilla[data-tipo="contado"][data-disponible="true"]:hover {
    box-shadow: 0 12px 28px -8px rgba(47, 84, 150, 0.25), 0 0 0 2px rgba(47, 84, 150, 0.2);
}

.btn-tipo-plantilla[data-tipo="credito"][data-disponible="true"]:hover {
    box-shadow: 0 12px 28px -8px rgba(237, 137, 54, 0.3), 0 0 0 2px rgba(237, 137, 54, 0.2);
}

.btn-tipo-plantilla[data-disponible="true"]:hover .btn-tipo-icon {
    animation: btnTipoIconPop 0.4s ease-out forwards;
}

.btn-tipo-circle {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Check visible: Contado = azul, Crédito = ámbar (el botón tiene text-white que hereda) */
.btn-tipo-circle.border-empresa-primario .btn-tipo-check {
    color: #2F5496 !important;
    fill: currentColor;
}

.btn-tipo-plantilla[data-disponible="true"]:hover .btn-tipo-circle {
    transform: scale(1.1);
}

/* Texto blanco cuando el tipo de pedido está seleccionado */
.btn-tipo-plantilla.ring-empresa-primario .flex-1 span,
.btn-tipo-plantilla.ring-empresa-acento .flex-1 span {
    color: white !important;
}

/* Clase de pedido (Sobrepedido / Directo) */
.btn-clase-pedido {
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-clase-pedido:not(.ring-2):hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.12);
}

.btn-clase-pedido[data-clase="sobrepedido"]:not(.ring-2):hover {
    box-shadow: 0 10px 24px -8px rgba(71, 85, 105, 0.2);
}

.btn-clase-pedido[data-clase="directo"]:not(.ring-2):hover {
    box-shadow: 0 10px 24px -8px rgba(14, 165, 233, 0.25);
}

/* Sidebar colapsable */
.sidebar.sidebar-collapsed {
    width: 0;
    min-width: 0;
    padding: 0;
    margin: 0;
    border: none;
}

/* Responsive: sidebar móvil como overlay */
@media (max-width: 1023px) {
    .sidebar {
        box-shadow: 8px 0 24px rgba(0, 0, 0, 0.15);
    }
    .sidebar.sidebar-collapsed {
        /* En móvil no usamos collapsed, usamos translate */
        width: 16rem;
        min-width: 16rem;
    }
}

/* Canvas firma: mantiene proporción en móvil */
#firma-canvas {
    max-width: 100%;
    min-height: 120px;
}

/* ============================================
   TABLAS RESPONSIVAS - Cards en móvil
   ============================================ */

/* Tabla: oculta en móvil, visible en md+ */
.table-desktop {
    display: none;
}
@media (min-width: 768px) {
    .table-desktop {
        display: table;
    }
}

/* Cards móvil: visibles solo en móvil */
.table-mobile-cards {
    display: block;
}
@media (min-width: 768px) {
    .table-mobile-cards {
        display: none;
    }
}

/* Estilo de cada card en móvil */
.mobile-pedido-card {
    border-bottom: 1px solid #e5e7eb;
}
.mobile-pedido-card:last-child {
    border-bottom: none;
}

/* Dropdown de acciones en móvil */
.mobile-actions-dropdown {
    position: relative;
}
.mobile-actions-menu {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.25rem;
    min-width: 12rem;
    z-index: 20;
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px -10px rgba(0,0,0,0.2);
    border: 1px solid #e5e7eb;
}
.mobile-actions-menu[aria-hidden="true"] {
    display: none;
}
.mobile-actions-menu a,
.mobile-actions-menu button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.625rem 1rem;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 500;
    background: white;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}
.mobile-actions-menu a:first-child,
.mobile-actions-menu button:first-child {
    border-radius: 0.75rem 0.75rem 0 0;
}
.mobile-actions-menu a:hover,
.mobile-actions-menu button:hover {
    background: #f8fafc;
}
.mobile-actions-menu a.text-red-600:hover,
.mobile-actions-menu button.text-red-600:hover {
    background: #fef2f2;
}

/* ============================================
   FORMULARIOS - Mensajes de error inline
   ============================================ */

/* Campo con error */
.form-input.border-red-300 {
    border-color: #fca5a5;
}
.form-input.border-red-300:focus {
    ring-color: rgba(239, 68, 68, 0.3);
}

/* Header superior - diseño dinámico (azul acorde al sistema) */
.header-top {
    background: linear-gradient(135deg, #1a365d 0%, #1f79e7 50%, #052a55 100%);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(47, 84, 150, 0.12);
}

/* Avatar dropdown - botón y menú */
.header-avatar-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.header-avatar-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(47, 84, 150, 0.15);
}

.header-dropdown-menu {
    animation: dropdownSlideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    transform-origin: top right;
}
@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.header-dropdown-item {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.header-dropdown-item:hover {
    transform: translateX(4px);
}
.header-dropdown-item:not([href*="logout"]):hover {
    background: linear-gradient(90deg, rgba(47, 84, 150, 0.08) 0%, transparent 100%) !important;
}
.header-dropdown-item[href*="logout"]:hover {
    background: linear-gradient(90deg, rgba(220, 38, 38, 0.06) 0%, transparent 100%) !important;
}
.header-dropdown-item:hover .header-dropdown-icon {
    transform: scale(1.1);
}
.header-dropdown-item:not([href*="logout"]):hover .header-dropdown-icon {
    color: #2F5496;
}
.header-dropdown-item[href*="logout"]:hover .header-dropdown-icon {
    color: #dc2626;
}
.header-dropdown-icon {
    transition: all 0.2s ease;
}

/* ============================================
   FEEDBACK VISUAL Y MICROINTERACCIONES
   ============================================ */

/* Botones: feedback al hacer clic y focus visible */
.btn-interactive {
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.btn-interactive:active {
    transform: scale(0.97);
}
.btn-interactive:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--color-primario);
}

/* Aplicar feedback a botones dentro del contenido principal */
main button:not([disabled]),
main a.inline-flex[href] {
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}
main button:not([disabled]):active,
main a.inline-flex[href]:active {
    transform: scale(0.97);
}
main button:focus-visible,
main a.inline-flex[href]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--color-primario);
}

/* Links y elementos clickeables con feedback sutil */
.clickable-feedback {
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.clickable-feedback:active {
    opacity: 0.9;
}

/* Inputs: transición suave al enfocar */
.input-feedback {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input-feedback:focus {
    transition-duration: 0.15s;
}

/* Inputs en formularios: transición al enfocar */
main input, main select, main textarea {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Header: feedback en botón toggle */
#sidebar-toggle {
    transition: transform 0.15s ease;
}
#sidebar-toggle:active {
    transform: scale(0.95);
}
#sidebar-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--color-primario);
}

/* Skeleton loading - efecto shimmer */
@keyframes skeletonShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        #f1f5f9 25%,
        #e2e8f0 50%,
        #f1f5f9 75%
    );
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
}
.skeleton-text:last-child {
    width: 60%;
    margin-bottom: 0;
}

.skeleton-card {
    height: 8rem;
}

.skeleton-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 9999px;
}

/* Toast / Flash messages - animación de entrada */
@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

.flash-toast {
    animation: toastSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    transition: opacity 0.25s ease;
}
.flash-toast.dismissing {
    animation: toastSlideOut 0.25s ease forwards;
}

.flash-toast-close {
    transition: opacity 0.2s ease, background-color 0.2s ease;
}
.flash-toast-close:hover {
    opacity: 0.8;
}
.flash-toast-close:active {
    transform: scale(0.95);
}

/* ============================================
   MODALES - Animaciones y UX
   ============================================ */

/* Overlay: transición suave de entrada/salida */
.modal-overlay {
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.modal-overlay.modal-closed {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.modal-overlay.modal-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Contenido del modal: escala y fade */
.modal-dialog {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-overlay.modal-closed .modal-dialog {
    transform: scale(0.96);
    opacity: 0;
}
.modal-overlay.modal-open .modal-dialog {
    transform: scale(1);
    opacity: 1;
}

/* Backdrop: transición suave */
.modal-backdrop {
    transition: opacity 0.2s ease;
}

/* Botón cerrar: feedback al hacer clic (hover lo define cada template) */
.modal-close-btn {
    transition: transform 0.15s ease, background-color 0.2s ease;
}
.modal-close-btn:active {
    transform: scale(0.92);
}
.modal-close-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--color-primario);
}

/* ============================================
   MODAL ÉXITO PEDIDO - Animación dinámica
   ============================================ */

.modal-exito-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-exito-overlay.modal-exito-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-exito-backdrop {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.85) 0%, rgba(5, 150, 105, 0.9) 50%, rgba(4, 120, 87, 0.95) 100%);
    backdrop-filter: blur(8px);
    animation: modalExitoBackdropIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.modal-exito-overlay.modal-exito-salida .modal-exito-backdrop {
    animation: modalExitoBackdropOut 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.modal-exito-content {
    position: relative;
    z-index: 1;
    text-align: center;
    animation: modalExitoContentIn 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}
.modal-exito-overlay.modal-exito-salida .modal-exito-content {
    animation: modalExitoContentOut 0.45s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.modal-exito-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.modal-exito-imagen {
    width: 360px;
    height: 360px;
    object-fit: contain;
    filter: drop-shadow(0 10px 25px rgba(0, 0, 0, 0.25));
    animation: modalExitoImagenBounce 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both,
               modalExitoImagenPulse 2s ease-in-out 1.2s infinite;
}

.modal-exito-titulo {
    font-size: 1.75rem;
    font-weight: 800;
    color: white;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    margin: 0;
    letter-spacing: -0.02em;
    animation: modalExitoTextIn 0.5s ease-out 0.5s both;
}

.modal-exito-texto {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.95);
    margin: 0;
    font-weight: 500;
    animation: modalExitoTextIn 0.5s ease-out 0.6s both;
}

@keyframes modalExitoBackdropIn {
    from {
        opacity: 0;
        transform: scale(1.1);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modalExitoBackdropOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(1.05);
    }
}

@keyframes modalExitoContentIn {
    from {
        opacity: 0;
        transform: scale(0.3) translateY(30px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes modalExitoContentOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
}

@keyframes modalExitoImagenBounce {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-15deg);
    }
    60% {
        opacity: 1;
        transform: scale(1.15) rotate(5deg);
    }
    80% {
        transform: scale(0.95) rotate(-2deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0);
    }
}

@keyframes modalExitoImagenPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes modalExitoTextIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
