/*
 * CSS Base - Dark Theme moderno ispirato al template
 * Colori: Grigio #6b7280, Cyan #22d3ee
 */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d29;
    --bg-card: #1e2139;
    --border-color: #2d3142;
    --text-primary: #ffffff;
    --text-secondary: #9ca3af;
    --primary: #6b7280;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #22d3ee;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --navbar-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'JARVIS', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Navbar */
.navbar {
    height: var(--navbar-height);
    background: linear-gradient(135deg, #1a1d29 0%, #0f1117 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.5rem;
    z-index: 1000;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: bold;
    letter-spacing: 2px;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.3s ease;
    z-index: 999;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    overflow-y: hidden;
}

.sidebar-header {
    padding: 1.5rem;
    padding-left: calc(1.5rem + calc(3rem/16));
    border-bottom: 1px solid var(--border-color);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar.collapsed .sidebar-header {
    padding: 1.5rem 0;
    justify-content: center;
}

.sidebar.collapsed .sidebar-header h5 {
    display: none;
}

.sidebar-header h5 {
    margin: 0;
    color: var(--text-primary);
    font-weight: 600;
    transition: all 0.3s ease;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    width: 48px;
    height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    flex-shrink: 0;
    font-size: 1.4rem;
    font-weight: 900;
}

.sidebar-toggle:hover {
    color: var(--text-primary);
    background: rgba(107, 114, 128, 0.2);
}

.sidebar.collapsed .sidebar-toggle {
    width: 48px;
    margin: 0 auto;
}

/* Toggle icons: chevron quando aperto, hamburger quando chiuso */
.sidebar-toggle .toggle-hamburger {
    display: none;
}

.sidebar.collapsed .sidebar-toggle .toggle-chevron {
    display: none;
}

.sidebar.collapsed .sidebar-toggle .toggle-hamburger {
    display: inline;
}

.sidebar-menu {
    list-style: none;
    padding: 1rem 0;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    position: relative;
    white-space: nowrap;
}

.sidebar.collapsed .sidebar-menu li a {
    justify-content: center;
    padding: 0.875rem 0.5rem;
}

.sidebar-menu li a:hover {
    background: rgba(107, 114, 128, 0.1);
    color: var(--primary);
    border-left-color: var(--primary);
}

.sidebar-menu li a.active {
    background: rgba(107, 114, 128, 0.15);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
    transition: none !important; /* Disabilita transizioni per aggiornamento immediato */
}

.sidebar-menu li a i {
    width: 24px;
    margin-right: 12px;
    font-size: 1.125rem;
    text-align: center;
    transition: all 0.3s ease;
}

.sidebar.collapsed .sidebar-menu li a i {
    margin-right: 0;
}

.sidebar-menu li a span {
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar.collapsed .sidebar-menu li a span {
    opacity: 0;
    visibility: hidden;
    width: 0;
}

.menu-section {
    padding: 1.5rem 1.5rem 0.5rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

.sidebar.collapsed .menu-section {
    opacity: 0;
    visibility: hidden;
    height: 0;
    padding: 0;
    margin: 0;
}

/* Sidebar Footer */
.sidebar-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 1rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
    transition: all 0.3s ease;
}

.sidebar.collapsed .sidebar-footer {
    opacity: 0;
    visibility: hidden;
    height: 0;
    padding: 0;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--navbar-height);
    min-height: calc(100vh - var(--navbar-height));
    padding: 2rem;
    transition: margin-left 0.3s ease;
}

.main-content.expanded {
    margin-left: var(--sidebar-collapsed-width);
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.card-header {
    background: rgba(107, 114, 128, 0.1);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
}

.card-body {
    padding: 1.5rem;
}

/* Tables */
.table-dark {
    --bs-table-bg: transparent;
    --bs-table-striped-bg: rgba(255, 255, 255, 0.02);
    --bs-table-hover-bg: rgba(107, 114, 128, 0.1);
}

.table thead th {
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.875rem;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.table tbody td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.table thead th {
    padding: 0.5rem 0.75rem;
}

.table tbody tr {
    transition: all 0.2s ease;
}

.table tbody tr:hover {
    background: rgba(107, 114, 128, 0.1);
}

/* Button groups */
.btn-group .btn {
    margin-left: 0.25rem;
}

/* Search input groups */
.input-group-text {
    border-right: none;
}

.input-group .form-control.border-start-0 {
    border-left: none;
}

.input-group .form-control:focus {
    border-color: var(--border-color);
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 0.5rem 1.25rem;
    transition: all 0.2s ease;
}

/* Primary: grigio scuro a riposo, più chiaro su hover */
.btn-primary {
    background: linear-gradient(135deg, #4b5563 0%, #6b7280 100%);
    border: none;
    color: #ffffff;
}

.btn-primary:hover,
.btn-primary:focus {
    background: linear-gradient(135deg, #6b7280 0%, #9ca3af 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(107, 114, 128, 0.4);
    color: #ffffff;
}

/* Success: verde scuro a riposo, più chiaro su hover */
.btn-success {
    background: #059669;
    border: none;
    color: #ffffff;
}

.btn-success:hover,
.btn-success:focus {
    background: var(--success);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(16, 185, 129, 0.4);
    color: #ffffff;
}

/* Danger: rosso scuro a riposo, più chiaro su hover */
.btn-danger {
    background: #dc2626;
    border: none;
    color: #ffffff;
}

.btn-danger:hover,
.btn-danger:focus {
    background: var(--danger);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(239, 68, 68, 0.4);
    color: #ffffff;
}

/* Warning: arancione scuro a riposo, più chiaro su hover */
.btn-warning {
    background: #d97706;
    border: none;
    color: #ffffff;
}

.btn-warning:hover,
.btn-warning:focus {
    background: var(--warning);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(245, 158, 11, 0.4);
    color: #ffffff;
}

/* Info: cyan scuro a riposo, più chiaro su hover */
.btn-info {
    background: #0891b2;
    border: none;
    color: #ffffff;
}

.btn-info:hover,
.btn-info:focus {
    background: var(--info);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(34, 211, 238, 0.4);
    color: #000000;
}

/* Secondary: grigio scuro a riposo, più chiaro su hover */
.btn-secondary {
    background: #374151;
    border: none;
    color: #ffffff;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: #6b7280;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(107, 114, 128, 0.4);
    color: #ffffff;
}

/* Badges */
.badge {
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-weight: 500;
}

/* Toast */
.toast {
    backdrop-filter: blur(10px);
}

/* User Dropdown - stile sidebar */
.user-dropdown {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 0;
}

.user-dropdown .dropdown-item {
    color: var(--text-secondary);
    padding: 0.625rem 1rem;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.user-dropdown .dropdown-item:hover,
.user-dropdown .dropdown-item:focus {
    background: rgba(107, 114, 128, 0.1);
    color: var(--primary);
    border-left-color: var(--primary);
}

.user-dropdown .dropdown-item i {
    width: 20px;
    margin-right: 8px;
    text-align: center;
}

/* Forms */
.form-control,
.form-select {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 0.625rem 1rem;
}

.form-control:focus,
.form-select:focus {
    background: var(--bg-secondary);
    border-color: var(--primary);
    box-shadow: none;
    color: var(--text-primary);
}

.form-label {
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* Pagination - Dark Theme */
.pagination .page-link {
    background-color: #343a40;
    border-color: #495057;
    color: #adb5bd;
    transition: all 0.15s ease;
}

.pagination .page-link:hover {
    background-color: #495057;
    border-color: #6c757d;
    color: #fff;
}

.pagination .page-item.active .page-link {
    background-color: #495057;
    border-color: #6c757d;
    color: #fff;
}

.pagination .page-item.disabled .page-link {
    background-color: #212529;
    border-color: #343a40;
    color: #6c757d;
}

.pagination .page-link:focus {
    box-shadow: none;
    outline: none;
}

.pagination .page-link {
    border-radius: 6px !important;
    margin: 0 0.25rem;
    min-width: 28px;
    text-align: center;
    padding: 0.25rem 0.5rem;
}

.pagination {
    flex-shrink: 0;
}

/* Settings tabs - gap uniforme tra colonne */
.tab-content .row {
    --bs-gutter-x: 1rem;
}

/* Delete Modal - Global */
#deleteModal .modal-content {
    border: 2px solid #dc3545;
    box-shadow: 0 10px 40px rgba(220, 53, 69, 0.3);
}

#deleteModal .modal-header {
    background: linear-gradient(135deg, rgba(220, 53, 69, 0.2) 0%, rgba(220, 53, 69, 0.1) 100%);
}

#deleteModal .modal-title {
    font-weight: 600;
}

#deleteModal .modal-body strong {
    color: #6b7280;
    font-weight: 600;
}

#deleteModal .alert-warning {
    background: rgba(255, 193, 7, 0.15);
    border-color: rgba(255, 193, 7, 0.3);
    color: #ffc107;
}

#deleteModal .btn-danger {
    background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%);
    border: none;
    transition: all 0.3s ease;
}

#deleteModal .btn-danger:hover {
    background: linear-gradient(135deg, #dc3545 0%, #ef4444 100%);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.4);
}

/* Rimuovi focus outline/halo da tutti gli elementi interattivi */
.btn:focus,
.btn:focus-visible,
.btn-close:focus,
.form-check-input:focus,
.form-switch .form-check-input:focus,
.dropdown-toggle:focus,
.nav-link:focus,
.page-link:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* Tooltip per sidebar collapsed */
.sidebar.collapsed .sidebar-menu li a {
    position: relative;
}

.sidebar.collapsed .sidebar-menu li a::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    pointer-events: none;
    margin-left: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.sidebar.collapsed .sidebar-menu li a:hover::after {
    opacity: 1;
    visibility: visible;
    margin-left: 15px;
}

/* Responsive */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
        width: var(--sidebar-width);
    }

    .main-content {
        margin-left: 0;
    }
}

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

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* SPA Navigation - Loading Indicator */
.spa-loading {
    cursor: wait;
}

.spa-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--info) 100%);
    z-index: 10000;
    animation: spa-loading-bar 1.5s ease-in-out infinite;
    transform-origin: left;
}

@keyframes spa-loading-bar {
    0% {
        transform: scaleX(0);
    }
    50% {
        transform: scaleX(0.5);
    }
    100% {
        transform: scaleX(1);
    }
}

.spa-loader .spinner-border {
    display: none;
}

/* Transizione smooth per cambio contenuto */
#main-content {
    transition: opacity 0.2s ease;
}

.spa-loading #main-content {
    opacity: 0.6;
}

/* Card con altezza fissa e scroll interno - CRITICHE per il layout */
.customers-card-body,
.systems-card-body,
.types-card-body {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 220px);
    overflow: hidden;
}

.customers-card-body .table-responsive,
.systems-card-body .table-responsive,
.types-card-body .table-responsive {
    border-radius: 8px;
    overflow-y: auto;
    overflow-x: auto;
    flex: 1;
    max-height: calc(100vh - 280px);
}

/* Header fisso della tabella */
.table-responsive thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #000000;
    color: #ffffff;
    border-top: none;
}

/* ==================== Search Box con Spinner ==================== */
.search-box .search-spinner {
    color: #ffffff;
    font-size: 1rem;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Quando caricato: nascondi spinner */
.search-box.loaded .search-spinner {
    opacity: 0;
    width: 0;
    margin: 0;
    overflow: hidden;
}
