/* Mobile Responsive Styles for Modern Financial Dashboard */

/* PWA and Mobile Enhancement Styles */
.install-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    border-radius: 50px;
    padding: 12px 20px;
    box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.pull-refresh-indicator {
    font-size: 12px;
    font-weight: 500;
}

.offline-indicator {
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

/* Update banner styles */
.update-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: #2f80ed;
    color: #fff;
    font-size: 14px;
    z-index: 1100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
.update-banner .update-text {
    flex: 1;
}
.update-banner .update-action {
    background: #fff;
    color: #2f80ed;
    border: none;
    border-radius: 20px;
    padding: 8px 12px;
    font-weight: 600;
}

/* Enhanced Touch Targets */
.mobile-nav-item,
.stat-card,
.bill-item,
.task-item {
    min-height: 44px;
    touch-action: manipulation;
}

/* Mobile-first approach */
@media screen and (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        height: 100svh;
        height: 100dvh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .top-header {
        padding: 1rem;
    }

    .sidebar-toggle {
        display: flex;
    }

    .search-box {
        max-width: 200px;
    }

    .user-menu {
        margin-left: auto;
    }
}

@media screen and (max-width: 768px) {
    /* Header adjustments */
    .top-header {
        padding: 0.75rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .page-title {
        font-size: 1.25rem;
        order: 1;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .sidebar-toggle {
        order: 2;
    }

    .search-box {
        order: 3;
        flex: 1;
        min-width: 150px;
        max-width: none;
    }

    .user-menu {
        order: 4;
        margin-left: 0.5rem;
    }

    /* Sidebar adjustments */
    .sidebar {
        width: 100vw;
        left: -100vw;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-header {
        padding: 1rem;
    }

    .logo {
        width: 32px;
        height: 32px;
    }

    .app-name {
        font-size: 1.1rem;
    }

    .nav-item {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .nav-item i {
        width: 20px;
        font-size: 1rem;
    }

    /* Page content adjustments */
    .page-content {
        padding: 1rem;
    }

    /* Stats grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-content h3 {
        font-size: 1.25rem;
    }

    .stat-content p {
        font-size: 0.8rem;
    }

    /* Content grid */
    .content-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Tables - Enhanced mobile responsiveness */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.5rem; /* Extend to screen edges */
        border-radius: 8px;
    }

    table {
        width: 100%;
        min-width: 100%;
        font-size: 0.85rem;
        table-layout: fixed;
        border-collapse: collapse;
    }
    
    th, td {
        padding: 0.5rem 0.25rem;
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
        line-height: 1.4;
        vertical-align: middle;
    }
    
    /* Make bill names uppercase and larger on medium mobile screens */
    .data-table td:nth-child(2) {
        text-transform: uppercase;
        font-size: 0.9rem;
        font-weight: 600;
        letter-spacing: 0.3px;
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
        max-width: 0;
        overflow: hidden;
    }

    /* Optimized column widths for mobile */
    .data-table th:first-child,
    .data-table td:first-child {
        width: 30%; /* Actions column - increased */
        min-width: 90px;
    }
    
    .data-table th:nth-child(2),
    .data-table td:nth-child(2) {
        width: 35%; /* Bill name column - reduced */
        min-width: 100px;
        padding-right: 0.5rem; /* Add right padding for spacing */
    }
    
    .data-table th:nth-child(3),
    .data-table td:nth-child(3) {
        width: 25%; /* Due date column */
        min-width: 80px;
    }
    
    .data-table th:nth-child(4),
    .data-table td:nth-child(4) {
        width: 10%; /* Status column */
        min-width: 60px;
    }

    .action-buttons {
        display: flex;
        gap: 0.2rem;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
        max-width: 100%;
        overflow: visible;
    }

    .action-buttons .btn {
        padding: 0.2rem 0.3rem;
        font-size: 0.7rem;
        min-width: 24px;
    }
    
    .action-buttons .status-toggle {
        padding: 0.2rem 0.4rem;
        font-size: 0.65rem;
        min-width: 28px;
        max-width: 60px;
        height: 28px;
        border-radius: 3px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        touch-action: manipulation;
        margin-right: 0.1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-transform: uppercase;
    }
    
    /* Status-specific colors for mobile */
    .action-buttons .status-toggle[data-status="PENDING"] {
        background: #ff9500;
        color: white;
    }
    
    .action-buttons .status-toggle[data-status="COMPLETED"] {
        background: #28a745;
        color: white;
    }
    
    /* Strikethrough for completed tasks on mobile */
    tr:has(.status-toggle[data-status="COMPLETED"]) td:nth-child(2) {
        text-decoration: line-through;
        opacity: 0.7;
    }
    
    /* Hide button text on mobile, show only icons */
    .action-buttons .btn span {
        display: none;
    }
    
    .action-buttons .btn i {
        font-size: 0.75rem;
        margin: 0;
    }

    /* Cards - Enhanced mobile layout */
    .card,
    .content-card {
        margin-bottom: 1rem;
        margin-left: 0;
        margin-right: 0;
        border-radius: 8px;
        overflow: hidden;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    .card-content {
        padding: 1rem;
    }
    
    /* Ensure content cards don't overflow on mobile */
    .content-card {
        padding: 1rem 0.5rem;
        box-sizing: border-box;
    }
    
    .content-card h3 {
        margin-left: 0.5rem;
        margin-right: 0.5rem;
    }

    /* Buttons */
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .btn-group {
        flex-direction: column;
        gap: 0.5rem;
    }

    .btn-group .btn {
        width: 100%;
    }

    /* Modals */
    .modal-content {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
        overflow-y: auto;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* Forms */
    .form-group {
        margin-bottom: 1rem;
    }

    .form-row {
        flex-direction: column;
        gap: 1rem;
    }

    .form-control {
        font-size: 1rem; /* Prevent zoom on iOS */
    }

    /* Dashboard specific */
    .dashboard-overview {
        gap: 1rem;
    }

    .recent-activity {
        padding: 1rem;
    }



    /* Progress bars - Mobile responsive styles */
    .progress-bar,
    .progress-bar-small {
        height: 8px; /* Slightly larger for better touch visibility */
        min-height: 8px;
        border-radius: 4px;
        overflow: hidden;
        background: rgba(255, 255, 255, 0.1);
        margin: 0.25rem 0;
        width: 100%;
        max-width: 100%;
    }
    
    .progress-fill,
    .progress-fill-small {
        height: 100%;
        border-radius: 4px;
        transition: width 0.3s ease;
        min-width: 2px; /* Ensure visibility even at 0% */
    }
    
    .progress-text {
        font-size: 0.7rem;
        margin-top: 0.2rem;
        color: rgba(255, 255, 255, 0.8);
        text-align: right;
        display: block;
        width: 100%;
    }
    
    /* Arrangement progress cell mobile styles */
    .arrangement-progress-cell {
        min-width: 80px;
        width: 100%;
        padding: 0.25rem;
    }
    
    .arrangement-progress {
        margin: 0.5rem 0;
    }
    
    .arrangement-progress span {
        font-size: 0.65rem;
        display: block;
        margin-bottom: 0.25rem;
        color: rgba(255, 255, 255, 0.7);
    }
    
    /* Installment visual progress mobile styles */
    .installment-visual-progress {
        margin-top: 0.5rem;
        width: 100%;
    }
    
    .installment-dots {
        display: flex !important;
        gap: 0.2rem !important;
        flex-wrap: wrap !important;
        justify-content: flex-start;
        max-width: 100%;
    }
    
    .installment-dot {
        width: 8px !important;
        height: 8px !important;
        border-radius: 50%;
        flex-shrink: 0;
        margin: 0;
    }
    
    /* Due installments table mobile adjustments */
    .due-installments-table .progress-bar {
        margin: 0.2rem 0;
    }
    
    .due-installments-table .progress-text {
        font-size: 0.65rem;
        margin-top: 0.1rem;
    }

    /* Bill and task items */
    .bill-item,
    .task-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.75rem;
    }

    .bill-info,
    .task-info {
        width: 100%;
    }

    .bill-item .btn,
    .task-item .btn {
        align-self: flex-end;
        min-width: 80px;
    }
}

@media screen and (max-width: 480px) {
    /* Extra small screens */
    .top-header {
        padding: 0.5rem;
    }

    .page-title {
        font-size: 1.1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .page-content {
        padding: 0.75rem 0.5rem;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    /* Ensure bills page doesn't overflow */
    #bills-page {
        padding: 0;
        overflow-x: hidden;
    }
    
    #bills-page .page-header {
        padding: 1rem 0.5rem;
        margin-bottom: 1rem;
    }
    
    /* Responsive page actions */
    .page-actions {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    
    .page-actions .btn {
        flex: 1;
        min-width: 120px;
    }

    /* Compact table for very small screens */
    .table-container {
        font-size: 0.75rem;
        border-radius: 8px;
        overflow: hidden;
        overflow-x: auto;
        margin: 0 -0.75rem; /* Extend further to screen edges */
    }

    table {
        width: 100%;
        min-width: 100%;
        table-layout: fixed;
    }

    /* Optimized column widths for very small screens */
    .data-table th:first-child,
    .data-table td:first-child {
        width: 32%; /* Actions column - increased for buttons */
        min-width: 85px;
    }
    
    .data-table th:nth-child(2),
    .data-table td:nth-child(2) {
        width: 38%; /* Bill name column - balanced */
        min-width: 90px;
        padding-right: 0.5rem; /* Add spacing */
    }
    
    .data-table th:nth-child(3),
    .data-table td:nth-child(3) {
        width: 25%; /* Due date column */
        min-width: 70px;
    }
    
    .data-table th:nth-child(4),
    .data-table td:nth-child(4) {
        width: 5%; /* Status column - hidden on small screens anyway */
        min-width: 30px;
    }

    th, td {
        padding: 0.5rem 0.25rem;
        vertical-align: middle;
    }

    /* Hide status column on very small screens */
    .mobile-hide-small {
        display: none !important;
    }

    /* Make table more compact */
    .data-table th,
    .data-table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.8rem;
        line-height: 1.4;
        vertical-align: middle;
    }
    
    /* Ensure minimum touch target size for buttons */
    .data-table .action-buttons .btn {
        min-height: 32px;
        min-width: 32px;
        touch-action: manipulation;
    }

    /* Ultra-compact action buttons for very small screens */
    .action-buttons {
        display: flex;
        gap: 0.15rem;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
    }

    .action-buttons .btn {
        padding: 0.2rem 0.3rem;
        font-size: 0.65rem;
        min-width: 28px;
        height: 28px;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    
    /* Ensure only icons are shown on very small screens */
    .action-buttons .btn span {
        display: none !important;
    }
    
    .action-buttons .btn i {
        font-size: 0.65rem;
        margin: 0;
    }

    /* Compact bills and tasks view */
    .data-table th {
        padding: 0.5rem 0.25rem;
        font-size: 0.7rem;
        background: rgba(79, 172, 254, 0.1);
    }

    .data-table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
        line-height: 1.4;
    }

    /* Compact action buttons */
    .data-table .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.65rem;
        min-width: auto;
        margin: 0.1rem;
    }

    /* Hide less important columns on mobile */
    .mobile-hide {
        display: none;
    }

    /* Stack table content vertically on very small screens */
    .data-table tbody tr {
        border-bottom: 2px solid rgba(79, 172, 254, 0.1);
    }

    .data-table tbody tr:hover {
        background: rgba(79, 172, 254, 0.05);
        transform: none;
    }

    /* Ensure table cells wrap content properly on mobile */
    .data-table td {
        word-wrap: break-word;
        max-width: 150px;
    }

    /* Make action buttons more mobile-friendly */
    .action-buttons {
        display: flex;
        gap: 0.25rem;
        flex-wrap: wrap;
    }

    .action-buttons .btn {
        min-width: 32px;
        padding: 0.25rem 0.5rem;
    }

    /* Bill name with actions mobile layout */
    .bill-name-with-actions {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .bill-name {
        width: 100%;
        margin-bottom: 0.25rem;
        text-transform: uppercase;
        font-size: 0.9rem;
        font-weight: 600;
        letter-spacing: 0.5px;
    }

    .bill-name-with-actions .action-buttons {
        width: 100%;
        justify-content: flex-start;
    }
    
    /* Make bill names in table cells uppercase and larger */
    .data-table td:nth-child(2) {
        text-transform: uppercase;
        font-size: 0.85rem;
        font-weight: 600;
        letter-spacing: 0.3px;
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
        max-width: 0;
        overflow: hidden;
        line-height: 1.4;
    }

    /* Stack form elements */
    .modal-content {
        margin: 0.5rem;
    }

    .form-control {
        padding: 0.75rem;
    }

    /* Adjust sidebar for very small screens */
    .sidebar {
        width: 100vw;
    }

    .nav-item {
        padding: 1rem;
        font-size: 1rem;
    }
}

/* Landscape orientation adjustments */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        width: 250px;
        left: -250px;
    }

    .sidebar.open {
        left: 0;
    }

    .top-header {
        padding: 0.5rem 1rem;
    }

    .page-content {
        padding: 0.75rem;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .modal-content {
        max-height: 90vh;
    }
    
    /* Progress bars in landscape mode */
    .progress-bar,
    .progress-bar-small {
        height: 6px;
        margin: 0.2rem 0;
    }
    
    .progress-text {
        font-size: 0.65rem;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .nav-item {
        min-height: 48px;
    }

    .form-control {
        min-height: 44px;
    }

    .action-buttons .btn {
        min-height: 36px;
        min-width: 36px;
    }

    /* Larger tap targets */
    .sidebar-toggle {
        min-height: 44px;
    }
    
    /* Progress bars for touch devices */
    .progress-bar,
    .progress-bar-small {
        min-height: 10px; /* Larger for better touch visibility */
        cursor: pointer;
    }
    
    .installment-dot {
        width: 10px !important;
        height: 10px !important;
        cursor: pointer;
    }

    .modal-close {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Dark mode adjustments for mobile */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
    .sidebar {
        background: var(--bg-secondary);
        border-right: 1px solid var(--border-primary);
    }

    .top-header {
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-primary);
    }

    .modal-content {
        background: var(--bg-secondary);
        border: 1px solid var(--border-primary);
    }
}

/* Floating Bottom Navigation - iPhone Style */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    z-index: 1000;
    display: none;
}

.bottom-nav-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 100%;
    margin: 0 auto;
    padding: 0 16px;
}

/* Reorder: place Due next to Home */
.bottom-nav-container .bottom-nav-item[data-page="dashboard"] { order: 0; }
/* Ensure Due comes immediately after Home by keeping same order as default */
.bottom-nav-container .bottom-nav-item[data-page="due"] { order: 1; }

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #666;
    transition: all 0.2s ease;
    padding: 8px 12px;
    border-radius: 12px;
    min-width: 60px;
}

.bottom-nav-item:hover,
.bottom-nav-item.active {
    color: #4facfe;
    background: rgba(79, 172, 254, 0.1);
    transform: translateY(-2px);
}

.bottom-nav-icon {
    font-size: 18px;
    margin-bottom: 4px;
    transition: transform 0.2s ease;
}

.bottom-nav-item:hover .bottom-nav-icon {
    transform: scale(1.1);
}

.bottom-nav-label {
    font-size: 8px;
    font-weight: 500;
    text-align: center;
    line-height: 1;
}

/* Show bottom nav on mobile */
@media screen and (max-width: 768px) {
    .bottom-nav {
        display: block;
    }
    
    /* Add bottom padding to main content to account for floating nav */
    .main-content {
        padding-bottom: 80px;
    }
    
    /* Hide desktop sidebar on mobile when bottom nav is active */
    .sidebar {
        transform: translateX(-100%);
    }
}

/* Dark mode for bottom nav */
@media screen and (max-width: 768px) and (prefers-color-scheme: dark) {
    .bottom-nav {
        background: rgba(28, 28, 30, 0.95);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .bottom-nav-item {
        color: #999;
    }
    
    .bottom-nav-item:hover,
    .bottom-nav-item.active {
        color: #4facfe;
        background: rgba(79, 172, 254, 0.15);
    }
}

/* iOS-style Visual Elements and Animations */
@media screen and (max-width: 768px) {
    /* iOS-style cards and containers */
    .stat-card,
    .table-container,
    .modal-content {
        border-radius: 16px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        border: none;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }
    
    /* iOS-style buttons */
    .btn {
        border-radius: 12px;
        font-weight: 500;
        transition: all 0.2s ease;
        border: none;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
    
    .btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 6px 20px rgba(79, 172, 254, 0.3);
    }
    
    .btn:active {
        transform: translateY(0);
        transition: all 0.1s ease;
    }
    
    /* iOS-style form controls */
    .form-control {
        border-radius: 12px;
        border: 1px solid rgba(0, 0, 0, 0.1);
        background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        transition: all 0.2s ease;
    }
    
    .form-control:focus {
        border-color: #4facfe;
        box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
        transform: translateY(-1px);
    }
    
    /* iOS-style page transitions */
    .page-content {
        animation: slideInUp 0.3s ease-out;
    }
    
    /* Smooth scrolling for iOS feel */
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* iOS-style status bar spacing */
    .top-header {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }
}

/* iOS-style animations */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Dark mode iOS-style adjustments */
@media screen and (max-width: 768px) and (prefers-color-scheme: dark) {
    .stat-card,
    .table-container,
    .modal-content {
        background: rgba(28, 28, 30, 0.95);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .form-control {
        background: rgba(44, 44, 46, 0.9);
        border-color: rgba(255, 255, 255, 0.2);
        color: #fff;
    }
}

/* Print styles for mobile */
@media print {
    .sidebar,
    .sidebar-toggle,
    .user-menu,
    .action-buttons,
    .bottom-nav {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* Enhanced Mobile Interactions */
@media screen and (max-width: 768px) {
    /* Swipe gestures visual feedback */
    .swipe-left {
        transform: translateX(-20px);
        transition: transform 0.2s ease;
    }
    
    .swipe-right {
        transform: translateX(20px);
        transition: transform 0.2s ease;
    }
    
    /* Swipe overlay and active state for showing labels */
    .swipe-active {
        position: relative;
        transition: transform 0.15s ease-out;
        will-change: transform;
        z-index: 1;
    }
    .swipe-overlay {
        position: absolute;
        inset: 0;
        display: flex;
        align-items: stretch; /* allow full-height blocks */
        padding: 0 12px;
        font-size: 0.9em;
        font-weight: 600;
        pointer-events: none;
        z-index: 2;
        color: #fff;
    }
    .swipe-overlay .icon-block {
        height: 100%;
        width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 6px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.25);
        color: #fff;
        text-shadow: 0 1px 2px rgba(0,0,0,0.25);
    }
    .swipe-overlay .swipe-label {
        display: flex;
        align-items: center;
        padding: 0 8px;
        font-weight: 700;
        color: #fff;
        text-shadow: 0 1px 2px rgba(0,0,0,0.25);
    }
    .swipe-overlay .icon-block.edit { background: rgba(37, 99, 235, 0.95); }
    .swipe-overlay .icon-block.delete { background: rgba(185, 28, 28, 0.95); }
    .swipe-overlay .swipe-content {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 6px 10px;
        border-radius: 999px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.25);
        color: #fff;
        font-weight: 700;
        text-shadow: 0 1px 2px rgba(0,0,0,0.25);
    }
    .swipe-overlay .swipe-content.edit {
        background: rgba(37, 99, 235, 0.95);
    }
    .swipe-overlay .swipe-content.delete {
        background: rgba(239, 68, 68, 0.95);
    }
    
    /* Light background cues during swipe */
    .swipe-left {
        background: linear-gradient(90deg, rgba(239, 68, 68, 0.24) 0%, transparent 100%);
    }
    .swipe-right {
        background: linear-gradient(90deg, transparent 0%, rgba(96, 165, 250, 0.24) 100%);
    }

    /* Allow vertical scrolling in rows while handling horizontal swipes */
    tbody tr {
        touch-action: pan-y;
    }

    /* Reduce clutter above tables */
    .page-header .due-summary-stats { display: none !important; }
    /* Reintroduce period headers for bills view */
    /* .period-section h3 { display: none !important; } */
    /* .period-section h3 span[id^="total-"] { display: none !important; } */

    /* Remove table headers from bills tables */
    .data-table thead { display: none !important; }
    
    /* Mobile-specific animations */
    .mobile-fade-in {
        animation: mobileSlideUp 0.3s ease-out;
    }
    
    @keyframes mobileSlideUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    /* Enhanced mobile navigation */
    .mobile-nav {
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .mobile-nav-item {
        transition: all 0.2s ease;
        border-radius: 12px;
        margin: 0 4px;
    }
    
    .mobile-nav-item:active {
        transform: scale(0.95);
        background: rgba(79, 172, 254, 0.1);
    }
    
    .mobile-nav-item.active {
        background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
        color: white;
        box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
    }
    
    /* Mobile action button styles removed */
    
    /* Improved stat cards for mobile */
    .stat-card {
        border-radius: 16px;
        transition: all 0.2s ease;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .stat-card:active {
        transform: scale(0.98);
    }
    
    /* Mobile-optimized forms */
    .form-group input,
    .form-group select,
    .form-group textarea {
        min-height: 48px;
        font-size: 14px; /* Prevents zoom on iOS */
        border-radius: 12px;
        padding: 12px 16px;
    }
    
    /* Mobile modal improvements */
    .modal {
        padding: 10px;
    }
    
    .modal-content {
        border-radius: 20px;
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-header {
        padding: 20px 20px 10px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-footer {
        padding: 10px 20px 20px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    /* Safe area adjustments for notched devices */
    .top-header {
        padding-top: max(1rem, env(safe-area-inset-top));
    }
    
    .mobile-nav {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    
    /* Loading states for mobile */
    .mobile-loading {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 200px;
    }
    
    .mobile-loading::after {
        content: '';
        width: 40px;
        height: 40px;
        border: 3px solid rgba(79, 172, 254, 0.3);
        border-top: 3px solid #4facfe;
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }
    
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
}

.page-content {
    padding: 0 !important;
}

table {
    font-size: 8px;
}

.card {
    break-inside: avoid;
}

/* Financial Overview Mobile Styles */
@media screen and (max-width: 1024px) {
    .financial-overview-header {
        margin: 0.5rem 0;
    }

    .financial-overview-toggle {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .financial-overview-panel {
        padding: 1rem;
        gap: 1rem;
    }

    .financial-inputs {
        flex-direction: column;
        gap: 0.75rem;
    }

    .input-group {
        width: 100%;
    }

    .financial-summary {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .summary-card {
        padding: 0.75rem;
    }

    .summary-card h4 {
        font-size: 0.8rem;
    }

    .summary-card .amount {
        font-size: 1.1rem;
    }

    .upcoming-bills-preview {
        padding: 0.75rem;
    }

    .bills-list {
        gap: 0.5rem;
    }

    .bill-preview-item {
        padding: 0.5rem;
        font-size: 0.85rem;
    }
}

@media screen and (max-width: 768px) {
    .financial-overview-toggle {
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
    }

    .financial-overview-panel {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .financial-inputs {
        gap: 0.6rem;
    }

    .input-group label {
        font-size: 0.8rem;
    }

    .input-group input {
        padding: 0.6rem;
        font-size: 0.9rem;
    }

    .summary-card {
        padding: 0.6rem;
    }

    .summary-card h4 {
        font-size: 0.75rem;
        margin-bottom: 0.3rem;
    }

    .summary-card .amount {
        font-size: 1rem;
    }

    .payment-status {
        padding: 0.6rem;
        font-size: 0.8rem;
    }

    .upcoming-bills-preview {
        padding: 0.6rem;
    }

    .upcoming-bills-preview h4 {
        font-size: 0.85rem;
    }

    .bill-preview-item {
        padding: 0.4rem;
        font-size: 0.8rem;
    }

    .bill-preview-item .bill-name {
        font-size: 0.8rem;
    }

    .bill-preview-item .bill-amount {
        font-size: 0.8rem;
    }

    .bill-preview-item .bill-due {
        font-size: 0.7rem;
    }
}

@media screen and (max-width: 480px) {
    .financial-overview-header {
        margin: 0.25rem 0;
    }

    .financial-overview-toggle {
        padding: 0.5rem 0.6rem;
        font-size: 0.8rem;
    }

    .financial-overview-panel {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .financial-inputs {
        gap: 0.5rem;
    }

    .input-group {
        margin-bottom: 0;
    }

    .input-group label {
        font-size: 0.75rem;
        margin-bottom: 0.25rem;
    }

    .input-group input {
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    .financial-summary {
        gap: 0.5rem;
    }

    .summary-card {
        padding: 0.5rem;
    }

    .summary-card h4 {
        font-size: 0.7rem;
        margin-bottom: 0.25rem;
    }

    .summary-card .amount {
        font-size: 0.9rem;
    }

    .payment-status {
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    .upcoming-bills-preview {
        padding: 0.5rem;
    }

    .upcoming-bills-preview h4 {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }

    .bills-list {
        gap: 0.4rem;
    }

    .bill-preview-item {
        padding: 0.35rem;
        font-size: 0.75rem;
    }

    .bill-preview-item .bill-name {
        font-size: 0.75rem;
        font-weight: 500;
    }

    .bill-preview-item .bill-amount {
        font-size: 0.75rem;
        font-weight: 600;
    }

    .bill-preview-item .bill-due {
        font-size: 0.65rem;
        opacity: 0.8;
    }

    /* Ensure the toggle icon is properly sized on mobile */
    .financial-overview-toggle .toggle-icon {
        font-size: 0.8rem;
    }

    /* Make sure the panel doesn't overflow on small screens */
    .financial-overview-panel.show {
        max-height: 80vh;
        overflow-y: auto;
    }
}

/* Financial Overview Widget Mobile Styles */
@media screen and (max-width: 1024px) {
    .financial-overview-widget {
        margin-bottom: 0.75rem;
    }

    .financial-widget-layout {
        flex-direction: column;
        gap: 0.75rem;
    }

    .financial-widget-inputs {
        width: 100%;
    }

    .widget-input-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .widget-input-group {
        width: 100%;
    }

    .widget-summary-cards {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .widget-summary-card {
        padding: 0.5rem;
    }

    .widget-bills-table th,
    .widget-bills-table td {
        padding: 0.4rem 0.2rem;
        font-size: 0.8rem;
    }
}

@media screen and (max-width: 768px) {
    .financial-overview-widget {
        margin-bottom: 0.5rem;
    }

    .widget-header {
        padding: 0.5rem;
    }

    .widget-title h3 {
        font-size: 0.9rem;
    }

    .widget-subtitle {
        font-size: 0.75rem;
    }

    .widget-content {
        padding: 0.5rem;
    }

    .financial-widget-inputs {
        gap: 0.4rem;
    }

    .widget-input-group label {
        font-size: 0.75rem;
        margin-bottom: 0.2rem;
    }

    .widget-input-group input {
        padding: 0.4rem;
        font-size: 0.85rem;
    }

    .widget-summary-cards {
        gap: 0.4rem;
    }

    .widget-summary-card {
        padding: 0.4rem;
    }

    .card-label {
        font-size: 0.7rem;
        margin-bottom: 0.2rem;
    }

    .card-amount {
        font-size: 0.9rem;
    }

    .financial-widget-status {
        padding: 0.4rem;
    }

    .status-text {
        font-size: 0.75rem;
    }

    .widget-bills-header {
        margin-bottom: 0.4rem;
    }

    .widget-bills-header h4 {
        font-size: 0.8rem;
    }

    .widget-bills-count {
        font-size: 0.7rem;
    }

    .widget-bills-table th,
    .widget-bills-table td {
        padding: 0.3rem 0.15rem;
        font-size: 0.75rem;
    }

    .widget-bills-table th:last-child,
    .widget-bills-table td:last-child {
        display: none;
    }
}

@media screen and (max-width: 480px) {
    .financial-overview-widget {
        margin-bottom: 0.4rem;
    }

    .widget-header {
        padding: 0.4rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .widget-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .widget-title h3 {
        font-size: 0.85rem;
    }

    .widget-subtitle {
        font-size: 0.7rem;
    }

    .widget-content {
        padding: 0.4rem;
    }

    .financial-widget-inputs {
        gap: 0.3rem;
    }

    .widget-input-group label {
        font-size: 0.7rem;
        margin-bottom: 0.15rem;
    }

    .widget-input-group input {
        padding: 0.35rem;
        font-size: 0.8rem;
    }

    .widget-summary-cards {
        gap: 0.3rem;
    }

    .widget-summary-card {
        padding: 0.35rem;
    }

    .card-label {
        font-size: 0.65rem;
        margin-bottom: 0.15rem;
    }

    .card-amount {
        font-size: 0.85rem;
    }

    .financial-widget-status {
        padding: 0.35rem;
    }

    .status-indicator {
        width: 6px;
        height: 6px;
    }

    .status-text {
        font-size: 0.7rem;
    }

    .widget-bills-header {
        margin-bottom: 0.3rem;
    }

    .widget-bills-header h4 {
        font-size: 0.75rem;
    }

    .widget-bills-count {
        font-size: 0.65rem;
    }

    .widget-bills-table th,
    .widget-bills-table td {
        padding: 0.25rem 0.1rem;
        font-size: 0.7rem;
    }

    .widget-bills-table th:nth-child(3),
    .widget-bills-table td:nth-child(3),
    .widget-bills-table th:last-child,
    .widget-bills-table td:last-child {
        display: none;
    }

    /* Make the table more compact on very small screens */
    .widget-bills-table {
        font-size: 0.65rem;
    }

    .widget-bills-table th:first-child,
    .widget-bills-table td:first-child {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .sidebar {
        transition: none;
    }

    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }

    .card {
        border: 2px solid var(--border-primary);
    }

    .nav-item.active {
        border-left: 4px solid var(--accent-primary);
    }
}

/* Center only chart cards on small screens (avoid affecting other widgets) */
@media screen and (max-width: 640px) {
  /* Unpaid Bills pie card container */
  .pie-chart-card {
    margin: 0 auto;
    max-width: 420px;
    width: 100%;
  }

  /* Center the pie canvas for Unpaid Bills */
  .pie-chart-card .pie-chart-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
  }

  .pie-chart-card .pie-chart-container canvas,
  #unpaidBillsPieChart {
    width: 100% !important;
    max-width: 360px !important;
    height: auto !important;
    display: block;
    margin: 0 auto;
  }

  /* Center the IN/UIT doughnut canvas and allow larger width */
  #inoutStackedBarChart {
    display: block;
    margin: 0 auto;
    width: 100% !important;
    max-width: 520px !important;
    height: auto !important;
  }

  /* Center any subtitles under charts */
.widget-subtitle {
  text-align: center;
}
}
@media (max-width: 768px) {
  .installment-details { width: 100%; overflow: hidden; }
  .installment-list { gap: 0.5rem !important; }
  .installment-item { grid-template-columns: 1fr !important; gap: 0.5rem !important; padding: 0.5rem 0.6rem !important; }
  .installment-col.left { flex-direction: column; }
  .installment-col.center { text-align: left; }
  .installment-col.right { justify-content: flex-start; align-items: center; flex-wrap: wrap; gap: 0.35rem; }
  .installment-status-badge { font-size: 0.7rem; }
  .installment-number { font-size: 0.9rem; }
  .installment-amount { font-size: 0.9rem; }
  .installment-item .btn { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
}
