/* APLIUM CORE DESIGN SYSTEM - PREMIUM & HARMONIZED 2.0 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=Outfit:wght@700;800;900&display=swap');

:root {
    /* Brand Colors - High Vibrancy */
    --aplium-green: #10b981;
    --aplium-green-hover: #059669;
    --aplium-green-soft: rgba(16, 185, 129, 0.1);
    
    /* Neutral Palette - Deep Lux */
    --aplium-bg-light: #f3f4f6;
    --aplium-bg-dark: #05070a;
    
    /* Layout Tokens */
    --card-radius: 28px;
    --btn-radius: 16px;
    
    /* Glassmorphism Defaults */
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
}

:root.dark {
    --glass-bg: rgba(15, 23, 42, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

/* Global Foundations */
body {
    font-family: 'Inter', sans-serif;
    -webkit-font-smoothing: antialiased;
    background-color: var(--aplium-bg-light);
    color: #1e293b;
    overflow-x: hidden;
}

.dark body {
    background-color: var(--aplium-bg-dark);
    color: #f8fafc;
}

/* Fallback global genérico para inputs en modo oscuro para evitar colores oscuros sobre fondos oscuros */
.dark input:not([type="radio"]):not([type="checkbox"]), 
.dark select, 
.dark textarea {
    color: #f8fafc;
}

h1, h2, h3, .font-heading {
    font-family: 'Outfit', sans-serif !important;
    letter-spacing: -0.03em;
}

/* Background Aesthetics */
.a-plium-bg {
    background: var(--aplium-bg-light) !important;
    position: relative;
}

.dark .a-plium-bg {
    background: var(--aplium-bg-dark) !important;
}

.a-plium-bg::before {
    content: "";
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: 
        radial-gradient(circle at 10% 20%, rgba(16, 185, 129, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.03) 0%, transparent 40%);
    pointer-events: none;
    z-index: -1;
}

/* Premium Cards */
.aplium-card {
    background: var(--glass-bg) !important;
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--card-radius) !important;
    box-shadow: var(--glass-shadow) !important;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.aplium-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.1);
}

.dark .aplium-card:hover {
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.5);
    border-color: rgba(16, 185, 129, 0.2) !important;
}

/* Form LUX Elements - Potent Visibility & High Definition */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
    width: 100% !important;
    background: #ffffff !important; /* Pure White for maximum contrast */
    color: #000000 !important; /* Pure Black for typed text */
    border: 1.5px solid #e2e8f0 !important;
    border-radius: 16px !important;
    padding: 0.85rem 1.25rem;
    font-family: 'Inter', system-ui, -apple-system, sans-serif !important; /* Hardened font-family stack */
    font-size: 0.95rem !important;
    font-weight: 500 !important; /* Slightly more weight for better definition */
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04) !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* Specific rule for placeholders to keep them SOFT GREY */
input::placeholder, textarea::placeholder {
    color: #94a3b8 !important; /* Soft Slate-400 placeholder */
    opacity: 1 !important;
    font-weight: 400 !important;
}

/* Dynamic change: apply grey color ONLY when showing placeholder */
input:placeholder-shown, textarea:placeholder-shown {
    color: #94a3b8 !important;
}

.dark input:not([type="checkbox"]):not([type="radio"]), .dark select, .dark textarea {
    background: #0f172a !important;
    border: 1.5px solid rgba(255, 255, 255, 0.15) !important;
    color: #ffffff !important; /* Pure White in dark mode */
    box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.3) !important;
    color-scheme: dark; /* Force native webkit elements (like calendar icons) to dark mode */
}

input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
    background: #ffffff !important;
    border-color: var(--aplium-green) !important;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12) !important;
    color: #000000 !important; /* Keep it Pure Black on focus */
    outline: none !important;
    transform: scale(1.01);
}

.dark input:not([type="checkbox"]):not([type="radio"]):focus, .dark select:focus, .dark textarea:focus {
    background: #0f172a !important;
    border-color: var(--aplium-green) !important;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2) !important;
    color: #ffffff !important; /* Preserve Pure White on focus in dark mode */
}

input::placeholder, textarea::placeholder {
    color: #64748b !important; /* Stronger Slate-500 for better visibility */
    opacity: 0.8 !important;
    font-weight: 600 !important; /* Same weight as value to avoid dizzying jumps */
}

.dark input::placeholder, .dark textarea::placeholder {
    color: #94a3b8 !important; /* Lighter slate for dark mode readability */
    opacity: 0.4 !important;
}

/* Typography Harmony */
h1, h2, h3, h4 {
    letter-spacing: -0.02em;
}

/* Date Input Internal Styling Fix - Unified weight and color */
input[type="date"]::-webkit-datetime-edit,
input[type="date"]::-webkit-datetime-edit-fields-wrapper,
input[type="date"]::-webkit-datetime-edit-day-field,
input[type="date"]::-webkit-datetime-edit-month-field,
input[type="date"]::-webkit-datetime-edit-year-field,
input[type="date"]::-webkit-datetime-edit-text {
    font-weight: 400 !important;
    color: #000000 !important; /* Pure Black for readability, matching other fields */
    font-family: 'Inter', sans-serif !important;
}

.dark input[type="date"]::-webkit-datetime-edit,
.dark input[type="date"]::-webkit-datetime-edit-fields-wrapper,
.dark input[type="date"]::-webkit-datetime-edit-day-field,
.dark input[type="date"]::-webkit-datetime-edit-month-field,
.dark input[type="date"]::-webkit-datetime-edit-year-field,
.dark input[type="date"]::-webkit-datetime-edit-text {
    color: #ffffff !important; /* Pure White for dark mode readability */
}

label {
    display: block !important;
    margin-bottom: 1.5rem;
}

label span {
    font-size: 11px !important;
    font-weight: 800 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.08em !important;
    color: var(--text-muted) !important;
    margin-left: 4px;
    margin-bottom: 8px;
    display: block !important;
}

/* Normalizar autocompletado del navegador (Fix para Edge/Chrome/Safari) */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0px 1000px var(--input-bg) inset !important;
    -webkit-text-fill-color: var(--text-main) !important;
    color: var(--text-main) !important;
    caret-color: var(--text-main) !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* Buttons harmony */
.aplium-btn {
    background: var(--surface-bg) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--card-border) !important;
    border-radius: 14px !important;
    padding: 0.75rem 1.25rem;
    font-weight: 700 !important;
    font-size: 0.875rem !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 1rem;
    cursor: pointer;
}

.aplium-btn-center {
    justify-content: center !important;
}

/* Sidebar Specific - Fixed height to avoid jumps */
.aplium-sidebar-btn {
    height: 52px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 1rem !important;
    padding: 0 1.25rem !important;
    border-radius: 14px !important;
    border: 1px solid transparent !important;
    width: 100% !important;
    transition: all 0.2s ease !important;
    cursor: pointer;
    box-sizing: border-box !important;
}

.aplium-sidebar-btn-inactive {
    background: transparent !important;
    border-color: transparent !important;
    color: var(--text-main) !important;
    font-weight: 600 !important;
    opacity: 0.7;
}

.aplium-sidebar-btn-inactive:hover {
    background: var(--aplium-green-soft) !important;
    color: var(--aplium-green) !important;
}

.aplium-sidebar-btn-active {
    background: var(--aplium-green) !important;
    color: white !important;
    font-weight: 800 !important;
    box-shadow: 0 10px 15px -3px rgba(22, 163, 74, 0.2) !important;
    border-color: var(--aplium-green) !important;
}

.aplium-sidebar-btn-danger {
    background: transparent !important;
    border-color: transparent !important;
    color: #ef4444 !important; /* text-red-500 */
    font-weight: 700 !important;
}

.aplium-sidebar-btn-danger:hover {
    background: rgba(239, 68, 68, 0.1) !important;
    color: #dc2626 !important; /* text-red-600 */
}

/* Red version for Investigation button if preferred */
.aplium-sidebar-btn-investigation {
    background: transparent !important;
    border-color: transparent !important;
    color: #ef4444 !important;
    font-weight: 700 !important;
}

.aplium-sidebar-btn-investigation:hover {
    background: rgba(239, 68, 68, 0.1) !important;
    color: #dc2626 !important;
}

.aplium-btn:hover {
    background: var(--aplium-slate-50) !important;
    border-color: var(--aplium-green) !important;
    color: var(--aplium-green) !important;
    transform: translateY(-1px);
}

.aplium-primary {
    background: linear-gradient(135deg, var(--aplium-green), var(--aplium-green-hover)) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--btn-radius) !important;
    font-weight: 800 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    padding: 1rem 1.5rem !important;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3) !important;
}

.aplium-primary::after {
    content: "";
    position: absolute;
    top: -50%; left: -50%; width: 200%; height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255,255,255,0.1), transparent);
    transform: rotate(45deg);
    transition: 0.6s;
}

.aplium-primary:hover::after {
    left: 120%;
}

/* Tables Harmony */
.aplium-table-container {
    background: var(--surface-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    overflow: hidden;
}

/* Fix definitivo para el selector de idioma: Edge + Modo Oscuro */
#langSelect {
    display: inline-block !important;
    width: auto !important;
    min-width: 90px !important;
    height: 40px !important;
    padding: 0 32px 0 12px !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    color: var(--text-main) !important;
    background-color: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    border-radius: 12px !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    background-size: 12px !important;
    cursor: pointer !important;
    line-height: normal !important;
    vertical-align: middle !important;
    box-sizing: border-box !important;
    text-align: left !important;
    outline: none !important;
}

#langSelect:hover {
    border-color: var(--aplium-green) !important;
}

#langSelect option {
    background: var(--surface-bg) !important;
    color: var(--text-main) !important;
    padding: 10px !important;
}

.aplium-table thead th {
    background: var(--aplium-slate-50) !important;
    padding: 1rem 1.5rem !important;
    font-size: 11px !important;
    font-weight: 900 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.1em !important;
    color: var(--text-muted) !important;
    border-bottom: 1px solid var(--card-border) !important;
}

:root.dark .aplium-table thead th {
    background: rgba(255, 255, 255, 0.03) !important;
}

.aplium-table tbody td {
    padding: 1.25rem 1.5rem !important;
    border-bottom: 1px solid var(--card-border) !important;
    font-size: 0.95rem !important;
    color: var(--text-main) !important;
}

.aplium-table tbody tr:last-child td {
    border-bottom: none !important;
}

.aplium-table tbody tr:hover td {
    background: rgba(22, 163, 74, 0.02) !important;
}

/* Icons & Tooltips */
.icon-container {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

/* Modal Harmony */
.aplium-modal-content {
    background: var(--card-bg) !important;
    border-radius: 30px !important;
    border: 1px solid var(--card-border) !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5) !important;
    padding: 2.5rem !important;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-premium {
    animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.animate-fade-in-up {
    animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Tom Select Premium */
.ts-control {
    border-radius: 14px !important;
    padding: 0.875rem 1.125rem !important;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--aplium-slate-200);
    border-radius: 10px;
}

:root.dark ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

/* Validation Badges */
.validation-badge {
    padding: 6px 14px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.validation-badge--valid {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.validation-badge--invalid {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.dark .validation-badge--valid {
    background: #064e3b;
    color: #34d399;
    border-color: #065f46;
}

.dark .validation-badge--invalid {
    background: #7f1d1d;
    color: #f87171;
    border-color: #991b1b;
}

/* --- Label Preview System (Two-Column) --- */
#labelPreviewArea {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-image:
        radial-gradient(circle at 1px 1px, var(--aplium-slate-200) 1px, transparent 0);
    background-size: 32px 32px;
    background-position: center;
}

.dark #labelPreviewArea {
    background-image:
        radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0);
}

#labelPreviewArea .label {
    background: #ffffff !important;
    background-image: 
        linear-gradient(rgba(0,0,0,0.01) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,0.01) 1px, transparent 1px) !important;
    background-size: 2px 2px !important;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow:
        0 1px 1px rgba(0,0,0,0.1),
        0 2px 2px rgba(0,0,0,0.1),
        0 4px 4px rgba(0,0,0,0.1),
        0 8px 8px rgba(0,0,0,0.1),
        0 16px 16px rgba(0,0,0,0.1) !important;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
    display: flex;
    flex-direction: column;
}

#labelPreviewArea .label::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, transparent 50%, rgba(0,0,0,0.02) 100%);
    pointer-events: none;
}

.dark #labelPreviewArea .label {
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Custom CSS Scrollbar for Config Panel */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--aplium-slate-200);
    border-radius: 10px;
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.05);
}

/* Animations for mode switching */
.animate-fade-in {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-mode] {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

[data-mode]:hover:not(.bg-white) {
    background: rgba(0, 0, 0, 0.03);
}

.dark [data-mode]:hover:not(.bg-white) {
    background: rgba(255, 255, 255, 0.05);
}

/* Label Inner Components - High Contrast for Readability */
.label * {
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Print Overrides for Label Area */
@media print {
    #printArea .label {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        page-break-after: always;
    }
}

/* --- Global Omnisearch - Modern UI Header Fix --- */
#globalSearch {
    padding-left: 3.25rem !important; /* Force space for magnifying glass */
    background: rgba(248, 250, 252, 1) !important; /* Solid bg for light mode */
    border: 1.5px solid rgba(0, 0, 0, 0.05) !important;
    border-radius: 12px !important;
    font-size: 0.85rem !important;
    height: 48px !important;
}

.dark #globalSearch {
    background: rgba(255, 255, 255, 0.05) !important; /* Glass effect for dark mode */
    border: 1.5px solid rgba(255, 255, 255, 0.1) !important;
    color: #cbd5e1 !important;
}

#globalSearch:focus {
    background: #ffffff !important;
    border-color: #10b981 !important;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1) !important;
}

/* Date range inputs in the traceability explorer - compact, fixed size */
input.evt-date-input {
    width: 130px !important;
    max-width: 130px !important;
    min-width: 130px !important;
    padding: 0 0.5rem !important;
    height: 2rem !important;
    font-size: 0.75rem !important;
    border-radius: 0.5rem !important;
    transform: none !important;
}