/* Reset e variabili globali */
:root {
    --primary-color: #4CAF50;
    --primary-dark: #388E3C;
    --secondary-color: #2196F3;
    --danger-color: #f44336;
    --warning-color: #FF9800;
    --background: #f5f5f5;
    --card-background: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-hover: 0 4px 16px rgba(0,0,0,0.15);
    --border-radius: 12px;
    --spacing: 16px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px var(--spacing);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.burger-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
    font-size: 20px;
}

.burger-btn:hover {
    background: rgba(255,255,255,0.3);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.header-title i {
    font-size: 28px;
}

.header-title h1 {
    font-size: 20px;
    font-weight: 600;
}

.by-fapel {
    font-size: 14px;
    font-weight: 400;
    opacity: 0.9;
}

/* Menu laterale */
.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--card-background);
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    z-index: 1000;
    transition: left 0.3s ease;
}

.side-menu.open {
    left: 0;
}

.menu-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.menu-header h2 {
    font-size: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.menu-close-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.menu-close-btn:hover {
    background: rgba(255,255,255,0.3);
}

.menu-nav {
    padding: 20px 0;
}

.menu-nav ul {
    list-style: none;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    width: 100%;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s ease;
    text-decoration: none;
}

.menu-item:hover {
    background: rgba(76, 175, 80, 0.1);
}

.menu-item i {
    font-size: 20px;
    color: var(--primary-color);
    width: 24px;
}

/* Menu overlay */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.menu-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--card-background);
    border-radius: var(--border-radius);
    max-width: 450px;
    width: 100%;
    box-shadow: var(--shadow-hover);
    animation: slideInModal 0.3s ease;
}

@keyframes slideInModal {
    from {
        transform: translateY(-30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-close-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.modal-close-btn:hover {
    background: rgba(255,255,255,0.3);
}

.modal-body {
    padding: 24px;
    max-height: 70vh;
    overflow-y: auto;
}

.info-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.info-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.description-section {
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.1) 0%, rgba(56, 142, 60, 0.05) 100%);
    padding: 16px;
    border-radius: 8px;
    border: none;
    margin-bottom: 24px;
}

.info-description {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    margin: 8px 0 0 0;
}

.features-section {
    background: #f9f9f9;
    padding: 16px;
    border-radius: 8px;
    border: none;
    margin-bottom: 24px;
}

.features-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0 0;
}

.features-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 10px 0;
    font-size: 14px;
    color: var(--text-primary);
}

.features-list li i {
    color: var(--primary-color);
    margin-top: 2px;
    font-size: 16px;
    min-width: 18px;
}

.features-list li strong {
    font-weight: 600;
}

.features-list li.sub-feature {
    margin-left: 28px;
    color: var(--text-secondary);
    font-size: 13px;
}

.features-list li.sub-feature::before {
    content: none;
}

.info-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-label i {
    color: var(--primary-color);
}

.info-value {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0;
}

.info-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--primary-color);
    text-decoration: none;
    margin-top: 8px;
    font-size: 14px;
    transition: opacity 0.3s ease;
}

.info-link:hover {
    opacity: 0.8;
}

/* Main content */
.app-main {
    max-width: 600px;
    margin: 0 auto;
    padding: var(--spacing);
    padding-bottom: 80px;
}

/* Status section */
.status-section {
    margin-bottom: 24px;
}

.status-card {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 32px 24px;
    text-align: center;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
}

.status-card.saved {
    border-left: 5px solid var(--primary-color);
}

.status-icon {
    font-size: 48px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.status-card.saved .status-icon {
    color: var(--primary-color);
}

.status-card h2 {
    font-size: 22px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.status-card p {
    color: var(--text-secondary);
    font-size: 16px;
}

.parking-details {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
    text-align: left;
}

.parking-details p {
    margin: 8px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.parking-details i {
    color: var(--primary-color);
    width: 20px;
}

/* Action buttons */
.action-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.btn {
    background: var(--card-background);
    border: none;
    border-radius: var(--border-radius);
    padding: 16px 24px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    color: white;
}

.btn:active {
    transform: scale(0.98);
}

.btn i {
    font-size: 20px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}

.btn-primary:hover {
    box-shadow: var(--shadow-hover);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #1976D2 100%);
}

.btn-navigate {
    background: linear-gradient(135deg, var(--warning-color) 0%, #F57C00 100%);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color) 0%, #D32F2F 100%);
}

/* Map section */
.map-section {
    background: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: slideIn 0.3s ease;
    margin-bottom: 24px;
}

.map-header {
    background: var(--primary-color);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.map-header h3 {
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.btn-close:hover {
    background: rgba(255,255,255,0.3);
}

.map-container {
    width: 100%;
    height: 400px;
}

.map-info {
    padding: 16px;
    background: #f9f9f9;
    border-top: 1px solid #e0e0e0;
}

.map-info p {
    margin: 8px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.map-info i {
    color: var(--primary-color);
}

/* History section */
.history-section {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.history-section h3 {
    font-size: 18px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.history-list {
    font-size: 14px;
    color: var(--text-secondary);
}

.history-item {
    padding: 12px;
    background: #f9f9f9;
    border-radius: 8px;
    margin: 8px 0;
    transition: background 0.2s ease;
}

.history-item:hover {
    background: #f0f0f0;
}

.history-date {
    font-size: 14px;
    color: var(--text-secondary);
}

.history-distance {
    font-weight: 600;
    color: var(--primary-color);
}

/* Footer */
.app-footer {
    background: var(--card-background);
    padding: 16px;
    text-align: center;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
}

.app-footer p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.install-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.3s ease;
}

.install-btn:hover {
    background: var(--primary-dark);
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0,0,0,0.85);
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: var(--shadow-hover);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--primary-color);
}

.toast.error {
    background: var(--danger-color);
}

/* Loading spinner */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

.loading-spinner p {
    color: white;
    margin-top: 16px;
    font-size: 16px;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Leaflet custom styles */
.leaflet-container {
    font-family: inherit;
}

.custom-marker-icon {
    background: var(--primary-color);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: var(--shadow);
}

/* Responsive design */
@media (max-width: 480px) {
    :root {
        --spacing: 12px;
    }
    
    .header-title h1 {
        font-size: 18px;
    }
    
    .by-fapel {
        font-size: 12px;
    }
    
    .status-card {
        padding: 24px 16px;
    }
    
    .status-icon {
        font-size: 40px;
    }
    
    .status-card h2 {
        font-size: 20px;
    }
    
    .btn {
        padding: 14px 20px;
        font-size: 15px;
    }
    
    .map-container {
        height: 300px;
    }
    
    .modal {
        padding: 12px;
    }
    
    .modal-body {
        padding: 16px;
        max-height: 65vh;
    }
    
    .features-list li {
        font-size: 13px;
    }
    
    .info-description {
        font-size: 14px;
    }
}

/* Landscape mode */
@media (orientation: landscape) and (max-height: 500px) {
    .app-header {
        padding: 12px var(--spacing);
    }
    
    .header-content h1 {
        font-size: 18px;
    }
    
    .header-content i {
        font-size: 22px;
    }
    
    .status-card {
        padding: 16px;
    }
    
    .map-container {
        height: 250px;
    }
}

/* Dark mode support (opzionale) */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #121212;
        --card-background: #1e1e1e;
        --text-primary: #ffffff;
        --text-secondary: #b0b0b0;
        --shadow: 0 2px 8px rgba(0,0,0,0.3);
    }
    
    .map-info {
        background: #2a2a2a;
        border-top-color: #333;
    }
    
    .parking-details {
        border-top-color: #333;
    }
    
    .info-section {
        border-bottom-color: #333;
    }
    
    .description-section {
        background: linear-gradient(135deg, rgba(76, 175, 80, 0.2) 0%, rgba(56, 142, 60, 0.1) 100%);
    }
    
    .features-section {
        background: #2a2a2a;
    }
    
    .menu-item:hover {
        background: rgba(76, 175, 80, 0.2);
    }
}

/* Nuove Pagine (Impostazioni, Statistiche, Distanze) */
.page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background);
    z-index: 150;
    overflow-y: auto;
    animation: slideInPage 0.3s ease;
}

@keyframes slideInPage {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

.page-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px var(--spacing);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.back-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
    font-size: 18px;
}

.back-btn:hover {
    background: rgba(255,255,255,0.3);
}

.page-header h2 {
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-content {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--spacing);
    padding-bottom: 100px;
}

/* Settings Page */
.settings-card {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.settings-card h3 {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.text-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

.text-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-small {
    padding: 12px 20px !important;
    font-size: 14px !important;
}

.saved-address {
    margin-top: 12px;
    padding: 12px;
    background: #f0f0f0;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    min-height: 20px;
}

.saved-address:empty::before {
    content: 'Nessun indirizzo salvato';
    font-style: italic;
}

.info-text {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
}

/* Statistics Page */
.stats-card {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.stats-card h3 {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.stats-map-container {
    width: 100%;
    height: 400px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
}

.legend {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 12px;
    background: #f9f9f9;
    border-radius: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.stats-summary {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    background: #f9f9f9;
    border-radius: 8px;
    align-items: center;
}

.summary-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.summary-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--primary-color);
}

/* Distances Page */
.chart-container {
    position: relative;
    height: 300px;
    margin: 16px 0;
}

.distance-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    background: #f9f9f9;
    border-radius: 8px;
}

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

.stat-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.table-container {
    overflow-x: auto;
    margin-top: 16px;
}

.parking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.parking-table thead {
    background: var(--primary-color);
    color: white;
}

.parking-table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
}

.parking-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
}

.parking-table tbody tr:hover {
    background: #f9f9f9;
}

.parking-table td {
    padding: 12px;
}

.empty-message {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-style: italic;
}

/* Responsive per nuove pagine */
@media (max-width: 480px) {
    .page-header h2 {
        font-size: 18px;
    }
    
    .settings-card, .stats-card {
        padding: 16px;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    .stats-map-container {
        height: 300px;
    }
    
    .chart-container {
        height: 250px;
    }
    
    .parking-table {
        font-size: 12px;
    }
    
    .parking-table th,
    .parking-table td {
        padding: 8px;
    }
}

/* Dark mode per nuove pagine */
@media (prefers-color-scheme: dark) {
    .settings-card, .stats-card {
        background: var(--card-background);
    }
    
    .text-input {
        background: #2a2a2a;
        border-color: #444;
        color: white;
    }
    
    .saved-address {
        background: #2a2a2a;
    }
    
    .legend {
        background: #2a2a2a;
    }
    
    .summary-item,
    .stat-item {
        background: #2a2a2a;
    }
    
    .parking-table tbody tr:hover {
        background: #2a2a2a;
    }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
    .app-header {
        padding-left: max(var(--spacing), env(safe-area-inset-left));
        padding-right: max(var(--spacing), env(safe-area-inset-right));
        padding-top: max(20px, env(safe-area-inset-top));
    }
    
    .app-main {
        padding-left: max(var(--spacing), env(safe-area-inset-left));
        padding-right: max(var(--spacing), env(safe-area-inset-right));
        padding-bottom: max(80px, env(safe-area-inset-bottom));
    }
    
    .app-footer {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
