:root {
    --sidebar-width: 220px;
    --primary: #2563eb;

    /* Design tokens */
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.07);

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2rem;

    --font-size-sm: 0.8rem;
    --font-size-base: 0.92rem;
    --font-size-lg: 1.05rem;
}

body {
    background: var(--color-bg);
    color: var(--color-text);
    font-size: var(--font-size-base);
}

/* Componenti Bootstrap: reskin leggero, no gradienti/skeuomorfismo */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
}

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

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

.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border-color: var(--color-border);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.card {
    border-color: var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

/* Touch target minimo su mobile */
@media (max-width: 768px) {
    .btn,
    .form-control,
    .form-select {
        min-height: 44px;
    }
    .btn-sm {
        min-height: 38px;
    }
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: #1e293b;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    transition: transform 0.3s;
}

#sidebar .brand {
    padding: 1.2rem 1rem;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid #334155;
    letter-spacing: 0.03em;
}

#sidebar .nav-link {
    color: #94a3b8;
    padding: 0.55rem 1rem;
    border-radius: 0;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#sidebar .nav-link:hover,
#sidebar .nav-link.active {
    color: #fff;
    background: #334155;
}

#sidebar .nav-group {
    margin-top: 0.2rem;
}

#sidebar .nav-section {
    padding: 0.75rem 1rem 0.2rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #cbd5e1;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    justify-content: space-between;
}

#sidebar .nav-section .title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

#sidebar .nav-section .title i {
    font-size: 0.85rem;
}

#sidebar .nav-section::-webkit-details-marker {
    display: none;
}

#sidebar .nav-section::after {
    content: "\25BE";
    font-size: 0.75rem;
    transition: transform 0.2s;
}

#sidebar .nav-group[open] > .nav-section::after {
    transform: rotate(180deg);
}

/* Main content */
#main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: 1.5rem;
}

@media (max-width: 768px) {
    #sidebar {
        transform: translateX(-100%);
    }
    #sidebar.open {
        transform: translateX(0);
    }
    #main-content {
        margin-left: 0;
    }
}

/* Topbar */
.topbar {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 0.6rem 1.2rem;
    margin: -1.5rem -1.5rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.topbar h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

/* Cards */
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
}

.stat-card .stat-label {
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: 0.3rem;
}

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

/* Tables */
.table-hover tbody tr:hover {
    background-color: #f1f5f9;
}

.badge-stato-emessa      { background: #dbeafe; color: #1d4ed8; }
.badge-stato-scaduta     { background: #fee2e2; color: #b91c1c; }
.badge-stato-pagata      { background: #dcfce7; color: #15803d; }
.badge-stato-parzialmente_pagata { background: #fef9c3; color: #854d0e; }
.badge-stato-in_attesa   { background: #f1f5f9; color: #475569; }
.badge-stato-accettato   { background: #dcfce7; color: #15803d; }
.badge-stato-scaduto     { background: #fee2e2; color: #b91c1c; }
.badge-stato-rifiutato   { background: #fee2e2; color: #b91c1c; }

.badge-stato {
    display: inline-block;
    padding: 0.2em 0.65em;
    border-radius: 9999px;
    font-size: var(--font-size-sm);
    font-weight: 600;
}

/* Forms */
.form-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
}

/* Tabelle: scroll orizzontale contenuto invece di rompere il layout */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .form-card.p-0 {
        padding: 0;
    }
    table.righe-table td,
    table.righe-table th {
        white-space: nowrap;
    }
}

/* Righe fattura */
.righe-table th {
    background: #f8fafc;
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
    border-bottom: 2px solid #e2e8f0;
}

.righe-table td {
    vertical-align: middle;
}

.righe-table input {
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    font-size: 0.88rem;
    width: 100%;
    background: transparent;
}

.righe-table input:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

/* PDF inline viewer */
.pdf-viewer {
    width: 100%;
    height: 600px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
}

/* Print / mobile helpers */
.mobile-toggle {
    display: none;
}
@media (max-width: 768px) {
    .mobile-toggle { display: inline-flex; }
}
