/* ===================================
   SHARED.CSS - LIMPIADO Y OPTIMIZADO
   Removidos: utilidades no usadas, estados duplicados, animaciones innecesarias
   =================================== */

/* Reset y Variables Consolidadas */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colores Principales - Consolidados */
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --secondary: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    /* Colores Neutros */
    --white: #ffffff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    
    /* Colores de accesibilidad */
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    --focus-ring: rgba(79, 70, 229, 0.2);
    --error-bg: #fef2f2;
    --success-bg: #f0fdf4;
    --warning-bg: #fffbeb;
    
    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    
    /* Bordes */
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    
    /* Espaciado consistente */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Thumb zones para móvil */
    --touch-target: 48px;
    --touch-target-lg: 56px;
    
    /* Tipografía */
    --font-sans: 'Inter', system-ui, sans-serif;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* Base Styles */
body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    line-height: 1.6;
    color: var(--text-primary);
    font-weight: 400;
    font-size: var(--text-base);
}

/* Header Compartido */
.main-header {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--gray-200);
    padding: var(--space-lg) 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: var(--text-2xl);
    font-weight: 800;
    color: var(--primary);
    margin-bottom: var(--space-xs);
}

.header-content p {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    color: var(--text-primary);
    font-weight: 600;
    font-size: var(--text-sm);
}

/* Botón Admin */
.admin-link {
    background: var(--primary);
    color: var(--white);
    text-decoration: none;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: var(--text-sm);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    box-shadow: var(--shadow);
}

.admin-link:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.admin-link:focus {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

/* Paneles Compartidos */
.panel {
    background: var(--white);
    border-radius: var(--radius-xl);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    margin-bottom: var(--space-xl);
}

.panel-header {
    background: linear-gradient(135deg, var(--gray-50) 0%, var(--white) 100%);
    border-bottom: 1px solid var(--gray-200);
    padding: var(--space-xl);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Formularios Compartidos */
.form-group {
    margin-bottom: var(--space-lg);
    position: relative;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
    font-size: var(--text-sm);
}

.form-group label.required::after {
    content: " *";
    color: var(--danger);
    font-weight: 700;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: var(--space-md);
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-lg);
    font-size: var(--text-base);
    transition: all 0.2s ease;
    background: var(--white);
    color: var(--text-primary);
    min-height: var(--touch-target);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--focus-ring);
    transform: scale(1.01);
}

.form-group input:invalid:not(.no-validation) {
    border-color: var(--danger);
    background: var(--error-bg);
}

.form-group input:valid:not(.no-validation) {
    border-color: var(--success);
    background: var(--success-bg);
}

/* Campos sin validación visual - mantener estilo neutro */
.form-group input.no-validation {
    border-color: var(--input-border);
    background: var(--white);
}

/* Opcional: mostrar verde suave cuando tiene contenido */
.form-group input.no-validation:not(:placeholder-shown) {
    border-color: var(--success);
    background: var(--success-bg);
}

.form-group input[readonly] {
    background: var(--gray-50);
    color: var(--text-muted);
}

.help-text {
    display: block;
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-sm);
    font-style: italic;
}

.field-error {
    color: var(--danger);
    font-size: var(--text-xs);
    margin-top: var(--space-xs);
    font-weight: 600;
}

/* Botones Compartidos */
.btn {
    padding: var(--space-lg) var(--space-xl);
    border: none;
    border-radius: var(--radius-lg);
    font-weight: 700;
    font-size: var(--text-base);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    min-height: var(--touch-target-lg);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:focus {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
}

.btn-warning {
    background: linear-gradient(135deg, var(--warning) 0%, #d97706 100%);
    color: var(--white);
}

.btn-info {
    background: linear-gradient(135deg, var(--info) 0%, #1e40af 100%);
    color: var(--white);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
    color: var(--white);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--gray-500) 0%, var(--gray-600) 100%);
    color: var(--white);
}

.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    color: var(--white);
}

.btn-sm {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--text-sm);
    min-height: var(--touch-target);
}

/* Estados de Badge */
.estado-badge {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.estado-badge.sin-datos {
    background: var(--gray-200);
    color: var(--gray-600);
}

.estado-badge.activo {
    background: var(--success);
    color: var(--white);
}

.estado-badge.alerta {
    background: var(--warning);
    color: var(--white);
}

.estado-badge.critico {
    background: var(--danger);
    color: var(--white);
}

/* Galpones Cards */
.galpones-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-lg);
    padding: var(--space-xl);
}

.galpon-card {
    background: var(--white);
    border-radius: var(--radius-xl);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
}

.galpon-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
}

.galpon-header {
    background: linear-gradient(135deg, #14b8a6 0%, #06b6d4 100%);
    color: var(--white);
    padding: var(--space-xl);
    text-align: center;
    border-radius: 8px 8px 0 0;
}

.galpon-header h3 {
    font-size: var(--text-lg);
    font-weight: 600;
}

.galpon-stats {
    padding: var(--space-xl);
}

.galpon-stat {
    text-align: center;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--gray-200);
}

.galpon-stat .stat-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--space-xs);
}

.galpon-stat .stat-label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    font-weight: 500;
}

.galpon-detail > *:not(:last-child) {
    margin-bottom: var(--space-sm);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
    font-size: var(--text-sm);
    border-bottom: 1px solid var(--gray-100);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Modal Compartido */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background: var(--white);
    margin: 5% auto;
    padding: 0;
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 800px; /* Aumentado para facturas */
    max-height: 90vh; /* Limitar altura al 90% del viewport */
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Modal específico para facturas grandes */
.modal-content.modal-factura {
    max-width: 900px;
    margin: 2% auto; /* Menos margen superior */
}

.modal-header {
    background: var(--primary);
    color: var(--white);
    padding: var(--space-xl);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    flex-shrink: 0; /* No reducir el header */
}

.modal-close {
    font-size: var(--text-xl);
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    opacity: 1;
}

.modal-body {
    padding: var(--space-xl);
    overflow-y: auto; /* Permitir scroll vertical */
    flex: 1; /* Ocupar el espacio disponible */
    max-height: calc(90vh - 200px); /* Altura máxima considerando header y footer */
}

.modal-footer {
    padding: var(--space-lg) var(--space-xl);
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: var(--space-md);
    justify-content: flex-end;
}

/* Estados Vacíos */
.no-data {
    text-align: center;
    padding: var(--space-2xl);
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--gray-300);
}

.no-data h3 {
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    font-size: var(--text-lg);
}

.no-data p {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

/* Alertas */
.alerta {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    border-radius: var(--radius-lg);
    border-left: 4px solid;
}

.alerta-critico {
    background: var(--error-bg);
    border-color: var(--danger);
    color: #991b1b;
}

.alerta-alerta {
    background: var(--warning-bg);
    border-color: var(--warning);
    color: #92400e;
}

.alerta-info {
    background: #eff6ff;
    border-color: var(--info);
    color: #1e40af;
}

.alerta-icon {
    font-size: var(--text-xl);
    flex-shrink: 0;
}

.alerta-content h4 {
    margin-bottom: var(--space-sm);
    font-size: var(--text-base);
    font-weight: 600;
}

.alerta-content p {
    margin-bottom: var(--space-xs);
    font-size: var(--text-sm);
}

.alerta-content small {
    opacity: 0.8;
}

/* Responsive Base */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: var(--space-md);
        text-align: center;
    }
    
    .header-content h1 {
        font-size: var(--text-xl);
    }
    
    .galpones-grid {
        grid-template-columns: 1fr;
        padding: var(--space-lg);
    }

    .panel-header {
        flex-direction: column;
        gap: var(--space-md);
        text-align: center;
    }
}

@media (max-width: 480px) {
    :root {
        --space-md: 0.75rem;
        --space-lg: 1rem;
        --space-xl: 1.5rem;
    }
    
    .panel-header {
        padding: var(--space-lg);
    }
    
    .form-group {
        margin-bottom: var(--space-md);
    }

    .modal-content {
        margin: 5% auto;
        max-width: 95%;
    }

    .modal-header,
    .modal-body {
        padding: var(--space-lg);
    }
}

/* ===================================
   BADGES PARA HISTÓRICO DE PRODUCCIÓN
   Idénticos al V9 para 100% compatibilidad visual
   =================================== */

/* Badge base */
.badge-viabilidad,
.badge-postura {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    min-width: 45px;
    color: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Badges de Viabilidad */
.badge-viabilidad.alta {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.85) 0%, rgba(5, 150, 105, 0.85) 100%);
}

.badge-viabilidad.media {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.85) 0%, rgba(217, 119, 6, 0.85) 100%);
}

.badge-viabilidad.baja {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.85) 0%, rgba(220, 38, 38, 0.85) 100%);
}

/* Badges de Postura */
.badge-postura.alta {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.85) 0%, rgba(5, 150, 105, 0.85) 100%);
}

.badge-postura.media {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.85) 0%, rgba(217, 119, 6, 0.85) 100%);
}

.badge-postura.baja {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.85) 0%, rgba(220, 38, 38, 0.85) 100%);
}

/* ===================================
   SISTEMA DE NOTIFICACIONES TOAST
   =================================== */

#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background: white;
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.1);
    min-width: 320px;
    max-width: 450px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    animation: slideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border-left: 4px solid var(--toast-color);
}

.toast.hiding {
    animation: slideOut 0.3s ease-out forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.toast-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toast-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--gray-900);
    line-height: 1.4;
}

.toast-message {
    font-size: 14px;
    color: var(--gray-600);
    line-height: 1.5;
    white-space: pre-line;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 18px;
}

.toast-close:hover {
    background: var(--gray-100);
    color: var(--gray-600);
}

/* Tipos de Toast */
.toast.error {
    --toast-color: #ef4444;
    border-left-color: #ef4444;
}

.toast.error .toast-icon {
    color: #ef4444;
}

.toast.success {
    --toast-color: #10b981;
    border-left-color: #10b981;
}

.toast.success .toast-icon {
    color: #10b981;
}

.toast.warning {
    --toast-color: #f59e0b;
    border-left-color: #f59e0b;
}

.toast.warning .toast-icon {
    color: #f59e0b;
}

.toast.info {
    --toast-color: #3b82f6;
    border-left-color: #3b82f6;
}

.toast.info .toast-icon {
    color: #3b82f6;
}

/* Responsive */
@media (max-width: 640px) {
    #toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: auto;
        max-width: none;
    }
}