/* 
 * Sistema de componentes UI mejorado para ERP-Koud
 * Incluye estados de carga, feedback visual y diseño responsivo
 */

/* ===== Variables de diseño mejoradas ===== */
:root {
    /* Colores principales */
    --primary: #2C3E50;
    --primary-light: #34495E;
    --primary-dark: #1A252F;
    --secondary: #3498DB;
    --success: #27AE60;
    --danger: #E74C3C;
    --warning: #F39C12;
    --info: #3498DB;
    
    /* Colores neutros */
    --gray-100: #F8F9FA;
    --gray-200: #E9ECEF;
    --gray-300: #DEE2E6;
    --gray-400: #CED4DA;
    --gray-500: #ADB5BD;
    --gray-600: #6C757D;
    --gray-700: #495057;
    --gray-800: #343A40;
    --gray-900: #212529;
    
    /* Espaciado */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-xxl: 3rem;
    
    /* Animaciones */
    --transition-fast: 150ms ease-in-out;
    --transition-normal: 300ms ease-in-out;
    --transition-slow: 500ms ease-in-out;
    
    /* Sombras */
    --shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --shadow-md: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 1rem 3rem rgba(0, 0, 0, 0.175);
    
    /* Bordes */
    --border-radius-sm: 0.25rem;
    --border-radius-md: 0.5rem;
    --border-radius-lg: 1rem;
    --border-radius-pill: 50rem;
}

/* ===== Modo oscuro mejorado ===== */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3a3a3a;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #404040;
    
    /* Ajuste de colores para modo oscuro */
    --primary: #3498DB;
    --primary-light: #5DADE2;
    --primary-dark: #2874A6;
}

/* ===== Skeleton Loading ===== */
.skeleton {
    background: linear-gradient(90deg, 
        var(--gray-200) 25%, 
        var(--gray-300) 50%, 
        var(--gray-200) 75%
    );
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: var(--border-radius-sm);
}

.skeleton-text {
    height: 1rem;
    margin-bottom: var(--spacing-sm);
    width: 100%;
}

.skeleton-title {
    height: 1.5rem;
    margin-bottom: var(--spacing-md);
    width: 60%;
}

.skeleton-button {
    height: 2.5rem;
    width: 6rem;
    border-radius: var(--border-radius-md);
}

.skeleton-avatar {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
}

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

/* ===== Loading States ===== */
.loading-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-spinner.lg {
    width: 2rem;
    height: 2rem;
    border-width: 3px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Loading overlay mejorado */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-content {
    background: white;
    padding: var(--spacing-xl);
    border-radius: var(--border-radius-lg);
    text-align: center;
    box-shadow: var(--shadow-lg);
}

[data-theme="dark"] .loading-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ===== Progress Indicators ===== */
.progress-steps {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--spacing-xl);
    counter-reset: step;
}

.progress-step {
    flex: 1;
    text-align: center;
    position: relative;
}

.progress-step::before {
    counter-increment: step;
    content: counter(step);
    display: inline-block;
    width: 2.5rem;
    height: 2.5rem;
    line-height: 2.5rem;
    background: var(--gray-300);
    color: var(--gray-600);
    border-radius: 50%;
    margin-bottom: var(--spacing-sm);
    transition: all var(--transition-normal);
}

.progress-step.active::before {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

.progress-step.completed::before {
    content: "✓";
    background: var(--success);
    color: white;
}

.progress-step:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 1.25rem;
    left: 50%;
    width: 100%;
    height: 2px;
    background: var(--gray-300);
    z-index: -1;
}

.progress-step.completed:not(:last-child)::after {
    background: var(--success);
}

/* ===== Enhanced Buttons ===== */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 1rem;
    height: 1rem;
    top: 50%;
    left: 50%;
    margin-left: -0.5rem;
    margin-top: -0.5rem;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Ripple effect */
.btn {
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

/* ===== Improved Cards ===== */
.card {
    transition: all var(--transition-normal);
    border: 1px solid var(--gray-200);
}

.card-interactive {
    cursor: pointer;
}

.card-interactive:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card-loading {
    position: relative;
    min-height: 200px;
}

.card-loading::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Enhanced Tables ===== */
.table-responsive-stack {
    width: 100%;
}

@media (max-width: 768px) {
    .table-responsive-stack tr {
        display: block;
        border: 1px solid var(--gray-300);
        margin-bottom: var(--spacing-md);
        border-radius: var(--border-radius-md);
    }
    
    .table-responsive-stack td {
        display: block;
        text-align: right;
        padding-left: 50%;
        position: relative;
        border: none;
    }
    
    .table-responsive-stack td::before {
        content: attr(data-label);
        position: absolute;
        left: var(--spacing-md);
        font-weight: bold;
        text-align: left;
    }
    
    .table-responsive-stack thead {
        display: none;
    }
}

/* ===== Floating Action Button ===== */
.fab-container {
    position: fixed;
    bottom: var(--spacing-xl);
    right: var(--spacing-xl);
    z-index: 1000;
}

.fab {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
    cursor: pointer;
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.fab:active {
    transform: scale(0.95);
}

/* ===== Toast Notifications Mejoradas ===== */
.toast-container {
    position: fixed;
    top: var(--spacing-xl);
    right: var(--spacing-xl);
    z-index: 9999;
    max-width: 350px;
}

.toast {
    background: white;
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--spacing-md);
    overflow: hidden;
    animation: slideIn 0.3s ease-out;
    transition: all var(--transition-normal);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-header {
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toast-body {
    padding: var(--spacing-md);
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.info {
    border-left: 4px solid var(--info);
}

/* ===== Empty States ===== */
.empty-state {
    text-align: center;
    padding: var(--spacing-xxl);
}

.empty-state-icon {
    font-size: 4rem;
    color: var(--gray-400);
    margin-bottom: var(--spacing-lg);
}

.empty-state-title {
    font-size: 1.5rem;
    color: var(--gray-700);
    margin-bottom: var(--spacing-md);
}

.empty-state-description {
    color: var(--gray-600);
    margin-bottom: var(--spacing-xl);
}

/* ===== Breadcrumbs ===== */
.breadcrumb {
    background: transparent;
    padding: 0;
    margin-bottom: var(--spacing-lg);
    font-size: 0.875rem;
}

.breadcrumb-item + .breadcrumb-item::before {
    content: "›";
    font-weight: bold;
    padding: 0 var(--spacing-sm);
}

/* ===== Focus States ===== */
:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(44, 62, 80, 0.25);
}

/* ===== Accessibility ===== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: var(--spacing-sm) var(--spacing-md);
    text-decoration: none;
    border-radius: var(--border-radius-sm);
}

.skip-link:focus {
    top: 0;
}

/* ===== Responsive Utilities ===== */
@media (max-width: 576px) {
    .hide-mobile { display: none !important; }
}

@media (min-width: 577px) and (max-width: 768px) {
    .hide-tablet { display: none !important; }
}

@media (min-width: 769px) {
    .hide-desktop { display: none !important; }
}

/* ===== Print Styles ===== */
@media print {
    .no-print { display: none !important; }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
    }
    
    a { text-decoration: none; }
    
    .card {
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }
}