/**
 * STILE PRINCIPALE - Gestione Vertenze Pro v3.0
 * Aggiornato: miglioramenti sidebar, dark mode e toggle menu
 */

/* ==================== RESET & VARIABLES ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2c3e50;
    --primary-light: #34495e;
    --secondary: #3498db;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --info: #17a2b8;
    --light: #ecf0f1;
    --dark: #2c3e50;
    --white: #ffffff;
    --gray: #95a5a6;
    --gray-light: #bdc3c7;
    --border: #dce1e3;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 0px;
    
    /* TEMA LIGHT - Crema caldo */
    --bg-body: #faf8f5;
    --bg-card: #ffffff;
    --bg-sidebar: #3d5a73;  /* Più chiaro del precedente #2c3e50 */
    --sidebar-header-bg: rgba(0,0,0,0.08);
    --sidebar-footer-bg: rgba(0,0,0,0.08);
    --sidebar-hover: rgba(255,255,255,0.12);
    --sidebar-active: rgba(255,255,255,0.18);
    --sidebar-border: rgba(255,255,255,0.12);
    --text-color: #2c3e50;
    --text-muted: #6c757d;
    --border-color: #e8e4df;
    --shadow-color: rgba(0,0,0,0.06);
    --input-bg: #ffffff;
    --hover-bg: #f5f2ed;
}

[data-theme="dark"] {
    /* TEMA DARK - Grigio più bilanciato, contrasti morbidi */
    --bg-body: #1e1e1e;
    --bg-card: #2a2a2a;
    --bg-sidebar: #252525;
    --sidebar-header-bg: rgba(255,255,255,0.03);
    --sidebar-footer-bg: rgba(255,255,255,0.03);
    --sidebar-hover: rgba(255,255,255,0.08);
    --sidebar-active: rgba(255,255,255,0.12);
    --sidebar-border: rgba(255,255,255,0.08);
    --text-color: #d4d4d4;
    --text-muted: #888888;
    --border-color: #3a3a3a;
    --shadow-color: rgba(0,0,0,0.3);
    --input-bg: #333333;
    --hover-bg: #353535;
    --primary: #5a9fd4;
    --primary-light: #4a8fc4;
    --secondary: #4eb3a6;
    --dark: #d4d4d4;
    --gray: #888888;
}

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

/* ==================== LAYOUT ==================== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--white);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease, background 0.3s;
}

/* Sidebar collapsed (desktop) */
.sidebar.collapsed {
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 20px;
    background: var(--sidebar-header-bg);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-header .logo {
    font-size: 2rem;
}

.sidebar-header .brand-name {
    display: block;
    font-weight: 600;
    font-size: 1rem;
}

.sidebar-header .brand-version {
    display: block;
    font-size: 0.75rem;
    opacity: 0.7;
}

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

.nav-section {
    padding: 15px 20px 8px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.5;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--white);
}

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--white);
    border-left-color: var(--secondary);
}

.nav-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--sidebar-footer-bg);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-icon {
    font-size: 1.5rem;
}

.user-name {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
}

.user-role {
    display: block;
    font-size: 0.75rem;
    opacity: 0.7;
}

.logout-btn {
    font-size: 1.2rem;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.logout-btn:hover {
    opacity: 1;
}

/* Toggle Tema */
.theme-toggle {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    margin-right: 10px;
}
.theme-toggle:hover {
    background: rgba(255,255,255,0.25);
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    min-height: 100vh;
    background: var(--bg-body);
    transition: background 0.3s;
}

.page-header {
    margin-bottom: 30px;
}

.page-title {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 5px;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ==================== CARDS ==================== */
.card {
    background: var(--bg-card);
    border-radius: 10px;
    box-shadow: 0 2px 10px var(--shadow-color);
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    transition: background 0.3s, border-color 0.3s;
}

.card-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

.card-body {
    padding: 20px;
}

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

.stat-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px var(--shadow-color);
    border: 1px solid var(--border-color);
    transition: background 0.3s, border-color 0.3s;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--gray);
    margin-bottom: 5px;
}

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

.stat-change {
    font-size: 0.8rem;
    color: var(--gray);
    margin-top: 5px;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.blue { background: #e3f2fd; }
.stat-icon.green { background: #e8f5e9; }
.stat-icon.orange { background: #fff3e0; }
.stat-icon.purple { background: #f3e5f5; }

/* Dark mode: sfondo icone leggermente più scuro */
[data-theme="dark"] .stat-icon.blue { background: rgba(52, 152, 219, 0.2); }
[data-theme="dark"] .stat-icon.green { background: rgba(39, 174, 96, 0.2); }
[data-theme="dark"] .stat-icon.orange { background: rgba(243, 156, 18, 0.2); }
[data-theme="dark"] .stat-icon.purple { background: rgba(155, 89, 182, 0.2); }
.stat-icon.red { background: #ffebee; }

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: #2980b9;
}

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

.btn-success:hover {
    background: #219a52;
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--dark);
}

.btn-outline:hover {
    background: var(--light);
}

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

.btn-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

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

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--dark);
}

.form-label .required {
    color: var(--danger);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.3s;
    background: var(--input-bg);
    color: var(--text-color);
}

.form-control:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--gray);
    margin-top: 5px;
}

/* ==================== TABLES ==================== */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--hover-bg);
}

tr:hover {
    background: var(--hover-bg);
}

.table-actions {
    display: flex;
    gap: 8px;
}

.table-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.table-empty .icon {
    font-size: 3rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

/* ==================== BADGES ==================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-richiesta { background: #e3f2fd; color: #1565c0; }
.badge-attesa_doc { background: #fff3e0; color: #e65100; }
.badge-prev_inviato { background: #f3e5f5; color: #7b1fa2; }
.badge-prev_accettato { background: #e8f5e9; color: #2e7d32; }
.badge-in_lavorazione { background: #fff8e1; color: #f57f17; }
.badge-pronto_consegna { background: #e0f2f1; color: #00695c; }
.badge-consegnato { background: #e8f5e9; color: #1b5e20; }
.badge-completato { background: #f5f5f5; color: #424242; }
.badge-archiviato { background: #eceff1; color: #546e7a; }

.badge-normale { background: #e8f5e9; color: #2e7d32; }
.badge-urgente { background: #fff3e0; color: #e65100; }
.badge-urgentissimo { background: #ffebee; color: #c62828; }

.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-warning { background: #fff3e0; color: #e65100; }
.badge-danger { background: #ffebee; color: #c62828; }
.badge-info { background: #e3f2fd; color: #1565c0; }
.badge-secondary { background: #eceff1; color: #546e7a; }

/* Dark mode badges - sfondi semi-trasparenti per meno contrasto */
[data-theme="dark"] .badge-richiesta { background: rgba(21, 101, 192, 0.25); color: #64b5f6; }
[data-theme="dark"] .badge-attesa_doc { background: rgba(230, 81, 0, 0.25); color: #ffb74d; }
[data-theme="dark"] .badge-prev_inviato { background: rgba(123, 31, 162, 0.25); color: #ce93d8; }
[data-theme="dark"] .badge-prev_accettato { background: rgba(46, 125, 50, 0.25); color: #81c784; }
[data-theme="dark"] .badge-in_lavorazione { background: rgba(245, 127, 23, 0.25); color: #ffd54f; }
[data-theme="dark"] .badge-pronto_consegna { background: rgba(0, 105, 92, 0.25); color: #4db6ac; }
[data-theme="dark"] .badge-consegnato { background: rgba(27, 94, 32, 0.25); color: #81c784; }
[data-theme="dark"] .badge-completato { background: rgba(66, 66, 66, 0.25); color: #bdbdbd; }
[data-theme="dark"] .badge-archiviato { background: rgba(84, 110, 122, 0.25); color: #90a4ae; }
[data-theme="dark"] .badge-normale { background: rgba(46, 125, 50, 0.25); color: #81c784; }
[data-theme="dark"] .badge-urgente { background: rgba(230, 81, 0, 0.25); color: #ffb74d; }
[data-theme="dark"] .badge-urgentissimo { background: rgba(198, 40, 40, 0.25); color: #ef9a9a; }
[data-theme="dark"] .badge-success { background: rgba(46, 125, 50, 0.25); color: #81c784; }
[data-theme="dark"] .badge-warning { background: rgba(230, 81, 0, 0.25); color: #ffb74d; }
[data-theme="dark"] .badge-danger { background: rgba(198, 40, 40, 0.25); color: #ef9a9a; }
[data-theme="dark"] .badge-info { background: rgba(21, 101, 192, 0.25); color: #64b5f6; }
[data-theme="dark"] .badge-secondary { background: rgba(84, 110, 122, 0.25); color: #90a4ae; }

/* ==================== ALERTS ==================== */
.alert {
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Dark mode alerts - colori più morbidi */
[data-theme="dark"] .alert-success {
    background: rgba(39, 174, 96, 0.15);
    color: #81c784;
    border-color: rgba(39, 174, 96, 0.3);
}
[data-theme="dark"] .alert-danger {
    background: rgba(231, 76, 60, 0.15);
    color: #ef9a9a;
    border-color: rgba(231, 76, 60, 0.3);
}
[data-theme="dark"] .alert-warning {
    background: rgba(243, 156, 18, 0.15);
    color: #ffd54f;
    border-color: rgba(243, 156, 18, 0.3);
}
[data-theme="dark"] .alert-info {
    background: rgba(52, 152, 219, 0.15);
    color: #64b5f6;
    border-color: rgba(52, 152, 219, 0.3);
}

.alert-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.5;
    line-height: 1;
}

.alert-close:hover {
    opacity: 1;
}

/* ==================== QUICK ACTIONS ==================== */
.quick-actions {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px var(--shadow-color);
    border: 1px solid var(--border-color);
    transition: background 0.3s, border-color 0.3s;
}

.quick-actions h3 {
    margin-bottom: 15px;
    font-size: 1rem;
    color: var(--text-color);
}

.actions-grid {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: var(--white);
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

.action-btn.secondary {
    background: linear-gradient(135deg, #27ae60 0%, #219a52 100%);
}

.action-btn.tertiary {
    background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
}

.action-icon {
    font-size: 1.2rem;
}

/* ==================== RECENT SECTION ==================== */
.recent-section {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px var(--shadow-color);
    border: 1px solid var(--border-color);
    transition: background 0.3s, border-color 0.3s;
}

.recent-section h3 {
    margin-bottom: 15px;
    font-size: 1rem;
    color: var(--text-color);
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.activity-item {
    display: flex;
    gap: 15px;
    padding: 15px;
    background: var(--hover-bg);
    border-radius: 8px;
    transition: background 0.3s;
}

.activity-icon {
    font-size: 1.5rem;
}

.activity-content {
    flex: 1;
}

.activity-content h4 {
    font-size: 0.9rem;
    margin-bottom: 5px;
    color: var(--text-color);
}

.activity-content p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.activity-time {
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ==================== LOGIN PAGE ==================== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}

.login-box {
    background: var(--white);
    border-radius: 15px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

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

.login-logo .icon {
    font-size: 4rem;
    margin-bottom: 10px;
}

.login-logo h1 {
    font-size: 1.5rem;
    color: var(--dark);
}

.login-logo p {
    color: var(--gray);
    font-size: 0.9rem;
}

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

/* Toggle menu button (hamburger) - sempre visibile */
.menu-toggle-btn {
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1001;
    width: 45px;
    height: 45px;
    background: var(--bg-sidebar);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    transition: background 0.2s, left 0.3s;
}

.menu-toggle-btn span {
    display: block;
    width: 22px;
    height: 3px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s ease;
    transform-origin: center;
}

.menu-toggle-btn:hover {
    background: var(--primary-light);
}

/* Animazione hamburger -> X quando sidebar è aperta */
.menu-toggle-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}
.menu-toggle-btn.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}
.menu-toggle-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Desktop: pulsante si sposta, contenuto sempre con spazio sopra */
@media (min-width: 769px) {
    /* Pulsante normalmente a destra della sidebar */
    .menu-toggle-btn {
        left: calc(var(--sidebar-width) + 15px);
        top: 15px;
    }
    
    /* Quando sidebar chiusa, pulsante va a sinistra */
    .menu-toggle-btn.sidebar-hidden {
        left: 15px;
    }
    
    .main-content {
        padding-top: 80px; /* Spazio per il pulsante - SEMPRE */
        transition: margin-left 0.3s ease;
    }
    
    /* Quando sidebar è nascosta */
    .main-content.expanded {
        margin-left: 0;
    }
}

/* Overlay behind sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* Mobile menu button - DEPRECATED, usa .menu-toggle-btn */
.mobile-menu-btn {
    display: none;
}

@media (max-width: 768px) {
    .menu-toggle-btn {
        left: 15px !important;
    }

    .sidebar {
        transform: translateX(-100%);
        z-index: 1000;
    }

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

    .main-content {
        margin-left: 0;
        padding: 15px;
        padding-top: 70px; /* Spazio per hamburger sopra */
    }

    .form-row {
        grid-template-columns: 1fr;
    }

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

    .actions-grid {
        flex-direction: column;
    }

    .action-btn {
        justify-content: center;
    }

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

    .table {
        min-width: 600px;
    }

    /* Card compatte */
    .card {
        margin-bottom: 15px;
    }

    .card-body {
        padding: 15px;
    }

    /* Page title più piccolo */
    .page-title {
        font-size: 1.3rem;
    }

    /* Stats grid 2 colonne */
    .stats-grid {
        gap: 10px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-value {
        font-size: 1.5rem;
    }
}

/* ==================== UTILITIES ==================== */
.text-muted { color: var(--gray); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-4 { margin-top: 1rem; }
.hidden { display: none !important; }
