/**
 * Badge Styles - PM_WEB Centralized Badge System
 * ================================================
 *
 * Provides consistent badge styling across the application with proper
 * contrast ratios for accessibility (WCAG 2.1 AA compliance).
 *
 * Last updated: 2025-10-26
 */

/* ============================================
   Color Variables - System Palette
   ============================================ */
:root {
    /* Badge color palette - Light backgrounds with dark text */
    --badge-color-1: #87CEEB;  /* Sky Blue */
    --badge-color-2: #DDA0DD;  /* Plum */
    --badge-color-3: #98FB98;  /* Pale Green */
    --badge-color-4: #F0E68C;  /* Khaki */
    --badge-color-5: #FFB6C1;  /* Light Pink */
    --badge-color-6: #D3D3D3;  /* Light Gray */
    --badge-color-7: #FFA07A;  /* Light Salmon */
    --badge-color-8: #20B2AA;  /* Light Sea Green */
    --badge-color-9: #9370DB;  /* Medium Purple */
    --badge-color-10: #32CD32; /* Lime Green */
}

/* ============================================
   Base Badge Classes
   ============================================ */
.badge-client,
.badge-pm,
.badge-type {
    background-color: var(--badge-default-color, #e9ecef);
    color: #212529; /* Dark text for contrast */
    font-weight: 500;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 0.375rem;
    padding: 0.25em 0.5em;
    font-size: 0.75em;
    display: inline-block;
    line-height: 1.5;
}

/* ============================================
   Dynamic Color Classes (JS Generated)
   ============================================ */
.badge-color-1 {
    background-color: var(--badge-color-1) !important;
    color: #212529 !important; /* Dark text for light background */
}
.badge-color-2 {
    background-color: var(--badge-color-2) !important;
    color: #212529 !important;
}
.badge-color-3 {
    background-color: var(--badge-color-3) !important;
    color: #212529 !important;
}
.badge-color-4 {
    background-color: var(--badge-color-4) !important;
    color: #212529 !important;
}
.badge-color-5 {
    background-color: var(--badge-color-5) !important;
    color: #212529 !important;
}
.badge-color-6 {
    background-color: var(--badge-color-6) !important;
    color: #212529 !important;
}
.badge-color-7 {
    background-color: var(--badge-color-7) !important;
    color: #212529 !important;
}
.badge-color-8 {
    background-color: var(--badge-color-8) !important;
    color: #ffffff !important; /* White text for darker green */
}
.badge-color-9 {
    background-color: var(--badge-color-9) !important;
    color: #ffffff !important; /* White text for purple */
}
.badge-color-10 {
    background-color: var(--badge-color-10) !important;
    color: #212529 !important;
}

/* ============================================
   BC Order Type Badges (Tipi Ordine)
   ============================================ */
.badge-tipo-O {
    background-color: #0d6efd !important; /* Bootstrap primary blue */
    color: #ffffff !important;
}

.badge-tipo-Q {
    background-color: #198754 !important; /* Bootstrap success green */
    color: #ffffff !important;
}

.badge-tipo-R {
    background-color: #dc3545 !important; /* Bootstrap danger red */
    color: #ffffff !important;
}

.badge-tipo-H,
.badge-tipo-H-interno,
.badge-tipo-H-esterno {
    background-color: #fd7e14 !important; /* Bootstrap orange */
    color: #ffffff !important;
}

.badge-tipo-Y {
    background-color: #6f42c1 !important; /* Bootstrap purple */
    color: #ffffff !important;
}

.badge-tipo-$ {
    background-color: #20c997 !important; /* Bootstrap teal */
    color: #ffffff !important;
}

.badge-tipo-default {
    background-color: #6c757d !important; /* Bootstrap secondary gray */
    color: #ffffff !important;
}

/* ============================================
   Filter Badge Overrides (Multi-Select Filters)
   ============================================ */
/* Force readable text for ALL badges in filter panels */
.filter-checkbox-group .badge {
    background-color: #e9ecef !important; /* Light gray background */
    color: #212529 !important; /* Dark text for contrast */
    font-weight: 500 !important;
    border: 1px solid rgba(0,0,0,0.1) !important;
}

/* Preserve existing badge-tipo-* colors but ensure text is readable */
.filter-checkbox-group .badge-tipo-O,
.filter-checkbox-group .badge-tipo-Q,
.filter-checkbox-group .badge-tipo-R,
.filter-checkbox-group .badge-tipo-H,
.filter-checkbox-group .badge-tipo-Y,
.filter-checkbox-group .badge-tipo-$ {
    /* Keep background colors from above definitions */
    color: #ffffff !important; /* White text for dark backgrounds */
}

/* Light background badge types need dark text */
.filter-checkbox-group .badge-tipo-A,
.filter-checkbox-group .badge-tipo-K,
.filter-checkbox-group .badge-tipo-L,
.filter-checkbox-group .badge-tipo-D {
    color: #000000 !important; /* Black text for light backgrounds */
}

/* ============================================
   BC Invoice Type Badges (Tipi Fattura)
   ============================================ */
.badge-tipo-A {
    background-color: #198754 !important;  /* Fattura Vendita - Green */
    color: #ffffff !important;
}

.badge-tipo-M {
    background-color: #dc3545 !important;  /* Fattura Acquisto - Red */
    color: #ffffff !important;
}

.badge-tipo-K {
    background-color: #20c997 !important;  /* Fattura Vendita UE - Teal */
    color: #ffffff !important;
}

.badge-tipo-L {
    background-color: #0dcaf0 !important;  /* Fattura Vendita Immediata - Cyan */
    color: #000000 !important;
}

.badge-tipo-B {
    background-color: #fd7e14 !important;  /* DDT Acquisto - Orange */
    color: #ffffff !important;
}

.badge-tipo-D {
    background-color: #ffc107 !important;  /* Nota Credito - Yellow */
    color: #000000 !important;
}

.badge-tipo-T {
    background-color: #6f42c1 !important;  /* Fattura Pro-Forma - Purple */
    color: #ffffff !important;
}

.badge-tipo-U {
    background-color: #0d6efd !important;  /* Fattura Accompagnatoria - Blue */
    color: #ffffff !important;
}

.badge-tipo-Z {
    background-color: #6c757d !important;  /* Fattura Autoconsumo - Gray */
    color: #ffffff !important;
}

.badge-tipo-N {
    background-color: #e83e8c !important;  /* Nota Debito - Pink */
    color: #ffffff !important;
}

/* ============================================
   Status Badges (Stati)
   ============================================ */
.badge-stato-aperto {
    background-color: #0dcaf0 !important; /* Bootstrap info cyan */
    color: #000000 !important;
}

.badge-stato-chiuso {
    background-color: #6c757d !important; /* Bootstrap secondary */
    color: #ffffff !important;
}

.badge-stato-evaso {
    background-color: #198754 !important; /* Bootstrap success */
    color: #ffffff !important;
}

.badge-stato-parziale,
.badge-stato-parzialmente-evaso {
    background-color: #ffc107 !important; /* Bootstrap warning */
    color: #000000 !important;
}

.badge-stato-scaduto {
    background-color: #dc3545 !important; /* Bootstrap danger */
    color: #ffffff !important;
}

.badge-stato-sospeso {
    background-color: #fd7e14 !important; /* Bootstrap orange */
    color: #ffffff !important;
}

.badge-stato-attivi {
    background-color: #0d6efd !important; /* Bootstrap primary blue */
    color: #ffffff !important;
}

.badge-stato-confermato {
    background-color: #20c997 !important; /* Bootstrap teal */
    color: #ffffff !important;
}

/* ============================================
   Bootstrap Badge Overrides (Fix Contrast)
   ============================================ */
.badge.bg-primary {
    background-color: #0d6efd !important;
    color: #ffffff !important;
}

.badge.bg-secondary {
    background-color: #6c757d !important;
    color: #ffffff !important;
}

.badge.bg-success {
    background-color: #198754 !important;
    color: #ffffff !important;
}

.badge.bg-danger {
    background-color: #dc3545 !important;
    color: #ffffff !important;
}

.badge.bg-warning {
    background-color: #ffc107 !important;
    color: #000000 !important; /* Dark text for yellow background */
}

/* IMPORTANT: Fix for bg-info - must explicitly set white text for cyan */
.badge.bg-info {
    background-color: #0dcaf0 !important;
    color: #ffffff !important; /* Changed to white for better contrast */
}

.badge.bg-light {
    background-color: #f8f9fa !important;
    color: #212529 !important;
}

.badge.bg-dark {
    background-color: #212529 !important;
    color: #ffffff !important;
}

/* CRITICAL: Ensure text color is always set for .badge class with bg-* utilities */
.badge.text-dark {
    color: #000000 !important;
}

/* ============================================
   Utility Classes
   ============================================ */
.badge-outline {
    background-color: transparent !important;
    border: 1px solid currentColor;
}

.badge-sm {
    font-size: 0.65em;
    padding: 0.15em 0.4em;
}

.badge-lg {
    font-size: 0.85em;
    padding: 0.35em 0.6em;
}

/* ============================================
   Due Date Visualization
   ============================================ */

/* Overdue items - strong red emphasis */
.due-date-overdue {
    color: #dc3545 !important;
    font-weight: 700 !important;
    animation: pulse-danger 2s ease-in-out infinite;
}

/* Due today - warning orange */
.due-date-today {
    color: #fd7e14 !important;
    font-weight: 600 !important;
}

/* Days remaining - success green */
.due-date-ok {
    color: #198754 !important;
    font-weight: 500 !important;
}

/* Optional: Subtle pulse animation for overdue items */
@keyframes pulse-danger {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.75;
    }
}

/* Hover effect for better interactivity */
.due-date-overdue:hover,
.due-date-today:hover,
.due-date-ok:hover {
    filter: brightness(0.9);
    cursor: help;
}

/* Tooltip support (optional - requires Bootstrap tooltip) */
[data-bs-toggle="tooltip"].due-date-overdue,
[data-bs-toggle="tooltip"].due-date-today,
[data-bs-toggle="tooltip"].due-date-ok {
    text-decoration: underline dotted;
}