:root {
    /* Colori Principali - Tema Logistica/Dark */
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-primary: #3b82f6; /* Blu strada */
    --accent-primary-hover: #2563eb;
    --accent-loaded: #22c55e; /* Verde per carico */
    --accent-empty: #f59e0b; /* Arancione per vuoto */
    --accent-danger: #ef4444; /* Rosso per errori/rimuovi */
    --border-color: #475569;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden; /* Evita lo scroll della pagina intera */
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: 400px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 10; /* Sopra la mappa */
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--accent-primary);
    margin-bottom: 8px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

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

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-md);
}

.card h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-main);
}

/* Form Inputs */
.input-group-row {
    display: flex;
    gap: 12px;
}

.input-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

label {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    transition: all 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

/* Buttons */
.btn-primary {
    background-color: var(--accent-primary);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s, transform 0.1s;
}

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

.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background-color: var(--bg-main);
    color: var(--text-main);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon:hover {
    background-color: var(--bg-main);
    color: var(--text-main);
}

.w-100 { width: 100%; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }

/* Stops List */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h2 { margin-bottom: 0; }

.stops-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stop-item {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    position: relative;
}

.stop-item:first-child .stop-type option[value="empty"],
.stop-item:first-child .stop-type option[value="loaded"] {
    display: none;
}

.stop-item:not(:first-child) .stop-type option[value="start"] {
    display: none;
}

.stop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.stop-number {
    background-color: var(--bg-card);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
}

.remove-stop-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.remove-stop-btn:hover { color: var(--accent-danger); }

.stop-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stop-status {
    font-size: 0.75rem;
    color: var(--accent-danger);
    min-height: 14px;
}

.stop-status.success { color: var(--accent-loaded); }

/* Autocomplete */
.autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-top: 4px;
    padding: 0;
    list-style: none;
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.autocomplete-suggestions li {
    padding: 10px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
}

.autocomplete-suggestions li:last-child {
    border-bottom: none;
}

.autocomplete-suggestions li:hover {
    background-color: var(--bg-main);
}

.suggestion-main { font-weight: 600; }
.suggestion-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* Risultati */
.hidden { display: none !important; }

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-box {
    background-color: var(--bg-main);
    padding: 16px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-left: 4px solid transparent;
}

.stat-box.total { grid-column: span 2; border-left-color: var(--accent-primary); }
.stat-box.loaded { border-left-color: var(--accent-loaded); }
.stat-box.empty { border-left-color: var(--accent-empty); }

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

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

.stat-sub {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.grand-total {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(37, 99, 235, 0.2));
    border: 1px solid rgba(59, 130, 246, 0.3);
    padding: 16px;
    border-radius: var(--radius-md);
    text-align: center;
}

.grand-total span {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.grand-total h3 {
    font-size: 2rem;
    color: var(--accent-primary);
    margin-top: 4px;
}

.financial-summary {
    background-color: var(--bg-main);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.financial-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.financial-row span:first-child {
    color: var(--text-muted);
}

.val-tariffa { color: var(--accent-loaded); font-weight: 600; }
.val-costi { color: var(--accent-danger); font-weight: 600; }

.profit-positive h3 { color: var(--accent-loaded); }
.profit-negative h3 { color: var(--accent-danger); }

.legs-list {
    background-color: var(--bg-main);
    border-radius: var(--radius-md);
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.leg-item {
    font-size: 0.85rem;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
}
.leg-item:last-child { border-bottom: none; }
.leg-type-loaded { color: var(--accent-loaded); }
.leg-type-empty { color: var(--accent-empty); }


/* Area Mappa */
.map-container {
    flex: 1;
    position: relative;
    background-color: #1e293b;
}

#map {
    width: 100%;
    height: 100%;
}

.map-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.1);
    border-left-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Modifiche ai controlli Leaflet per Dark Mode */
.leaflet-container {
    background-color: #242424 !important;
}
.leaflet-bar a {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}
.leaflet-bar a:hover {
    background-color: var(--bg-main) !important;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background-color: var(--bg-sidebar);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-lg {
    max-width: 700px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.history-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.folder-card {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px solid var(--border-color);
}

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

.folder-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.folder-totals {
    display: flex;
    gap: 16px;
    font-size: 0.85rem;
}

.history-item {
    background-color: var(--bg-main);
    padding: 12px;
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.history-item:last-child { margin-bottom: 0; }

.history-item-info h4 { font-size: 0.9rem; margin-bottom: 4px; }
.history-item-info p { font-size: 0.8rem; color: var(--text-muted); }

.history-item-stats {
    text-align: right;
}
.history-item-stats h4 { font-size: 1rem; }
.history-item-stats p { font-size: 0.75rem; color: var(--text-muted); }

.delete-folder-btn {
    background: none; border: none; color: var(--accent-danger); cursor: pointer; padding: 4px; border-radius: 4px;
}
.delete-folder-btn:hover { background-color: rgba(239, 68, 68, 0.1); }

/* Responsive */
@media (max-width: 768px) {
    body {
        overflow: auto; /* Permette lo scroll naturale della pagina su mobile */
    }
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    .map-container {
        height: 40vh; /* Mappa alta 40% dello schermo */
        min-height: 300px;
        order: 1;
        position: relative;
        z-index: 1;
    }
    .sidebar {
        width: 100%;
        height: auto; /* La sidebar si espande per il suo contenuto */
        order: 2;
        border-right: none;
        box-shadow: none;
        overflow: visible; /* Lascia gestire lo scroll al body */
    }
    .sidebar-content {
        overflow-y: visible;
    }
}
