:root {
    --bs-primary: #a62754;
    --bs-primary-rgb: 166, 39, 84;
    --bs-primary-dark: #8c1e42;
}

/* ===== OVERRIDE BOOTSTRAP PRIMARY COLOR ===== */
.btn-primary {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
}

.btn-primary:hover, 
.btn-primary:focus {
    background-color: var(--bs-primary-dark) !important;
    border-color: var(--bs-primary-dark) !important;
}

.btn-outline-primary {
    color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
}

.btn-outline-primary:hover {
    background-color: var(--bs-primary) !important;
    color: white !important;
}

.text-primary {
    color: var(--bs-primary) !important;
}

.bg-primary {
    background-color: var(--bs-primary) !important;
}

/* ===== LAYOUT PRINCIPALE ===== */
body {
    padding-top: 56px;
    padding-bottom: 60px;
    background-color: #f8f9fa;
    overflow: hidden;
}

body.modal-open {
    overflow: hidden;
}

/* ===== COMPONENTI FISSI ===== */
.fixed-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    height: 61px;
}

.fixed-sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 60px;
    width: 15%;
    background: white;
    overflow-y: auto;
    z-index: 1020;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

.main-content {
    position: fixed;
    top: 56px;
    left: 15%;
    right: 0;
    bottom: 60px;
    overflow-y: auto;
    background: white;
    padding: 20px;
    z-index: 1010;
}

.fixed-footer,
.mobile-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: white;
    z-index: 1030;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
}

/* ===== COMPONENTI UI ===== */
/* Cards */
.card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    box-shadow: 0 2px 8px rgba(166, 39, 84, 0.1);
    border-radius: 12px;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(166, 39, 84, 0.2);
}

/* Buttons */
.btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 8px;
    font-weight: 500;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(166, 39, 84, 0.25);
}

.btn-sm {
    border-radius: 6px;
}

/* List Groups */
.list-group-item {
    transition: all 0.3s ease;
    border-radius: 8px !important;
    margin-bottom: 4px;
    border: 1px solid rgba(166, 39, 84, 0.1);
}

.list-group-item:hover {
    background-color: rgba(166, 39, 84, 0.08);
    transform: translateX(8px);
    border-color: rgba(166, 39, 84, 0.3);
}

/* Navigation */
.navbar-nav .dropdown-menu {
    position: absolute !important;
    margin-top: 8px !important;
}

.nav-link {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 8px;
    margin: 2px 0;
}

.nav-link:not(.dropdown-toggle):hover {
    background-color: rgba(166, 39, 84, 0.12);
    transform: translateX(8px);
}

.sidebar-nav .nav-link.active {
    background-color: var(--bs-primary) !important;
    color: white !important;
    transform: translateX(8px);
}

/* Tables */
.table tbody tr {
    transition: all 0.3s ease;
}

.table td,
.table th {
    white-space: nowrap;
}

.table-sortable th[data-sortable] {
    cursor: pointer;
    user-select: none;
    position: relative;
}

.table-sortable th[data-sortable]:hover {
    background-color: #f8f9fa;
}

/* Forms */
input.form-control,
textarea.form-control,
select.form-select {
    background-color: #fff !important;
    border: 1px solid rgba(166, 39, 84, 0.2) !important;
    border-radius: 8px !important;
    color: #212529 !important;
    transition: all 0.25s ease-in-out;
    box-shadow: none !important;
}

input.form-control:focus,
textarea.form-control:focus,
select.form-select:focus {
    border-color: var(--bs-primary) !important;
    box-shadow: 0 0 0 0.25rem rgba(166, 39, 84, 0.25) !important;
    outline: none !important;
}

input.form-control:hover,
textarea.form-control:hover,
select.form-select:hover {
    border-color: rgba(166, 39, 84, 0.4) !important;
}

input.form-control:disabled,
textarea.form-control:disabled,
select.form-select:disabled,
input.form-control[readonly],
textarea.form-control[readonly],
select.form-select[readonly] {
    background-color: #f8f9fa !important;
    color: #6c757d !important;
    border-color: rgba(166, 39, 84, 0.1) !important;
    opacity: 1 !important;
}

/* Chrome Autofill */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-box-shadow: 0 0 0px 1000px #fff inset !important;
    -webkit-text-fill-color: #212529 !important;
    transition: background-color 5000s ease-in-out 0s !important;
}

::placeholder {
    color: #999 !important;
    opacity: 1 !important;
}

*:focus {
    box-shadow: 0 0 0 0.25rem rgba(166, 39, 84, 0.3) !important;
    outline: none !important;
}

/* Form Validation */
.is-invalid {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

.is-valid {
    border-color: #28a745 !important;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;
}

.invalid-feedback {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #dc3545;
}

/* Pagination */
.pagination .page-item .page-link {
    color: var(--bs-primary);
    border: 1px solid #dee2e6;
    transition: all 0.2s ease-in-out;
}

.pagination .page-item .page-link:hover {
    color: var(--bs-primary-dark);
    background-color: rgba(166, 39, 84, 0.1);
    border-color: var(--bs-primary);
}

.pagination .page-item.active .page-link {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: white !important;
}

.pagination .page-item.disabled .page-link {
    color: #6c757d;
    background-color: #f8f9fa;
    border-color: #dee2e6;
}

.pagination .page-item .page-link:focus {
    box-shadow: 0 0 0 0.25rem rgba(166, 39, 84, 0.25);
    border-color: var(--bs-primary);
}

.pagination.pagination-sm .page-link {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

#itemsPerPageSelect {
    border-radius: 0 !important;
}

/* ===== PAGINA LOGIN ===== */
.login-body {
    background-color: var(--bs-primary) !important;
    min-height: 100vh;
    display: flex;
    padding-top: 15%;
    position: relative;
}

.login-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(166, 39, 84, 0.9) 0%, rgba(140, 30, 66, 0.9) 100%);
    z-index: 0;
}

.login-card {
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 2.5rem;
    border: none;
    position: relative;
    z-index: 1;
}

.login-logo {
    padding: 1rem 0;
}

.brand-name {
    font-weight: 700;
    letter-spacing: 1px;
    font-size: 1.8rem;
}

.logo-placeholder {
    background: rgba(166, 39, 84, 0.1);
    border-radius: 50%;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.login-submit-btn {
    background: linear-gradient(135deg, var(--bs-primary) 0%, var(--bs-primary-dark) 100%) !important;
    border: none !important;
    padding: 12px 24px;
    font-weight: 600;
    font-size: 1.1rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(166, 39, 84, 0.3);
}

.login-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(166, 39, 84, 0.4);
}

.login-submit-btn:active {
    transform: translateY(0);
}

/* ===== COMPONENTI SPECIALI ===== */
/* Loading Overlay */
#globalLoading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(166, 39, 84, 0.3);
    text-align: center;
    max-width: 400px;
    width: 90%;
    border: 2px solid var(--bs-primary);
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--bs-primary);
    border-radius: 50%;
    animation: spin 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
    margin: 0 auto 20px;
    position: relative;
}

.loading-spinner::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border: 4px solid transparent;
    border-top: 4px solid rgba(166, 39, 84, 0.3);
    border-radius: 50%;
    animation: spin 2s linear infinite;
}

.loading-text {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--bs-primary);
    margin-bottom: 10px;
    animation: pulse 2s infinite;
}

.loading-subtext {
    color: #6c757d;
    font-size: 0.9rem;
}

/* Modals */
.modal {
    z-index: 1060 !important;
}

.modal-backdrop {
    z-index: 1050 !important;
}

.modal-body.scrollable {
    max-height: 60vh;
    overflow-y: auto;
    padding: 1rem;
}

.modal-body.scrollable table {
    margin-bottom: 0;
}

.notification-toast {
    animation: slideInRight 0.3s ease-out;
}

/* Progress Bars */
[id^="compressionProgress"] {
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    height: 25px;
}

[id^="compressionProgress"] .progress-bar {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 8px;
}

.progress-text {
    font-size: 11px !important;
    font-weight: 600;
    text-shadow: 0 1px 1px rgba(0,0,0,0.3);
    color: white;
    letter-spacing: 0.3px;
}

/* Stat Cards */
.stat-card-sm {
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Description Rows */
.description-row td {
    border-top: 0;
    padding-top: 0;
}

.description-content {
    margin-top: 0.25rem;
    margin-left: 0.5rem;
}

/* Highlight Animation */
.highlighted-row {
    background-color: #d4edda !important;
    border-left: 4px solid #28a745;
    transition: all 0.5s ease;
    box-shadow: 2px 8px rgba(40, 167, 69, 0.3);
    animation: pulse-highlight 2s ease-in-out;
}

/* Drag and Drop */
.draggable-file {
    transition: all 0.3s ease;
    cursor: move;
}

.draggable-file.dragging {
    opacity: 0.5;
    background-color: #f8f9fa;
}

.draggable-file:hover {
    background-color: #f8f9fa;
}

.handle {
    cursor: grab;
}

.handle:active {
    cursor: grabbing;
}

/* ===== ANIMAZIONI ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes loadingFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes loadingFadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes pulse-highlight {
    0% { background-color: #d4edda; }
    50% { background-color: #c3e6cb; }
    100% { background-color: #d4edda; }
}

.fade-in-up {
    animation: fadeInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.loading-fade-in {
    animation: loadingFadeIn 0.3s ease-out forwards;
}

.loading-fade-out {
    animation: loadingFadeOut 0.3s ease-in forwards;
}

/* ===== MEDIA QUERIES ===== */
@media (min-width: 992px) {
    .mobile-toolbar {
        display: none !important;
    }
    .fixed-footer {
        display: block !important;
    }
    .fixed-sidebar {
        display: block !important;
    }
}

@media (max-width: 991.98px) {
    .fixed-sidebar {
        display: none !important;
    }
    .main-content {
        left: 0 !important;
        bottom: 60px !important;
        padding: 15px !important;
    }
    
    .offcanvas-start {
        width: 65% !important;
        max-width: 240px !important;
    }
    
    body {
        padding-bottom: 60px !important;
    }
    .fixed-footer {
        display: none !important;
    }
    .mobile-toolbar {
        display: block !important;
    }
}

@media (max-width: 576px) {
    .card-footer .btn-group {
        flex-direction: column;
    }
    
    .card-footer .btn-group .btn {
        border-radius: 0.375rem !important;
        margin-bottom: 0.25rem;
    }
    
    .modal-footer .btn {
        margin-bottom: 0.5rem;
    }
    
    .camera-container video {
        height: 300px !important;
        max-height: 50vh;
    }
    
    .login-card {
        margin: 1rem;
        padding: 1.5rem;
    }
    
    .brand-name {
        font-size: 1.5rem;
    }
}