/* ============================================
   MOBILE FIX - Complete Mobile Optimization
   ============================================ */

/* Fix Sidebar Height - Deve arrivare fino in fondo */
.sidebar {
    min-height: 100vh;
    height: 100%;
    overflow-y: auto;
}

/* Tablet Responsive (1024px and below) */
@media (max-width: 1024px) {
    /* Mobile Menu Toggle */
    .mobile-menu-toggle {
        display: flex !important;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 1001;
        width: 48px;
        height: 48px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: var(--transition);
    }

    /* Sidebar Mobile */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
        min-height: 100vh;
        height: 100%;
        overflow-y: auto;
    }

    .sidebar.sidebar-open {
        left: 0;
    }

    /* Main Content */
    .main-content {
        margin-left: 0 !important;
        padding: 80px 24px 24px !important;
        width: 100% !important;
    }

    /* Stats Grid - 2 colonne su tablet */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px;
    }

    /* Page Header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .page-header > div:last-child {
        width: 100%;
    }

    /* Bottoni Full Width */
    .page-header .btn-primary,
    .page-header .btn-secondary {
        width: 100%;
        justify-content: center;
    }
}

/* Mobile Responsive (768px and below) */
@media (max-width: 768px) {
    /* Main Content - Più padding per mobile */
    .main-content {
        padding: 70px 16px 80px 16px !important;
    }

    /* Dashboard Grid - 1 colonna su mobile */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    /* Month Selector Card - Responsive */
    .month-selector-card {
        padding: 20px !important;
    }

    .month-selector-card h2 {
        font-size: 24px !important;
    }

    .period-selectors {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .period-selectors select {
        font-size: 16px !important;
        padding: 12px !important;
    }

    /* Summary Section - Responsive */
    .summary-section {
        padding: 12px !important;
    }

    .summary-section h4 {
        font-size: 12px !important;
    }

    .summary-table th,
    .summary-table td {
        padding: 8px 6px !important;
        font-size: 13px !important;
    }

    .summary-table th {
        font-size: 11px !important;
    }

    /* Stats Grid - 1 colonna su mobile */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    /* Stat Card - Più compatto */
    .stat-card {
        padding: 16px;
    }

    .stat-card h3 {
        font-size: 14px;
    }

    .stat-card .value {
        font-size: 24px;
    }

    /* Page Header */
    .page-header h1 {
        font-size: 24px !important;
    }

    /* Dashboard Charts - Entrate e Uscite uno sotto l'altro */
    .charts-row {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .tables-row {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    /* Chart Wrappers - Reduce height on mobile */
    .pie-chart-wrapper {
        height: 240px !important;
    }

    /* Charts Section - Uno sotto l'altro */
    .charts-grid,
    .category-charts,
    [class*="grid"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    /* Chart Cards */
    .chart-card,
    .card {
        margin-bottom: 16px;
    }

    .chart-card h3,
    .card h3 {
        font-size: 16px !important;
    }

    /* Charts - Responsive Height */
    canvas {
        max-height: 240px !important;
        width: 100% !important;
    }

    /* Chart Container */
    .chart-container {
        position: relative;
        height: 240px !important;
        width: 100%;
    }

    /* Category Tables - Fix spacing */
    .category-table {
        font-size: 13px !important;
    }

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

    .category-table .category-name {
        max-width: 120px !important;
    }

    /* Show budget/amount columns properly */
    .category-table .amount-cell,
    .category-table .budget-cell {
        white-space: nowrap;
        font-size: 13px !important;
    }

    /* Form Rows - 1 colonna */
    .form-row,
    .form-row.two-col,
    .form-row.three-col {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    /* Buttons - Full Width su mobile */
    .btn-primary,
    .btn-secondary,
    .btn-danger {
        width: 100%;
        justify-content: center;
        padding: 12px 20px;
        font-size: 15px;
    }

    /* Floating Action Button per Aggiungi Transazione */
    .btn-primary[onclick*="openModal"],
    .btn-primary[onclick*="addTransaction"] {
        position: fixed !important;
        bottom: 20px;
        right: 20px;
        width: 60px !important;
        height: 60px !important;
        border-radius: 50% !important;
        padding: 0 !important;
        box-shadow: 0 4px 12px rgba(0, 212, 255, 0.3);
        z-index: 100;
    }

    .btn-primary[onclick*="openModal"] span,
    .btn-primary[onclick*="addTransaction"] span {
        display: none;
    }

    .btn-primary[onclick*="openModal"] svg,
    .btn-primary[onclick*="addTransaction"] svg {
        margin: 0 !important;
        width: 24px;
        height: 24px;
    }

    /* Modals - Full Screen su mobile */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        max-height: 100vh;
        overflow-y: auto;
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: var(--bg-secondary);
        z-index: 10;
        border-bottom: 1px solid var(--border-color);
    }

    .modal-body {
        padding: 20px;
        max-height: calc(100vh - 160px);
        overflow-y: auto;
    }

    .modal-footer {
        position: sticky;
        bottom: 0;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        padding: 16px;
    }

    /* Tables - Scroll Orizzontale */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }

    table {
        min-width: 600px;
        font-size: 14px;
    }

    table th,
    table td {
        padding: 10px 8px;
    }

    /* Tabs - Scroll Orizzontale */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        margin: 0 -16px;
        padding: 0 16px;
    }

    .tab {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Cards */
    .card {
        margin-bottom: 16px;
    }

    /* Filters - Stack verticalmente */
    .filters {
        flex-direction: column !important;
        gap: 12px;
    }

    .filters > * {
        width: 100% !important;
    }

    /* Transaction Items */
    .transaction-item {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }

    .transaction-item > div {
        width: 100%;
    }

    /* Budget Items */
    .budget-item {
        flex-direction: column;
        gap: 12px;
    }

    .budget-item .progress-bar {
        width: 100% !important;
    }

    /* Charts - Responsive */
    canvas {
        max-height: 250px !important;
    }
}

/* Small Mobile (480px and below) */
@media (max-width: 480px) {
    /* Mobile Menu Toggle - Più grande */
    .mobile-menu-toggle {
        width: 52px;
        height: 52px;
    }

    /* Main Content */
    .main-content {
        padding: 65px 12px 80px 12px !important;
    }

    /* Dashboard Grid */
    .dashboard-grid {
        gap: 12px !important;
    }

    /* Month Selector */
    .month-selector-card {
        padding: 16px !important;
    }

    .month-selector-card h2 {
        font-size: 20px !important;
    }

    .period-selectors select {
        padding: 10px !important;
        font-size: 15px !important;
    }

    /* Summary Section */
    .summary-section {
        padding: 10px !important;
    }

    .summary-section h4 {
        font-size: 11px !important;
        margin-bottom: 8px !important;
    }

    .summary-table th,
    .summary-table td {
        padding: 6px 4px !important;
        font-size: 12px !important;
    }

    .summary-table th {
        font-size: 10px !important;
    }

    /* Page Header */
    .page-header {
        padding: 16px 12px;
    }

    .page-header h1 {
        font-size: 20px !important;
    }

    .page-header .subtitle,
    .page-header p {
        font-size: 13px !important;
    }

    /* Stat Cards - Ancora più compatti */
    .stat-card {
        padding: 12px;
    }

    .stat-card h3 {
        font-size: 12px !important;
    }

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

    /* Charts */
    .chart-card h3,
    .card h3 {
        font-size: 14px !important;
    }

    canvas {
        max-height: 240px !important;
    }

    .chart-container {
        height: 240px !important;
    }

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

    /* Form Elements */
    input,
    select,
    textarea {
        font-size: 16px !important; /* Previene zoom su iOS */
        padding: 12px;
    }

    label {
        font-size: 14px !important;
    }

    /* Modal */
    .modal-body {
        padding: 16px;
    }

    .modal-header h2,
    .modal-header h3 {
        font-size: 18px !important;
    }

    /* Table */
    table {
        font-size: 12px;
    }

    table th,
    table td {
        padding: 6px 4px;
    }

    /* Floating Button - Più piccolo */
    .btn-primary[onclick*="openModal"],
    .btn-primary[onclick*="addTransaction"] {
        width: 56px !important;
        height: 56px !important;
        bottom: 16px;
        right: 16px;
    }

    /* Generic Text Scaling */
    h1 {
        font-size: 20px !important;
    }

    h2 {
        font-size: 18px !important;
    }

    h3 {
        font-size: 16px !important;
    }

    h4 {
        font-size: 14px !important;
    }

    p, span, div {
        font-size: 14px;
    }

    small, .small-text {
        font-size: 12px !important;
    }
}

/* Landscape Mobile Fix */
@media (max-width: 768px) and (orientation: landscape) {
    .main-content {
        padding: 65px 16px 20px !important;
    }

    .modal-content {
        height: auto !important;
        max-height: 90vh;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    /* Aumenta area touch per tutti i link */
    a, button, .btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Rimuovi hover effects su touch */
    *:hover {
        transition: none;
    }

    /* Migliora scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* iOS Safari Fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix per la barra degli indirizzi di Safari */
    .main-content {
        min-height: -webkit-fill-available;
    }

    .sidebar {
        height: -webkit-fill-available;
    }

    /* Previeni bounce scroll sul body */
    body {
        position: fixed;
        overflow: hidden;
        width: 100%;
    }

    .main-content {
        overflow-y: auto;
        height: 100vh;
        -webkit-overflow-scrolling: touch;
    }
}

/* Print Styles */
@media print {
    .sidebar,
    .mobile-menu-toggle,
    .sidebar-overlay,
    .btn,
    .modal {
        display: none !important;
    }

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

    body {
        background: white;
        color: black;
    }
}
