:root {
    --primary: #13425f;
    --primary-dark: #0d2f45;
    --success: #28a745;
    --warning: #fd7e14;
    --danger: #dc3545;
    --purple: #6f42c1;
    --info: #17a2b8;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-600: #6c757d;
    --gray-800: #343a40;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
    color: var(--gray-800);
}

/* SIDEBAR */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 250px;
    background: var(--primary);
    color: #fff;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-logo {
    font-size: 22px;
    font-weight: bold;
    color: #fff;
    text-decoration: none;
	border-radius: 50px;
	padding: 14px;
	background: #fff;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
}

.sidebar-user {
    padding: 15px 20px;
    background: rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

.sidebar-userinfo {
    font-size: 14px;
    overflow: hidden;
}

.sidebar-userinfo small {
    opacity: 0.7;
}

.sidebar-menu {
    flex: 1;
    padding: 15px 0;
    overflow-y: auto;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.2s;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.sidebar-menu a.active {
    border-left: 3px solid #fff;
}

.sidebar-menu i {
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    padding: 10px;
    border-radius: 5px;
}

.sidebar-footer a:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* MAIN CONTENT */
.main {
    margin-left: 250px;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.topbar {
    background: #fff;
    padding: 15px 30px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar h1 {
    font-size: 24px;
    color: var(--gray-800);
}

.topbar-info {
    color: var(--gray-600);
    font-size: 14px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--gray-800);
    cursor: pointer;
    padding: 5px;
}

.content {
    padding: 30px;
}

/* OVERLAY */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* CARDS */
.card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.card-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    color: var(--gray-800);
}

.card-body {
    padding: 20px;
}

/* STAT CARDS */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 15px;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary); }
.stat-icon.green { background: var(--success); }
.stat-icon.orange { background: var(--warning); }
.stat-icon.purple { background: var(--purple); }

.stat-value {
    font-size: 28px;
    font-weight: bold;
    color: var(--gray-800);
}

.stat-label {
    color: var(--gray-600);
    font-size: 14px;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--gray-600); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* FORMS */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--gray-800);
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 5px;
    font-size: 14px;
    -webkit-appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

.form-control:disabled,
.form-control[readonly] {
    background: var(--gray-100);
}

select.form-control {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 35px;
    background-color: #fff;
}

.password-wrapper {
    position: relative;
}

.password-wrapper input {
    width: 100%;
    padding-right: 40px;
}

.toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--gray-600);
}

.toggle-password:hover {
    color: var(--gray-800);
}

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

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

.table th,
.table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    background: var(--gray-100);
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
}

.table tr:hover {
    background: var(--gray-100);
}

/* BADGES */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-success { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-primary { background: #cce5ff; color: #004085; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-secondary { background: #e2e3e5; color: #383d41; }

/* ALERTS */
.alert {
    padding: 15px 20px;
    border-radius: 5px;
    margin-bottom: 20px;
}

.alert-success { background: #d4edda; color: #155724; }
.alert-danger { background: #f8d7da; color: #721c24; }
.alert-warning { background: #fff3cd; color: #856404; }

/* EMPTY STATE */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--gray-600);
}

.empty-state i {
    font-size: 50px;
    margin-bottom: 15px;
    opacity: 0.3;
}

/* GRID */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

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

.login-box {
    background: #fff;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 2px 20px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.login-logo {
    text-align: center;
    margin-bottom: 30px;
    color: var(--primary);
    font-size: 28px;
    font-weight: bold;
}

.hint {
    font-size: 12px;
    color: var(--gray-600);
    margin-top: 5px;
}

/* PAGINATION */
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
    list-style: none;
    padding: 0;
    margin: 0;
}

/* COMMENTS */
.comment {
    padding: 15px;
    border-bottom: 1px solid var(--gray-200);
}

.comment:last-child {
    border-bottom: none;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--gray-600);
}

.comment-text {
    color: var(--gray-800);
}

/* D-FLEX UTILITIES */
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-center { justify-content: center; }
.gap-2 { gap: 10px; }
.flex-wrap { flex-wrap: wrap; }

/* TEXT UTILITIES */
.text-center { text-align: center; }
.text-muted { color: var(--gray-600); }

/* ========================================
   RESPONSIVE - TABLET (max 992px)
======================================== */
@media (max-width: 992px) {
    .content {
        padding: 20px;
    }

    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   RESPONSIVE - MOBILE (max 768px)
======================================== */
@media (max-width: 768px) {
    /* Sidebar nascosta di default */
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: block;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Main senza margin */
    .main {
        margin-left: 0;
    }

    /* Topbar */
    .topbar {
        padding: 12px 15px;
    }

    .topbar h1 {
        font-size: 16px;
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .menu-toggle {
        display: block;
        margin-right: 10px;
    }

    /* Content */
    .content {
        padding: 15px;
    }

    /* Cards */
    .card-header {
        padding: 12px 15px;
        font-size: 14px;
    }

    .card-body {
        padding: 15px;
    }

    /* Stats - 2 colonne su mobile */
    .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 12px;
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .stat-value {
        font-size: 20px;
    }

    .stat-label {
        font-size: 11px;
    }

    /* Buttons */
    .btn {
        padding: 12px 16px;
        font-size: 14px;
    }

    .btn-sm {
        padding: 8px 12px;
    }

    /* Forms - filtri in colonna */
    .form-group label {
        font-size: 13px;
    }

    .form-control {
        padding: 12px;
        font-size: 16px; /* Previene zoom su iOS */
    }

    /* FORM GRID - STACKING VERTICALE */
    [style*="grid-template-columns"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
    }

    [style*="grid-template-columns"] > div,
    [style*="grid-template-columns"] > .form-group {
        width: 100% !important;
    }

    [style*="grid-template-columns"] .btn {
        width: 100%;
        margin-top: 5px;
    }

    /* Tabella responsive */
    .table {
        min-width: 500px;
    }

    .table th,
    .table td {
        padding: 10px 8px;
        font-size: 13px;
    }

    /* Login */
    .login-box {
        padding: 30px 20px;
    }

    .login-logo {
        font-size: 24px;
    }

    /* Azioni tabella */
    td .btn-sm {
        padding: 6px 10px;
    }

    /* Gap 10px sopra tra bottoni impilati */
    .btn + .btn,
    .btn-sm + .btn-sm {
        margin-top: 10px;
    }

    /* Password row in tables */
    tr[id^="pwd-"] td {
        padding: 12px !important;
    }

    tr[id^="pwd-"] form {
        flex-direction: column !important;
        gap: 10px !important;
    }

    tr[id^="pwd-"] input[type="password"] {
        width: 100% !important;
        max-width: none !important;
    }

    tr[id^="pwd-"] span {
        display: block;
        margin-bottom: 5px;
    }

    tr[id^="pwd-"] .btn {
        width: 100%;
    }
}

/* ========================================
   RESPONSIVE - SMALL MOBILE (max 480px)
======================================== */
@media (max-width: 480px) {
    .topbar {
        padding: 10px;
    }

    .topbar h1 {
        font-size: 14px;
    }

    .topbar-info {
        display: none;
    }

    .content {
        padding: 10px;
    }

    .card {
        border-radius: 8px;
        margin-bottom: 12px;
    }

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

    .card-body {
        padding: 12px;
    }

    /* Stats */
    .stat-grid {
        gap: 8px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-icon {
        width: 35px;
        height: 35px;
        font-size: 14px;
    }

    .stat-value {
        font-size: 18px;
    }

    .stat-label {
        font-size: 10px;
    }

    /* Buttons */
    .btn:not(.btn-sm) {
        width: 100%;
        justify-content: center;
    }

    .btn-sm {
        padding: 5px 8px;
        font-size: 11px;
    }

    /* Gap 10px sopra tra bottoni impilati */
    .btn-sm + .btn-sm {
        margin-top: 10px;
    }

    /* Table più compatta */
    .table {
        min-width: 400px;
    }

    .table th,
    .table td {
        padding: 8px 5px;
        font-size: 11px;
    }

    .badge {
        padding: 2px 6px;
        font-size: 10px;
    }

    code {
        font-size: 10px !important;
    }

    /* Alert compatto */
    .alert {
        padding: 10px 12px;
        font-size: 13px;
    }

    /* Form compatto */
    .form-group {
        margin-bottom: 10px;
    }

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

    .empty-state i {
        font-size: 30px;
        margin-bottom: 10px;
    }

    .empty-state p {
        font-size: 13px;
    }
}

/* ========================================
   PRINT STYLES
======================================== */
@media print {
    .sidebar,
    .topbar,
    .btn,
    .sidebar-overlay {
        display: none !important;
    }

    .main {
        margin-left: 0 !important;
    }

    .content {
        padding: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ddd;
    }
}

/* ========================================
   SIDEBAR COLLASSABILE (desktop / tablet / smartphone in orizzontale, > 768px)
   Stato in sessionStorage: resta chiusa navigando tra le pagine, al nuovo accesso torna visibile.
======================================== */
.sidebar-collapse,
.sidebar-expand {
    display: none;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    padding: 0;
}
@media (min-width: 769px) {
    .sidebar-collapse {
        display: flex;
        position: absolute;
        top: 22px;
        right: -14px;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: #fff;
        color: var(--primary);
        box-shadow: 0 1px 6px rgba(0,0,0,0.3);
        font-size: 12px;
        z-index: 1001;
    }
    .sidebar-expand {
        width: 34px;
        height: 34px;
        margin-right: 12px;
        border-radius: 8px;
        background: var(--primary);
        color: #fff;
        font-size: 14px;
        flex: 0 0 auto;
    }
    html.sb-collapsed .sidebar-expand { display: flex; }
    html.sb-collapsed .sidebar {
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform 0.3s ease, visibility 0s linear 0.3s;
    }
    html.sb-collapsed .sidebar-collapse { display: none; }
    html.sb-collapsed .main { margin-left: 0; }
    html.sb-collapsed .topbar h1 { margin-right: auto; }
}
