/**
 * Toolbar Unificata - Sistema Pulito e Semplificato
 * Risolve i problemi di annidamento eccessivo e posizionamento
 */

/* ===== TOOLBAR BASE ===== */
.compact-toolbar {
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    /* min-height: 48px; */
    display: flex;
    align-items: center;
    padding: 0 8px;
}

.toolbar-container {
    width: 100%;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap; /* Allow wrapping */
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: #dee2e6;
    margin: 0 4px;
}

/* ===== TOOLBAR BUTTONS - APPLE DESIGN SYSTEM ===== */
.toolbar-btn {
    /* Layout & Positioning */
    align-items: center;
    appearance: button;
    display: flex;
    justify-content: center;
    position: relative;
    cursor: pointer;
    
    /* Dimensions */
    height: 38px;
    min-width: 38px;
    width: 40px;
    padding: 8px;
    margin-right: 8px;
    
    /* Typography */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    font-weight: 400;
    line-height: 16px;
    color: rgb(59, 66, 82);
    text-align: center;
    -webkit-font-smoothing: antialiased;
    
    /* Background & Borders */
    background-color: rgb(255, 255, 255);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    
    /* Shadow & Effects */
    box-shadow: rgba(0, 0, 0, 0.05) 0px 1px 2px 0px, rgba(0, 0, 0, 0.05) 0px -1px 0px 0px inset;
    
    /* Transitions */
    transition: all 0.2s ease-in-out;
    
    /* Touch & Interaction */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    user-select: auto;
}

.toolbar-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
}

.toolbar-btn:active {
    background: rgba(0, 0, 0, 0.1);
}

.toolbar-btn i {
    font-size: 16px;
    line-height: 1;
}

/* ===== UNIFIED APPLE-STYLE COUNTER BADGE SYSTEM ===== */
.btn-with-badge {
    position: relative;
    overflow: visible; /* Permette al badge di uscire dal bottone */
}

.badge-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: linear-gradient(135deg, #ff3b30, #ff6b6b);
    color: white;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3), 0 1px 3px rgba(0, 0, 0, 0.12);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.badge-count.show {
    opacity: 1;
    transform: scale(1);
}

/* Varianti colore per diversi tipi di counter */
.badge-count.success {
    background: linear-gradient(135deg, #34c759, #30d158);
    box-shadow: 0 2px 8px rgba(52, 199, 89, 0.3), 0 1px 3px rgba(0, 0, 0, 0.12);
}

.badge-count.warning {
    background: linear-gradient(135deg, #ff9500, #ffad33);
    box-shadow: 0 2px 8px rgba(255, 149, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.12);
}

.badge-count.info {
    background: linear-gradient(135deg, #007aff, #5ac8fa);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3), 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Animazione pulse per counter attivi */
.badge-count.pulse {
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0% { 
        box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3), 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0 rgba(255, 59, 48, 0.7); 
    }
    50% { 
        box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3), 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 6px rgba(255, 59, 48, 0); 
    }
    100% { 
        box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3), 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0 rgba(255, 59, 48, 0); 
    }
}

/* ===== ERROR MAP COMPONENT STYLES ===== */
.error-map-btn {
    position: relative;
    display: none; /* Nascosto di default, mostrato dal JS quando ci sono errori */
}

.error-map-btn.has-errors {
    color: #dc3545 !important;
    border-color: #dc3545 !important;
}

.error-map-btn.has-errors:hover {
    background-color: #dc3545 !important;
    color: white !important;
}

.error-map-btn.active {
    background-color: #dc3545 !important;
    color: white !important;
    border-color: #dc3545 !important;
}

/* Dropdown della mappa errori */
.error-map-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    min-width: 300px;
    max-width: 400px;
    z-index: 1050;
    display: none;
    padding: 0;
    margin-top: 0.25rem;
}

.error-map-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #dee2e6;
    background-color: #f8f9fa;
    border-radius: 0.375rem 0.375rem 0 0;
}

.error-map-body {
    max-height: 300px;
    overflow-y: auto;
    padding: 0;
}

.error-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.error-item:hover {
    background-color: #f8f9fa;
}

.error-item .error-field {
    font-weight: 600;
    color: #495057;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.error-item .error-message {
    color: #6c757d;
    font-size: 0.8rem;
    line-height: 1.3;
}

/* Field highlighting */
.field-highlight {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
    transition: all 0.3s ease !important;
}

/* ===== EXPANDABLE TOOLBAR BUTTON ===== */
.toolbar-btn-expandable {
    /* Override fixed width from base .toolbar-btn */
    width: auto !important;
    min-width: 38px !important;
    max-width: 200px !important;
    
    /* Content-based padding */
    padding: 8px 12px !important;
    
    /* Smooth width transitions */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    
    /* Text handling */
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    
    /* Flexbox for icon + text alignment */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
}

.toolbar-btn-expandable:hover {
    /* Slight scale on hover */
    transform: scale(1.02) !important;
}

/* Label inside expandable button */
.toolbar-btn-expandable .btn-label {
    font-size: 14px !important;
    font-weight: 500 !important;
    line-height: 1 !important;
    margin: 0 !important;
    
    /* Smooth show/hide transition */
    transition: opacity 0.3s ease, transform 0.3s ease !important;
}

/* IMPORTANT: Handle Bootstrap responsive classes properly */
.toolbar-btn-expandable .btn-label.d-none:not(.d-md-inline) {
    opacity: 0 !important;
    transform: translateX(-10px) !important;
}

.toolbar-btn-expandable .btn-label:not(.d-none),
.toolbar-btn-expandable .btn-label.d-none.d-md-inline {
    opacity: 1 !important;
    transform: translateX(0) !important;
}

/* Mobile behavior for d-md-inline labels */
@media (max-width: 767.98px) {
    .toolbar-btn-expandable .btn-label.d-none.d-md-inline {
        opacity: 0 !important;
        transform: translateX(-10px) !important;
        display: none !important;
    }
}

/* Desktop behavior for d-md-inline labels */
@media (min-width: 768px) {
    .toolbar-btn-expandable .btn-label.d-none.d-md-inline {
        opacity: 1 !important;
        transform: translateX(0) !important;
        display: inline !important;
    }
}

/* Icon inside expandable button */
.toolbar-btn-expandable i {
    font-size: 16px !important;
    line-height: 1 !important;
    flex-shrink: 0 !important;
}

/* Responsive behavior improvements */
@media (max-width: 768px) {
    .toolbar-btn-expandable {
        /* Tighter padding on mobile */
        padding: 6px 10px !important;
        gap: 4px !important;
    }
    
    .toolbar-btn-expandable .btn-label {
        font-size: 13px !important;
    }
}

/* Specific styles for sync button */
.toolbar-btn-expandable.sync-btn {
    /* Sync-specific colors */
    background: linear-gradient(135deg, #007aff, #5ac8fa) !important;
    color: white !important;
    border-color: rgba(0, 122, 255, 0.3) !important;
}

.toolbar-btn-expandable.sync-btn:hover {
    background: linear-gradient(135deg, #0056b3, #007aff) !important;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3) !important;
}

.toolbar-btn-expandable.sync-btn:active {
    transform: scale(0.98) !important;
}

/* CRITICAL: Fix sync button text visibility */
.toolbar-btn-expandable.sync-btn .btn-label {
    color: white !important;
    font-weight: 600 !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2) !important;
    opacity: 1 !important;
    display: inline !important;
}

.toolbar-btn-expandable.sync-btn i {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2) !important;
}

/* DISABLE OLD RIPPLE EFFECT for sync button */
.toolbar-btn-expandable.sync-btn::before {
    display: none !important;
}

/* MODERN RIPPLE EFFECT - Solo per bottone Sincronizza */
.toolbar-btn-expandable.sync-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0.2) 40%, rgba(255,255,255,0.1) 70%, transparent 100%);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
    z-index: 2;
    opacity: 0;
}

.toolbar-btn-expandable.sync-btn:hover::after {
    width: 130%;
    height: 130%;
    opacity: 1;
}

.toolbar-btn-expandable.sync-btn:active::after {
    width: 140%;
    height: 140%;
    opacity: 0.8;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Override responsive hide for sync button specifically */
@media (min-width: 768px) {
    .toolbar-btn-expandable.sync-btn .btn-label.d-none.d-md-inline {
        display: inline !important;
        opacity: 1 !important;
        transform: translateX(0) !important;
    }
}

/* ===== VISIONATO BUTTON APPLE STYLES ===== */
.visionato-btn {
    /* Override any inline styles */
    cursor: pointer !important;
    font-size: 1.2rem !important;
    padding: 0.5rem !important;
    
    /* Apple-style transitions */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    transform-origin: center !important;
}

/* CRITICAL: Material Icons font override for ALL material-icons */
.material-icons {
    /* Force Material Icons font family */
    font-family: 'Material Icons' !important;
    
    /* Material Icons specific properties */
    font-weight: normal !important;
    font-style: normal !important;
    font-variant: normal !important;
    text-transform: none !important;
    line-height: 1 !important;
    letter-spacing: normal !important;
    word-wrap: normal !important;
    white-space: nowrap !important;
    direction: ltr !important;
    
    /* Support for all WebKit browsers */
    -webkit-font-smoothing: antialiased !important;
    
    /* Support for Safari and Chrome */
    text-rendering: optimizeLegibility !important;
    
    /* Support for Firefox */
    -moz-osx-font-smoothing: grayscale !important;
    
    /* Support for IE */
    font-feature-settings: 'liga' !important;
}

/* Specific override for toolbar buttons with material icons */
.toolbar-btn.material-icons {
    /* Ensure Material Icons are displayed properly in toolbar */
    font-family: 'Material Icons' !important;
}

.visionato-btn.icon-visioned {
    color: #34c759 !important; /* Apple green */
}

.visionato-btn.icon-not-visioned {
    color: #8e8e93 !important; /* Apple gray */
}

.visionato-btn.icon-loading {
    color: #007aff !important; /* Apple blue */
    animation: spin 1s linear infinite;
}

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

.visionato-btn:hover {
    transform: scale(1.1) !important;
    filter: brightness(1.1) !important;
}

.visionato-btn:active {
    transform: scale(0.95) !important;
}

/* Animation classes for JavaScript */
.visionato-btn.animating {
    transform: scale(1.3) rotate(360deg) !important;
}

.visionato-btn.pulse {
    transform: scale(1.2) !important;
}

/* Settings button specifico */
#manageSpecialLabelsBtn {
    color: #6c757d;
}

#manageSpecialLabelsBtn:hover {
    color: #495057;
    background: rgba(0, 0, 0, 0.05);
}

/* ===== DROPDOWN SEMPLIFICATO ===== */
.toolbar-dropdown {
    position: relative;
}

.toolbar-dropdown .dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
}

.toolbar-dropdown .dropdown-toggle::after {
    margin-left: 0;
}

/* Badge nel bottone */
.dropdown-badge {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dropdown-badge i {
    font-size: 18px;
}

/* ===== DROPDOWN MENU PULITO ===== */
.toolbar-dropdown .dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    margin-top: 0;
    min-width: 240px;
    max-width: 320px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    border: 1px solid #e0e0e0;
    background: white;
    z-index: 1050;
}

/* Fix posizione dropdown per special labels */
.special-labels-toolbar .dropdown-menu {
    right: auto;
    left: 0;
}

/* Search box */
.dropdown-search {
    padding: 8px 12px;
    border-bottom: 1px solid #e0e0e0;
}

.dropdown-search input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
}

/* Dropdown items - SEMPLIFICATI */
.dropdown-option {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    color: #212529;
    text-decoration: none;
    transition: background 0.15s ease;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.dropdown-option:hover {
    background: #f8f9fa;
}

.dropdown-option.active {
    background: #e3f2fd;
}

/* Icona opzione */
.dropdown-option-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 8px;
}

.dropdown-option-icon i {
    font-size: 20px;
}

/* Testo opzione */
.dropdown-option-content {
    flex: 1;
    min-width: 0;
}

.dropdown-option-label {
    font-weight: 500;
    font-size: 14px;
    line-height: 1.3;
}

.dropdown-option-desc {
    font-size: 12px;
    color: #6c757d;
    line-height: 1.3;
    margin-top: 2px;
}

/* Check icon */
.dropdown-option-check {
    width: 20px;
    margin-left: 8px;
    flex-shrink: 0;
}

.dropdown-option-check i {
    font-size: 18px;
    color: #1976d2;
}

/* ===== SPECIAL ACTIONS SPECIFICI ===== */
.special-actions-dropdown .dropdown-menu {
    min-width: 260px;
    padding: 0;
}

.special-actions-dropdown .dropdown-header {
    background: #f8f9fa;
    padding: 12px 16px;
    padding-left: 16px; /* Distanza appropriata dal bordo sinistro */
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
    border-bottom: 1px solid #e0e0e0;
    margin: 0;
    border-radius: 8px 8px 0 0;
}

/* Special actions dropdown items */
.special-actions-dropdown .dropdown-option {
    padding: 10px 16px;
}

.special-actions-dropdown .dropdown-option:first-child {
    border-top: none;
}

.special-actions-dropdown .dropdown-option:last-child {
    border-radius: 0 0 8px 8px;
}

/* ===== SPECIAL LABELS SPECIFICI ===== */
.special-labels-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Special label dropdown button - STILI SPOSTATI IN special-labels-inline.css */

/* Badge dentro il bottone - occupa tutto lo spazio disponibile */
.special-label-dropdown .dropdown-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    justify-content: flex-start;
    overflow: hidden; /* Importante per contenere il testo */
    padding-right: 20px; /* Spazio per la freccia dropdown */
}

/* Icona e testo allineati */
.dropdown-badge i {
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0; /* L'icona non si riduce mai */
}

.dropdown-badge span {
    font-size: 14px;
    line-height: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1; /* Il testo prende tutto lo spazio rimanente */
    min-width: 0; /* Importante per far funzionare text-overflow */
}

/* Fix freccia dropdown Bootstrap */
.special-label-dropdown::after {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 0 !important;
}

/* Override Bootstrap defaults per toolbar */
.toolbar-dropdown .btn {
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: white;
    transition: all 0.2s ease;
}

.toolbar-dropdown .btn:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.2);
}

.toolbar-dropdown .btn:focus {
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

/* Rimuovi padding default Bootstrap solo per special labels */
.special-labels-toolbar .dropdown-toggle {
    /* Padding già gestito da .special-label-dropdown */
}

/* Fix allineamento per tutti i dropdown in toolbar */
.toolbar-dropdown {
    display: inline-flex;
    align-items: center;
}

/* Assicurati che i dropdown-item non abbiano padding eccessivo */
.toolbar-dropdown .dropdown-menu li {
    padding: 0;
    margin: 0;
}

.toolbar-dropdown .dropdown-divider {
    margin: 4px 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .toolbar-container {
        flex-wrap: wrap;
    }
    
    .toolbar-section {
        flex-wrap: wrap;
    }
    
    .toolbar-dropdown .dropdown-menu {
        position: fixed;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-width: none;
    }
}

/* ===== ANIMAZIONI ===== */
/* .dropdown-menu {
    animation: grow 0.3s forwards;
    transform: scale(0.95);
    opacity: 0.8;
}

@keyframes grow {
    from {
        transform: scale(0.95);
        opacity: 0.8;
        top: calc(100% + 4px);
    }
    to {
        transform: scale(1);
        opacity: 1;
        top: calc(100% + 4px);
    }
}*/

/* ===== UTILITY CLASSES ===== */
.no-results-message {
    padding: 24px;
    text-align: center;
    color: #6c757d;
}

.no-results-message i {
    font-size: 48px;
    opacity: 0.3;
    display: block;
    margin-bottom: 8px;
}