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

:root {
    --primary: #1e3a5f;
    --primary-light: #2d5a87;
    --accent: #00d4aa;
    --accent-hover: #00b894;
    --danger: #e74c3c;
    --warning: #f39c12;
    --success: #27ae60;
    --bg: #f0f4f8;
    --card: #ffffff;
    --text: #333;
    --text-light: #666;
    --border: #e0e6ed;
}

/* Dark Mode */
[data-theme="dark"] {
    --primary: #8fa8c9;
    --primary-light: #a8c0db;
    --accent: #00d4aa;
    --accent-hover: #00e4b8;
    --danger: #ff6b6b;
    --warning: #ffc145;
    --success: #51cf66;
    --bg: #1a1d23;
    --card: #252830;
    --text: #e4e6eb;
    --text-light: #a8adb5;
    --border: #363a45;
}

[data-theme="dark"] .login-container {
    background: linear-gradient(-45deg, #1a1d23, #252830, #2d3748, #1a1d23);
}

[data-theme="dark"] .login-box {
    background: rgba(37, 40, 48, 0.95);
}

[data-theme="dark"] .header {
    background: #252830;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

[data-theme="dark"] .stat-icon.blue { background: #2d3a4d; }
[data-theme="dark"] .stat-icon.green { background: #2d3d35; }
[data-theme="dark"] .stat-icon.orange { background: #3d3530; }
[data-theme="dark"] .stat-icon.purple { background: #352d3d; }
[data-theme="dark"] .stat-icon.cyan { background: #1a3a3d; }
[data-theme="dark"] .stat-icon.red { background: #3d2020; }
[data-theme="dark"] .stat-icon.yellow { background: #3d3520; }
[data-theme="dark"] .stat-icon.pink { background: #3d2030; }

[data-theme="dark"] .badge {
    background: linear-gradient(135deg, #2d3748 0%, #363a45 100%);
    color: var(--text);
}

[data-theme="dark"] .data-table th {
    background: #1a1d23;
}

[data-theme="dark"] .data-table tr:hover {
    background: #2d3748;
}

[data-theme="dark"] .tab-btn {
    background: #1a1d23;
    color: var(--text);
}

[data-theme="dark"] .tab-btn:hover {
    background: #2d3748;
}

[data-theme="dark"] .tab-btn.active {
    background: var(--accent);
    color: #1a1d23;
}

[data-theme="dark"] .modal-content {
    background: var(--card);
}

[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group textarea,
[data-theme="dark"] .form-group select {
    background: #1a1d23;
    border-color: var(--border);
    color: var(--text);
}

[data-theme="dark"] .quick-action {
    background: #1a1d23;
}

[data-theme="dark"] .quick-action:hover {
    background: #2d3748;
}

[data-theme="dark"] .scadenza-item {
    background: #1a1d23;
}

[data-theme="dark"] .scadenza-item.warning {
    background: #3d3520;
    border-left-color: var(--warning);
}

[data-theme="dark"] .scadenza-item.danger {
    background: #3d2020;
    border-left-color: var(--danger);
}

/* Bottone tema */
.btn-theme {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 8px;
    transition: background 0.2s;
}

.btn-theme:hover {
    background: rgba(255,255,255,0.1);
}

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

/* ============ LOGIN ============ */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(-45deg, #1e3a5f, #2d5a87, #00d4aa, #1e3a5f);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    position: relative;
    overflow: hidden;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.login-container::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-box {
    background: rgba(255, 255, 255, 0.95);
    padding: 50px 40px;
    border-radius: 20px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
    backdrop-filter: blur(10px);
}

.login-box .logo { text-align: center; margin-bottom: 30px; }
.login-box .logo-icon { font-size: 48px; margin-bottom: 10px; }
.login-box h1 { text-align: center; color: var(--primary); font-size: 24px; margin-bottom: 8px; }
.login-box .subtitle { text-align: center; color: var(--text-light); font-size: 14px; margin-bottom: 30px; }

.login-box .form-group { margin-bottom: 20px; }
.login-box .form-group label { display: block; margin-bottom: 8px; font-weight: 500; font-size: 14px; }
.login-box input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    transition: all 0.3s;
}
.login-box input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0, 212, 170, 0.1); }

.login-box button[type="submit"] {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.login-box button[type="submit"]:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0, 212, 170, 0.4); }

.login-error { background: #fee; color: var(--danger); padding: 12px; border-radius: 8px; text-align: center; margin-bottom: 20px; display: none; }

/* ============ APP ============ */
.app-container { display: none; }

/* ============ HEADER ============ */
.header {
    background: var(--card);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.header-brand { display: flex; align-items: center; gap: 12px; }
.header-brand .icon { font-size: 28px; }
.header h1 { font-size: 20px; color: var(--primary); }
.header-center { flex: 1; max-width: 500px; margin: 0 30px; }
.header-right { display: flex; align-items: center; gap: 20px; }
.header-user { color: var(--text-light); font-size: 14px; }

/* Search Box */
.search-box { position: relative; }
.search-box input {
    width: 100%;
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s;
}
.search-box input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--card);
}
.search-box input::placeholder { color: var(--text-light); }

.search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card);
    border: 2px solid var(--border);
    border-top: none;
    border-radius: 0 0 10px 10px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 150;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}
.search-results.active { display: block; }

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg); }

.search-result-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: var(--bg);
}
.search-result-info { flex: 1; }
.search-result-info strong { display: block; font-size: 14px; color: var(--text); }
.search-result-info span { font-size: 12px; color: var(--text-light); }

.search-no-results {
    padding: 20px;
    text-align: center;
    color: var(--text-light);
}

.search-result-info mark {
    background: rgba(0, 212, 170, 0.3);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

[data-theme="dark"] .search-box input {
    background: #1a1d23;
    border-color: var(--border);
}
[data-theme="dark"] .search-box input:focus {
    background: var(--card);
}
[data-theme="dark"] .search-results {
    background: var(--card);
    border-color: var(--border);
}
[data-theme="dark"] .search-result-item:hover {
    background: #2d3748;
}
.btn-logout { background: var(--bg); color: var(--text); border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; transition: all 0.2s; }
.btn-logout:hover { background: #e0e6ed; }

/* ============ MAIN - SFONDO ANIMATO ============ */
body.logged-in {
    background: linear-gradient(-45deg, #e8ecf3, #f0f4fa, #e5eef7, #f5f7fb, #e8ecf3);
    background-size: 300% 300%;
    animation: dashboardBG 8s ease infinite;
}

body.logged-in::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%236876B2' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

body.logged-in[data-theme="dark"] {
    background: linear-gradient(-45deg, #08090c, #0c0e14, #10131a, #0a0c10, #08090c);
    background-size: 300% 300%;
    animation: dashboardBG 8s ease infinite;
}

body.logged-in[data-theme="dark"]::before {
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%236876B2' fill-opacity='0.08'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

@keyframes dashboardBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.main-content { 
    margin-top: 70px; 
    padding: 30px; 
    max-width: 1400px; 
    margin-left: auto; 
    margin-right: auto;
    min-height: calc(100vh - 70px);
    position: relative;
    z-index: 1;
}

/* ============ DASHBOARD ============ */
.dashboard-welcome { margin-bottom: 30px; }
.dashboard-welcome h2 { font-size: 28px; color: var(--primary); margin-bottom: 5px; }
.dashboard-welcome p { color: var(--text-light); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { background: var(--card); border-radius: 16px; padding: 24px; box-shadow: 0 2px 12px rgba(0,0,0,0.06); display: flex; align-items: center; gap: 16px; transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-3px); }
.stat-icon { width: 56px; height: 56px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; }
.stat-icon.blue { background: #e3f2fd; }
.stat-icon.green { background: #e8f5e9; }
.stat-icon.orange { background: #fff3e0; }
.stat-icon.purple { background: #f3e5f5; }
.stat-icon.cyan { background: #e0f7fa; }
.stat-icon.red { background: #ffebee; }
.stat-icon.yellow { background: #fffde7; }
.stat-icon.pink { background: #fce4ec; }
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { transform: translateY(-5px); box-shadow: 0 8px 25px rgba(0,0,0,0.15); border: 2px solid var(--accent); }
.stat-info h3 { font-size: 28px; color: var(--primary); }
.stat-info p { font-size: 13px; color: var(--text-light); }

.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; margin-bottom: 30px; }
@media (max-width: 1024px) { .dashboard-grid { grid-template-columns: 1fr; } }

.dashboard-card { background: var(--card); border-radius: 16px; padding: 24px; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.dashboard-card h3 { font-size: 16px; color: var(--primary); margin-bottom: 20px; display: flex; align-items: center; gap: 10px; }

.activity-list { list-style: none; }
.activity-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.activity-info { flex: 1; }
.activity-info strong { display: block; font-size: 14px; }
.activity-info span { font-size: 12px; color: var(--text-light); }
.activity-time { font-size: 12px; color: var(--text-light); }

.scadenza-item { display: flex; align-items: center; justify-content: space-between; padding: 12px; background: var(--bg); border-radius: 10px; margin-bottom: 10px; }
.scadenza-item:last-child { margin-bottom: 0; }
.scadenza-item.warning { background: #fff8e1; border-left: 4px solid var(--warning); }
.scadenza-item.danger { background: #ffebee; border-left: 4px solid var(--danger); }
.scadenza-info strong { display: block; font-size: 14px; }
.scadenza-info span { font-size: 12px; color: var(--text-light); }
.scadenza-date { font-size: 13px; font-weight: 600; }

.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.quick-action { background: var(--bg); border: none; padding: 20px; border-radius: 12px; cursor: pointer; text-align: center; transition: all 0.2s; }
.quick-action:hover { background: #e0e6ed; transform: translateY(-2px); }
.quick-action .icon { font-size: 24px; margin-bottom: 8px; }
.quick-action span { display: block; font-size: 13px; color: var(--text); }

/* ============ CLIENTI ============ */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.section-header h2 { color: var(--primary); font-size: 22px; }

.btn-primary { background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%); color: white; border: none; padding: 12px 24px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0, 212, 170, 0.3); }
.btn-secondary { background: var(--primary); color: white; border: none; padding: 10px 18px; border-radius: 8px; cursor: pointer; }
.btn-danger { background: var(--danger); color: white; border: none; padding: 10px 18px; border-radius: 8px; cursor: pointer; }
.btn-add { background: var(--success); color: white; padding: 10px 18px; border: none; border-radius: 8px; cursor: pointer; margin-bottom: 16px; }
.btn-small { padding: 6px 12px; font-size: 12px; border: none; border-radius: 6px; cursor: pointer; }
.btn-view { background: var(--primary); color: white; }
.btn-edit { background: var(--warning); color: white; }
.btn-delete { background: var(--danger); color: white; }

/* View Details */
.view-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.view-row {
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.view-row:last-child {
    border-bottom: none;
}
.view-label {
    font-size: 12px;
    color: var(--text-light);
    text-transform: uppercase;
    margin-bottom: 4px;
}
.view-value {
    font-size: 15px;
    color: var(--text);
    white-space: pre-wrap;
}

.clienti-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.cliente-card { background: var(--card); border-radius: 16px; padding: 24px; cursor: pointer; transition: all 0.2s; border: 2px solid transparent; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.cliente-card:hover { transform: translateY(-4px); box-shadow: 0 12px 30px rgba(0,0,0,0.12); border-color: var(--accent); }
.cliente-card h3 { color: var(--primary); margin-bottom: 8px; font-size: 18px; }
.cliente-card p { color: var(--text-light); font-size: 14px; margin-bottom: 12px; }
.badge { display: inline-block; background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); color: var(--primary); padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 500; margin-right: 6px; }

/* ============ CLIENTE DETAIL ============ */
.cliente-detail { display: none; }
.back-btn { display: inline-flex; align-items: center; gap: 8px; color: var(--primary); cursor: pointer; margin-bottom: 20px; font-weight: 500; }
.back-btn:hover { color: var(--accent); }

.cliente-header { background: var(--card); padding: 24px; border-radius: 16px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.cliente-header h2 { color: var(--primary); }
.cliente-actions { display: flex; gap: 10px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; background: var(--card); padding: 16px; border-radius: 16px; margin-bottom: 20px; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.tab-btn { padding: 10px 16px; border: none; background: var(--bg); border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500; transition: all 0.2s; }
.tab-btn:hover { background: #e0e6ed; }
.tab-btn.active { background: var(--primary); color: white; }

.tab-content { background: var(--card); padding: 24px; border-radius: 16px; display: none; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.tab-content.active { display: block; }
.tab-content h3 { color: var(--primary); margin-bottom: 20px; padding-bottom: 12px; border-bottom: 2px solid var(--border); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; }
.form-group input, .form-group textarea, .form-group select { width: 100%; padding: 12px; border: 2px solid var(--border); border-radius: 8px; font-size: 14px; transition: all 0.2s; }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { outline: none; border-color: var(--accent); }
.form-group textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-actions { margin-top: 24px; display: flex; gap: 12px; }
.checkbox-group { display: flex; align-items: center; gap: 10px; }
.checkbox-group input[type="checkbox"] { width: auto; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.data-table th, .data-table td { padding: 14px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--bg); font-weight: 600; font-size: 13px; color: var(--text-light); text-transform: uppercase; }
.data-table tr:hover { background: #f8fafc; }
.data-table .actions { display: flex; gap: 6px; }

/* Modal */
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 200; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal.active { display: flex; }
.modal-content { background: var(--card); padding: 32px; border-radius: 20px; width: 100%; max-width: 600px; max-height: 85vh; overflow-y: auto; box-shadow: 0 25px 50px rgba(0,0,0,0.25); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.modal-header h3 { color: var(--primary); font-size: 20px; }
.modal-close { background: none; border: none; font-size: 28px; cursor: pointer; color: var(--text-light); }
.modal-close:hover { color: var(--danger); }

/* Audit */
.audit-log { max-height: 400px; overflow-y: auto; }
.audit-item { padding: 12px; border-left: 3px solid var(--accent); margin-bottom: 10px; background: var(--bg); border-radius: 0 8px 8px 0; }
.audit-item .timestamp { font-size: 12px; color: var(--text-light); }

/* Empty state */
.empty-state { text-align: center; padding: 48px; color: var(--text-light); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }

/* Autocomplete */
.autocomplete-wrapper { position: relative; }
.autocomplete-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card);
    border: 2px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg); }
.autocomplete-item strong { color: var(--accent); }

[data-theme="dark"] .autocomplete-dropdown {
    background: var(--card);
    border-color: var(--border);
}
[data-theme="dark"] .autocomplete-item:hover {
    background: #2d3748;
}

/* ============ READONLY MODE (per utenti non admin) ============ */
body.readonly-mode .btn-add,
body.readonly-mode .btn-primary,
body.readonly-mode .btn-edit,
body.readonly-mode .btn-delete,
body.readonly-mode .btn-danger,
body.readonly-mode .cliente-actions,
body.readonly-mode .quick-action[onclick*="Nuovo"] {
    display: none !important;
}


/* ============ IMPOSTAZIONI ============ */
.btn-icon {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 8px;
    transition: background 0.2s;
}
.btn-icon:hover {
    background: rgba(0,0,0,0.1);
}
[data-theme="dark"] .btn-icon:hover {
    background: rgba(255,255,255,0.1);
}

.impostazioni-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

.badge-admin {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
}
.badge-cliente {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
}

.log-item {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
}
.log-item.success {
    border-left: 4px solid var(--success);
}
.log-item.failed {
    border-left: 4px solid var(--danger);
}
.log-item.info {
    border-left: 4px solid var(--primary);
}
.log-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.log-info strong {
    font-size: 14px;
}
.log-info span {
    font-size: 12px;
    color: var(--text-light);
}
.log-meta {
    text-align: right;
    font-size: 12px;
    color: var(--text-light);
}
.log-meta span {
    display: block;
}

/* Header logo fix */
.header-logo {
    height: 36px;
    width: auto;
}
.login-logo {
    height: 64px;
    width: auto;
    margin-bottom: 10px;
}

/* Admin only elements */
body.readonly-mode .admin-only {
    display: none !important;
}

/* ============ ALLEGATI ============ */
.allegati-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.allegato-card {
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.allegato-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.allegato-thumb {
    position: relative;
    height: 150px;
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
}

.allegato-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.allegato-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.allegato-thumb:hover .allegato-overlay {
    opacity: 1;
}

.allegato-overlay span {
    color: white;
    font-weight: 600;
    font-size: 14px;
}

.allegato-info {
    padding: 12px;
}

.allegato-info h4 {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.allegato-meta {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-light);
}

.allegato-note {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.allegato-actions {
    padding: 0 12px 12px;
    display: flex;
    gap: 6px;
}

.allegato-actions .btn-small {
    flex: 1;
    text-align: center;
}

/* Progress bar upload */
.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
    animation: progress-animation 1.5s ease-in-out infinite;
}

@keyframes progress-animation {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

/* Dark mode allegati */
[data-theme="dark"] .allegato-card {
    background: #1a1d23;
}

[data-theme="dark"] .allegato-thumb {
    background: #252830;
}

/* ============ RESPONSIVE - MOBILE ============ */
@media (max-width: 768px) {
    /* Header mobile - compatto su una riga */
    .header {
        padding: 10px 15px;
        gap: 10px;
    }
    .header-brand h1 {
        display: none;
    }
    .header-logo {
        height: 28px;
    }
    .header-center {
        flex: 1;
        margin: 0 10px;
        max-width: none;
    }
    .search-box input {
        padding: 8px 12px;
        font-size: 13px;
    }
    .header-right {
        gap: 5px;
    }
    .header-user {
        display: none;
    }
    .btn-logout {
        padding: 6px 10px;
        font-size: 12px;
    }
    .btn-icon {
        padding: 5px;
        font-size: 18px;
    }
    .btn-theme {
        font-size: 18px;
        padding: 5px;
    }
    
    /* Main content */
    .main-content {
        margin-top: 60px;
        padding: 15px;
    }
    
    /* Dashboard */
    .dashboard-welcome h2 {
        font-size: 22px;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    .stat-card {
        padding: 16px;
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }
    .stat-icon {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
    .stat-info h3 {
        font-size: 22px;
    }
    .stat-info p {
        font-size: 11px;
    }
    
    /* Quick actions */
    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
    }
    .quick-action {
        padding: 15px 10px;
    }
    .quick-action .icon {
        font-size: 20px;
    }
    .quick-action span {
        font-size: 11px;
    }
    
    /* Section header */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    .section-header > div {
        width: 100%;
        flex-direction: column !important;
    }
    .section-header button {
        width: 100%;
    }
    
    /* Clienti grid */
    .clienti-grid {
        grid-template-columns: 1fr;
    }
    
    /* Cliente header */
    .cliente-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    .cliente-header h2 {
        font-size: 18px;
    }
    .cliente-actions {
        width: 100%;
        flex-wrap: wrap;
        justify-content: center;
    }
    .cliente-actions button {
        flex: 1;
        min-width: 80px;
        padding: 8px 12px;
        font-size: 12px;
    }
    
    /* Tabs - scrollable horizontal */
    .tabs {
        padding: 12px;
        gap: 8px;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .tab-btn {
        padding: 8px 12px;
        font-size: 12px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    /* Tab content */
    .tab-content {
        padding: 16px;
    }
    .tab-content h3 {
        font-size: 16px;
    }
    
    /* Tables - card style on mobile */
    .data-table {
        display: block;
    }
    .data-table thead {
        display: none;
    }
    .data-table tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    .data-table tr {
        display: flex;
        flex-direction: column;
        background: var(--bg);
        padding: 12px;
        border-radius: 10px;
        border: 1px solid var(--border);
    }
    .data-table td {
        display: block;
        padding: 8px 0;
        border-bottom: 1px solid var(--border);
        text-align: left;
    }
    .data-table td:last-child {
        border-bottom: none;
    }
    .data-table .actions {
        justify-content: flex-start;
        padding-top: 10px;
    }
    
    /* Modal */
    .modal-content {
        margin: 15px;
        padding: 20px;
        max-height: 90vh;
        border-radius: 16px;
    }
    .modal-header h3 {
        font-size: 18px;
    }
    
    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
    }
    .form-actions {
        flex-direction: column;
    }
    .form-actions button {
        width: 100%;
    }
    
    /* Buttons */
    .btn-primary, .btn-secondary, .btn-danger, .btn-add {
        width: 100%;
        justify-content: center;
        padding: 14px;
    }
    
    /* Login box */
    .login-box {
        margin: 15px;
        padding: 30px 20px;
    }
    .login-logo {
        height: 50px;
    }
    .login-box h1 {
        font-size: 20px;
    }
    
    /* Impostazioni */
    .impostazioni-grid {
        grid-template-columns: 1fr;
    }
    
    /* Log items */
    .log-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .log-meta {
        text-align: left;
    }
}

/* Tablet adjustments */
@media (max-width: 1024px) and (min-width: 769px) {
    .header-center {
        max-width: 300px;
        margin: 0 15px;
    }
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .impostazioni-grid {
        grid-template-columns: 1fr;
    }
}