/* =============================================
   GESTIONALE MAGAZZINO - CUSTOM STYLES
   ============================================= */

:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --sidebar-width: 260px;
    --sidebar-bg: #2c3e50;
    --sidebar-hover: #34495e;
}

/* =============================================
   GENERAL STYLES
   ============================================= */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f6fa;
    min-height: 100vh;
}

/* =============================================
   LOGIN PAGE
   ============================================= */

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-logo {
    max-width: 180px;
    height: auto;
    margin-bottom: 15px;
}

.superadmin-login .login-header h2 {
    color: var(--danger-color);
}

.superadmin-login .btn-danger {
    background-color: var(--danger-color);
    border-color: var(--danger-color);
}

/* =============================================
   SIDEBAR
   ============================================= */

.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

.sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #ecf0f1;
    transition: all 0.3s;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    padding: 20px;
    background: rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.sidebar-logo {
    max-width: 150px;
    height: auto;
    margin-bottom: 5px;
}

/* Sidebar Footer — tenant name at bottom */
.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 0;
}

.sidebar-footer-company {
    display: flex;
    align-items: center;
    padding: 8px 20px;
    color: #20c997;
    font-size: 0.85rem;
    font-weight: 500;
}

.sidebar-footer-company i {
    margin-right: 10px;
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.sidebar-footer-nav {
    padding: 0 !important;
}

.sidebar-footer-nav .nav-link {
    color: rgba(255, 255, 255, 0.8);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-size: 0.9rem;
}

.sidebar-footer-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: white;
    border-left-color: var(--success-color);
}

.sidebar-footer-nav .nav-link.active {
    background: var(--sidebar-hover);
    color: white;
    border-left-color: var(--success-color);
}

.sidebar-footer-nav .nav-link i {
    margin-right: 10px;
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.sidebar .nav {
    padding: 10px 0;
    flex: 1;
}

.sidebar .nav-item {
    padding: 0;
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.8);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-size: 0.9rem;
}

.sidebar .nav-link:hover {
    background: var(--sidebar-hover);
    color: white;
    border-left-color: var(--success-color);
}

.sidebar .nav-link.active {
    background: var(--sidebar-hover);
    color: white;
    border-left-color: var(--success-color);
}

.sidebar .nav-link i {
    margin-right: 10px;
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.sidebar .nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 10px 20px;
}

.sidebar .nav-section {
    padding: 10px 20px 5px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 600;
}

/* Sidebar Search */
.sidebar-search input {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.15) !important;
    color: #ecf0f1 !important;
    font-size: 0.85rem;
}

.sidebar-search input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.sidebar-search input:focus {
    background: rgba(255, 255, 255, 0.15) !important;
    border-color: var(--success-color) !important;
    box-shadow: none;
}

/* Sidebar Accordion Groups */
.sidebar-group-toggle {
    position: relative;
    cursor: pointer;
}

.sidebar-group-toggle .sidebar-arrow {
    transition: transform 0.2s;
    font-size: 0.7rem;
}

.sidebar-group-toggle.collapsed .sidebar-arrow {
    transform: rotate(-90deg);
}

.sidebar-submenu {
    padding-left: 0;
}

.sidebar-submenu .nav-link {
    padding-left: 42px;
    font-size: 0.85rem;
    padding-top: 7px;
    padding-bottom: 7px;
}

/* Hide items when search filters */
.sidebar .nav-item.search-hidden {
    display: none !important;
}

.sidebar .sidebar-group.search-hidden {
    display: none !important;
}

/* =============================================
   MAIN CONTENT
   ============================================= */

#content {
    width: 100%;
    min-height: 100vh;
    transition: all 0.3s;
    margin-left: var(--sidebar-width);
}

#content.expanded {
    margin-left: 0;
}

#content > .navbar {
    border-bottom: 1px solid #e9ecef;
}

#content main {
    max-width: 100%;
}

/* =============================================
   NAVBAR
   ============================================= */

.navbar {
    padding: 10px 20px;
}

#sidebarCollapse {
    border: none;
    background: transparent;
    transition: all 0.2s;
}

#sidebarCollapse:hover {
    background: #20c997;
    color: var(--primary-color);
}

.navbar .dropdown-toggle::after {
    margin-left: 8px;
}

.navbar .badge {
    font-size: 0.7rem;
    margin-left: 5px;
}

/* =============================================
   BREADCRUMB
   ============================================= */

.breadcrumb {
    background: transparent;
    padding: 0;
    font-size: 0.85rem;
}

.breadcrumb-item a {
    color: var(--primary-color);
    text-decoration: none;
}

.breadcrumb-item a:hover {
    text-decoration: underline;
}

/* =============================================
   CARDS
   ============================================= */

.card {
    border: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    border-radius: 8px;
}

.card-header {
    background: white;
    border-bottom: 1px solid #eee;
    padding: 15px 20px;
}

.card-header h5 {
    margin: 0;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Stat Cards */
.stat-card {
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.stat-card .card-title {
    font-size: 2rem;
    font-weight: 700;
}

.stat-card .card-subtitle {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-card-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-card-icon {
    font-size: 2.5rem;
    opacity: 0.3;
}

/* =============================================
   TABLES
   ============================================= */

.table {
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
    border-top: none;
    padding: 12px 15px;
}

.table td {
    padding: 12px 15px;
    vertical-align: middle;
}

/* Colonne numeriche e azioni: mai andare a capo */
.table td.text-end,
.table td.text-center,
.table .text-nowrap {
    white-space: nowrap;
}

.table tbody tr {
    transition: background-color 0.2s;
}

.table-hover tbody tr:hover {
    background-color: #f8f9fa;
}

/* Sortable column headers */
.table th a {
    color: #6c757d;
}

.table th a:hover {
    color: var(--primary-color);
}

/* =============================================
   FORMS
   ============================================= */

.form-label {
    font-weight: 500;
    margin-bottom: 5px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(44, 62, 80, 0.15);
}

.input-group-text {
    background: #f8f9fa;
    border-color: #dee2e6;
}

/* =============================================
   BUTTONS
   ============================================= */

.btn {
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 6px;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-success {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

.btn-group-sm .btn {
    padding: 4px 8px;
}

/* Quick Action Buttons */
.quick-action-btn {
    padding: 12px 16px;
    border-radius: 8px;
    transition: all 0.2s;
}

.quick-action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

/* =============================================
   BADGES
   ============================================= */

.badge {
    font-weight: 500;
    padding: 5px 10px;
}

/* =============================================
   ALERTS
   ============================================= */

.alert {
    border: none;
    border-radius: 8px;
}

/* =============================================
   TOAST SYSTEM
   ============================================= */

.toast-container {
    z-index: 1090 !important;
}

.toast {
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
}

.toast-success {
    border-left: 4px solid var(--success-color);
}

.toast-danger {
    border-left: 4px solid var(--danger-color);
}

.toast-warning {
    border-left: 4px solid var(--warning-color);
}

.toast-info {
    border-left: 4px solid #17a2b8;
}

/* =============================================
   EMPTY STATE
   ============================================= */

.empty-state {
    padding: 40px 20px;
}

.empty-state .display-1 {
    font-size: 4rem;
}

/* =============================================
   SKELETON LOADING
   ============================================= */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 14px;
    width: 100%;
    margin: 6px 0;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =============================================
   ERROR PAGES
   ============================================= */

.error-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.error-container h1 {
    font-size: 6rem;
    font-weight: 700;
    color: #6c757d;
}

/* =============================================
   UTILITIES
   ============================================= */

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* =============================================
   PAGINATION RESPONSIVE
   ============================================= */

.pagination-wrapper {
    flex-wrap: wrap;
    gap: 0.5rem;
}

.pagination-wrapper .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
}

/* =============================================
   TABLE CONTAINMENT
   ============================================= */

.card {
    overflow: hidden;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* =============================================
   FILTER BAR - Search + Filtri collapsabili
   ============================================= */

.filter-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.filter-bar .filter-search {
    flex: 1;
}

.filter-advanced {
    padding-top: 0.75rem;
}

.filter-advanced .row {
    --bs-gutter-x: 0.5rem;
    --bs-gutter-y: 0.5rem;
}

/* =============================================
   RESPONSIVE - TABLET (max 992px)
   ============================================= */

@media (max-width: 992px) {
    .sidebar {
        margin-left: calc(-1 * var(--sidebar-width));
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1050;
        box-shadow: none;
    }

    .sidebar.active {
        margin-left: 0;
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.3);
    }

    #content {
        margin-left: 0;
    }

    /* Overlay scuro quando sidebar aperta */
    .sidebar.active::after {
        content: '';
        position: fixed;
        top: 0;
        left: var(--sidebar-width);
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }

    /* Main content padding ridotto */
    #content main {
        padding: 1rem !important;
    }

    /* Sidebar touch targets piu grandi */
    .sidebar .nav-link {
        padding: 12px 20px;
        font-size: 0.95rem;
    }

    .sidebar-submenu .nav-link {
        padding: 10px 20px 10px 42px;
        font-size: 0.9rem;
    }

    /* Header pagina: wrap bottoni */
    #mainContent > .d-flex.justify-content-between {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    #mainContent > .d-flex.justify-content-between > div {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    /* Paginazione: stack verticale su tablet */
    .pagination-wrapper {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .pagination-wrapper .pagination .page-link {
        padding: 0.35rem 0.6rem;
        font-size: 0.8rem;
    }
}

/* =============================================
   RESPONSIVE - MOBILE (max 768px)
   ============================================= */

@media (max-width: 768px) {
    .login-card {
        padding: 30px 20px;
    }

    #content main {
        padding: 0.75rem !important;
    }

    .card-body {
        padding: 12px;
    }

    .card-header {
        padding: 10px 12px;
    }

    /* Tabelle compatte */
    .table th {
        padding: 8px 6px;
        font-size: 0.7rem;
        letter-spacing: 0;
    }

    .table td {
        padding: 8px 6px;
        font-size: 0.8rem;
    }

    /* Stat cards */
    .stat-card .card-title {
        font-size: 1.5rem;
    }

    .stat-card-value {
        font-size: 1.4rem;
    }

    .stat-card-icon {
        font-size: 1.8rem;
    }

    .breadcrumb {
        font-size: 0.75rem;
    }

    .navbar {
        padding: 8px 12px;
    }

    .navbar .nav-link .badge {
        display: none;
    }

    .alert {
        font-size: 0.85rem;
        padding: 8px 12px;
    }

    /* Paginazione compatta */
    .pagination-wrapper .pagination .page-link {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .pagination-wrapper > small,
    .pagination-wrapper > div {
        font-size: 0.75rem;
    }

    /* Modal full-width */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-lg {
        max-width: calc(100% - 1rem);
    }

    /* Header pagina: stack verticale */
    #mainContent > .d-flex.justify-content-between {
        flex-direction: column;
        align-items: flex-start !important;
    }

    #mainContent > .d-flex.justify-content-between > div {
        width: 100%;
    }

    .empty-state {
        padding: 20px 10px;
    }

    .empty-state .display-1 {
        font-size: 2.5rem;
    }
}

/* =============================================
   RESPONSIVE - SMALL MOBILE (max 576px)
   ============================================= */

@media (max-width: 576px) {
    :root {
        --sidebar-width: 240px;
    }

    #content main {
        padding: 0.5rem !important;
    }

    .card-body {
        padding: 10px;
    }

    .table th,
    .table td {
        padding: 6px 4px;
        font-size: 0.75rem;
    }

    .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .btn-sm {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    .stat-card .card-body {
        padding: 10px;
    }

    .stat-card .card-title {
        font-size: 1.2rem;
    }

    h2 {
        font-size: 1.3rem;
    }

    h5 {
        font-size: 1rem;
    }
}

/* =============================================
   SCROLLBAR
   ============================================= */

.sidebar::-webkit-scrollbar {
    width: 5px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* =============================================
   LOADING STATES
   ============================================= */

.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =============================================
   PRICE FORMATTING - prezzo a sinistra, EUR a destra
   ============================================= */
.price {
    display: inline-flex;
    justify-content: flex-end;
    align-items: baseline;
    gap: 0.25em;
    white-space: nowrap;
}
.price-val {
    text-align: right;
}
.price-cur {
    text-align: right;
    color: #6c757d;
    font-size: 0.8em;
}
