:root {
    --sidebar-width: 240px;
    --sidebar-bg: #1e2a3b;
    --sidebar-text: #c8d6e5;
    --sidebar-active: #3498db;
    --sidebar-hover: rgba(255,255,255,0.07);
    --brand-color: #3498db;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f5f7fa;
    color: #2c3e50;
}

/* ── Sidebar ── */
#sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s ease;
}

/* ── Sidebar collapsed (icon-only) ── */
#wrapper.sidebar-hidden #sidebar {
    width: 54px;
    min-width: 54px;
}

#wrapper.sidebar-hidden .sidebar-brand {
    padding: 1rem 0;
    justify-content: center;
}
/* Sidebar compressa: nascondi logo e nome, mostra solo il tasto apri/chiudi */
#wrapper.sidebar-hidden .sidebar-brand-inner { display: none; }

#wrapper.sidebar-hidden .sidebar-link {
    justify-content: center;
    padding: 0.65rem 0;
    gap: 0;
}
#wrapper.sidebar-hidden .sidebar-link .nav-label { display: none; }
#wrapper.sidebar-hidden .sidebar-link i { margin: 0 !important; font-size: 1.15rem; }

#wrapper.sidebar-hidden .sidebar-section { display: none; }

#wrapper.sidebar-hidden .sidebar-footer { padding: 0.75rem 0; text-align: center; }
#wrapper.sidebar-hidden .user-info { display: none; }
#wrapper.sidebar-hidden .sidebar-footer .logout-label { display: none; }
#wrapper.sidebar-hidden .sidebar-footer form { margin: 0 !important; }
#wrapper.sidebar-hidden .sidebar-footer .btn { padding: 0.4rem 0; width: 100%; border-radius: 0; border-left: none; border-right: none; }

#sidebar-toggle-btn {
    background: none;
    border: none;
    color: #fff;
    padding: 0;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    flex-shrink: 0;
    opacity: 0.85;
    transition: opacity 0.15s;
}
#sidebar-toggle-btn:hover { opacity: 1; }

.sidebar-brand-inner .logo-img {
    height: 1.5rem;
    max-width: 8rem;
    object-fit: contain;
}

.sidebar-brand {
    padding: 1.25rem 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.sidebar-menu {
    padding: 0.5rem 0;
}

.sidebar-section {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: rgba(200,214,229,0.45);
    padding: 0.9rem 1rem 0.25rem;
    text-transform: uppercase;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: 0;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-link.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 500;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.85rem;
}

.user-info {
    color: var(--sidebar-text);
    margin-bottom: 0.5rem;
    word-break: break-all;
}

#page-content-wrapper {
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Page header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #e9ecef;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    color: #1e2a3b;
}

/* ── Cards ── */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    font-weight: 600;
    border-radius: 10px 10px 0 0 !important;
}

/* ── Confirm modal ── */
.confirm-modal-content {
    border: none;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
}

.confirm-modal-content .modal-header {
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    border-radius: 12px 12px 0 0;
}

.confirm-modal-content .modal-title {
    font-weight: 600;
    color: var(--brand-color);
}

.confirm-modal-content .modal-body {
    padding: 1.25rem 1.5rem;
    font-size: 0.98rem;
}

/* ── Tables ── */
.table th {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6c757d;
    border-top: none;
}

.table-hover tbody tr:hover {
    background: #f8f9ff;
}

/* ── Buttons ── */
.btn-sm {
    font-size: 0.8rem;
}

/* ── Product images ── */
.product-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.product-image-card {
    position: relative;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    overflow: hidden;
    background: #f8f9fa;
}

.product-image-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.product-image-card .image-actions {
    padding: 0.4rem;
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    background: #fff;
}

.product-image-card.is-main {
    border-color: var(--brand-color);
}

.product-image-card .main-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    font-size: 0.65rem;
    background: var(--brand-color);
    color: #fff;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

/* ── Catalog grid ── */
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 0.85rem;
}

.catalog-card-wrapper {
    display: flex;
}

.catalog-card {
    border: 1px solid #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: box-shadow 0.2s, transform 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.catalog-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

.catalog-card img {
    width: 100%;
    height: 115px;
    object-fit: cover;
    flex-shrink: 0;
}

.catalog-card .no-image {
    width: 100%;
    height: 115px;
    background: #f5f7fa;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ced4da;
    font-size: 2rem;
    flex-shrink: 0;
}

.catalog-card .card-body {
    padding: 0.6rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.catalog-card .card-actions {
    margin-top: auto;
    padding-top: 0.5rem;
}

.catalog-card .product-name {
    font-weight: 600;
    font-size: 0.85rem;
    line-height: 1.3;
    margin-bottom: 0.15rem;
    color: #1e2a3b;
}

.catalog-card .product-code {
    font-size: 0.72rem;
    color: #6c757d;
}

.catalog-card .product-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--brand-color);
    margin-top: 0.4rem;
}

.catalog-discount-row {
    font-size: .72rem;
    line-height: 1.2;
    min-height: 1.1rem;
    margin-top: 0.1rem;
}

/* ── Catalog list view ── */
.catalog-grid.catalog-list-view {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.catalog-list-view .catalog-card-wrapper {
    width: 100%;
}

.catalog-list-view .catalog-card {
    flex-direction: row;
    align-items: center;
}

.catalog-list-view .catalog-card img,
.catalog-list-view .catalog-card .no-image {
    width: 64px;
    height: 64px;
    flex-shrink: 0;
}

.catalog-list-view .catalog-card .no-image {
    font-size: 1.4rem;
}

.catalog-list-view .catalog-card .card-body {
    display: grid;
    grid-template-columns: minmax(160px, 1.4fr) minmax(150px, 1fr) minmax(110px, auto) 270px;
    grid-template-areas:
        "name code  price actions"
        "name cat   disc  actions";
    column-gap: 1rem;
    row-gap: 0.1rem;
    align-items: center;
    align-content: center;
    padding: 0.5rem 0.75rem;
    width: 100%;
}

.catalog-list-view .catalog-card .product-name {
    grid-area: name;
    margin-bottom: 0;
}

.catalog-list-view .catalog-card .product-code {
    grid-area: code;
    align-self: end;
}

.catalog-list-view .catalog-card .product-category {
    grid-area: cat;
    align-self: start;
}

.catalog-list-view .catalog-card .product-price {
    grid-area: price;
    margin-top: 0;
    align-self: end;
    white-space: nowrap;
}

.catalog-list-view .catalog-card .catalog-discount-row {
    grid-area: disc;
    min-height: 0;
    align-self: start;
    white-space: nowrap;
}

.catalog-list-view .catalog-card .card-actions {
    grid-area: actions;
    margin-top: 0;
    padding-top: 0;
    width: 270px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.25rem;
}

.catalog-list-view .catalog-card .card-actions > .text-muted {
    margin-bottom: 0;
}

.catalog-list-view .catalog-card .card-actions .btn-group {
    width: 100%;
    margin-bottom: 0;
}

@media (max-width: 991.98px) {
    .catalog-list-view .catalog-card .card-body {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "name    price"
            "code    disc"
            "cat     cat"
            "actions actions";
    }

    .catalog-list-view .catalog-card .card-actions {
        width: 100%;
    }
}

/* ── Product detail modal ── */
.pm-clickable {
    cursor: pointer;
}

.pm-gallery {
    background: #f5f7fa;
    border-radius: 8px;
    overflow: hidden;
}

.pm-main-img {
    width: 100%;
    height: 280px;
    object-fit: contain;
    background: #fff;
}

.pm-no-image {
    width: 100%;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ced4da;
    font-size: 3rem;
}

.pm-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.85;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.pm-nav-prev { left: 8px; }
.pm-nav-next { right: 8px; }

.pm-img-counter {
    position: absolute;
    bottom: 8px;
    right: 8px;
    font-size: 0.7rem;
}

.pm-thumb {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
}

.pm-thumb-active {
    border-color: var(--brand-color);
}

/* ── Cart ── */
.cart-badge {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
}

/* ── Login page ── */
.login-page {
    background: linear-gradient(135deg, #1e2a3b 0%, #2c3e50 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-logo .icon {
    font-size: 3rem;
    color: var(--brand-color);
}

.login-logo .logo-img {
    height: 3rem;
    max-width: 220px;
    object-fit: contain;
}

.login-logo h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: #1e2a3b;
    margin-top: 0.5rem;
}

.login-logo p {
    color: #6c757d;
    font-size: 0.9rem;
    margin: 0;
}

/* ── Stat cards ── */
.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    color: #1e2a3b;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: 0.15rem;
}

/* ── Price list table ── */
.pricelist-table input[type="number"] {
    max-width: 120px;
    text-align: right;
}

/* ── Order status badges ── */
.badge-pending   { background: #ffc107; color: #000; }
.badge-confirmed { background: #198754; color: #fff; }
.badge-validated { background: #0d6efd; color: #fff; }
.badge-cancelled { background: #dc3545; color: #fff; }

/* ── Sidebar backdrop (mobile overlay) ── */
#sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1054;
}
#sidebar-backdrop.active { display: block; }

/* ── Page header: wrap buttons on narrow screens ── */
.page-header {
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ── Touch-friendly btn-sm on mobile/tablet ── */
@media (max-width: 991px) {
    .btn-sm {
        min-height: 36px;
        padding-left: 0.65rem;
        padding-right: 0.65rem;
    }
}

/* ── Tablet: hide secondary table columns ── */
.col-hide-tablet { display: none; }
@media (min-width: 992px) {
    .col-hide-tablet { display: table-cell; }
}

/* ── Responsive ── */
@media (max-width: 991px) {
    /* Sidebar: fixed 54px icon strip, always visible */
    #sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100vh !important;
        width: 54px !important;
        min-width: 54px !important;
        z-index: 1055;
        overflow-x: hidden;
        overflow-y: auto;
        transition: width 0.25s ease, box-shadow 0.25s ease;
    }

    /* When expanded: overlay the content without shifting it */
    #sidebar.mobile-expanded {
        width: var(--sidebar-width) !important;
        box-shadow: 6px 0 24px rgba(0,0,0,0.35);
    }

    /* Icon-only styles when NOT expanded */
    #sidebar:not(.mobile-expanded) .sidebar-brand {
        padding: 1rem 0;
        justify-content: center;
    }
    /* Sidebar compressa (mobile): nascondi logo e nome, mostra solo il tasto apri/chiudi */
    #sidebar:not(.mobile-expanded) .sidebar-brand-inner { display: none; }
    #sidebar:not(.mobile-expanded) .sidebar-link {
        justify-content: center;
        padding: 0.65rem 0;
        gap: 0;
    }
    #sidebar:not(.mobile-expanded) .sidebar-link .nav-label { display: none; }
    #sidebar:not(.mobile-expanded) .sidebar-link i { margin: 0 !important; font-size: 1.15rem; }
    #sidebar:not(.mobile-expanded) .sidebar-section { display: none; }
    #sidebar:not(.mobile-expanded) .sidebar-footer { padding: 0.75rem 0; text-align: center; }
    #sidebar:not(.mobile-expanded) .user-info { display: none; }
    #sidebar:not(.mobile-expanded) .sidebar-footer .logout-label { display: none; }
    #sidebar:not(.mobile-expanded) .sidebar-footer form { margin: 0 !important; }
    #sidebar:not(.mobile-expanded) .sidebar-footer .btn {
        padding: 0.4rem 0;
        width: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    /* Content area offset to account for the fixed 54px sidebar */
    #wrapper { padding-left: 54px; }
}

@media (min-width: 992px) {
    #sidebar-backdrop { display: none !important; }
    #wrapper { padding-left: 0; }
}

@media (max-width: 576px) {
    .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
