/**
 * Finance Module Responsive Styles
 * Mobile-first responsive design for all Finance views
 * Location: public/assets/finance/css/responsive.css
 * Part of Finance Module Usability Overhaul - Phase 3.1
 */

/* ==================== Base Mobile Styles ==================== */

/* Touch-friendly targets (minimum 44x44px) */
.kt-btn,
.form-control,
.form-select,
button,
a.kt-menu-link {
    min-height: 44px;
}

/* Prevent zoom on input focus (iOS) */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ==================== Small Mobile (< 480px) ==================== */

@media screen and (max-width: 479px) {
    /* Stack form columns */
    .row.g-4 > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Full-width buttons */
    .kt-btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Compact card headers */
    .kt-card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .kt-card-header .kt-card-title {
        font-size: 1rem;
    }
    
    /* Stack toolbar items */
    .kt-container-fixed {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    
    /* Hide breadcrumb on very small screens */
    .breadcrumb {
        display: none;
    }
    
    /* Compact table cells */
    .kt-table th,
    .kt-table td {
        padding: 0.5rem;
        font-size: 0.75rem;
    }
    
    /* Hide less important columns */
    .kt-table [data-priority="low"] {
        display: none;
    }
    
    /* Stack action buttons */
    .kt-card-footer {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    /* Full-width search */
    .kt-input {
        width: 100%;
    }
    
    /* Compact stats cards */
    .quick-stats {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    
    .quick-stat {
        padding: 0.5rem;
    }
    
    .quick-stat .stat-value {
        font-size: 1rem;
    }
}

/* ==================== Mobile (480px - 767px) ==================== */

@media screen and (min-width: 480px) and (max-width: 767px) {
    /* Two-column layout for forms */
    .row.g-4 > .col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Horizontal scroll for tables */
    .kt-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Sticky first column */
    .kt-table th:first-child,
    .kt-table td:first-child {
        position: sticky;
        left: 0;
        background: white;
        z-index: 1;
    }
    
    /* Compact pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }
    
    .pagination .page-link {
        padding: 0.375rem 0.625rem;
        font-size: 0.875rem;
    }
}

/* ==================== Tablet (768px - 1023px) ==================== */

@media screen and (min-width: 768px) and (max-width: 1023px) {
    /* Two-column form layout */
    .row.g-4 > .col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
    
    /* Sidebar adjustments */
    .finance-context-sidebar {
        width: 240px;
    }
    
    /* Compact entry point cards */
    .entry-point-card .card-body {
        padding: 1rem;
    }
    
    .entry-point-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .entry-point-title {
        font-size: 1rem;
    }
    
    .entry-point-description {
        font-size: 0.8125rem;
    }
}

/* ==================== Desktop (1024px - 1279px) ==================== */

@media screen and (min-width: 1024px) and (max-width: 1279px) {
    /* Standard layout */
    .kt-container-fixed {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    /* Sidebar visible */
    .finance-context-sidebar {
        width: 260px;
    }
}

/* ==================== Large Desktop (1280px+) ==================== */

@media screen and (min-width: 1280px) {
    /* Full sidebar */
    .finance-context-sidebar {
        width: 280px;
    }
    
    /* Wider containers */
    .kt-container-fixed {
        max-width: 1400px;
    }
}

/* ==================== Grid View Responsive ==================== */

/* Mobile grid adjustments */
@media screen and (max-width: 767px) {
    .grid-view-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .grid-view-table {
        min-width: 800px;
    }
    
    .grid-view-cell {
        min-width: 60px;
        padding: 0.375rem;
        font-size: 0.75rem;
    }
    
    /* Sticky student name column */
    .grid-view-table th:first-child,
    .grid-view-table td:first-child {
        position: sticky;
        left: 0;
        background: white;
        z-index: 2;
        min-width: 150px;
    }
    
    /* Month header scroll indicator */
    .grid-view-container::after {
        content: '→ Scroll for more months';
        display: block;
        text-align: center;
        padding: 0.5rem;
        font-size: 0.75rem;
        color: var(--kt-muted-foreground);
        background: linear-gradient(to right, transparent, var(--kt-muted) 50%);
    }
}

/* ==================== Form Responsive ==================== */

/* Mobile form layout */
@media screen and (max-width: 991px) {
    /* Stack main content and sidebar */
    .row.g-4 > .col-lg-8,
    .row.g-4 > .col-lg-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Sidebar becomes bottom section */
    .row.g-4 > .col-lg-4 {
        order: 2;
        margin-top: 1.5rem;
    }
    
    /* Horizontal action buttons */
    .kt-card-body .d-flex.flex-column.gap-3 {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .kt-card-body .d-flex.flex-column.gap-3 > * {
        flex: 1 1 auto;
        min-width: 120px;
    }
}

/* ==================== Dashboard Responsive ==================== */

@media screen and (max-width: 991px) {
    /* Two-column entry points on tablet */
    .entry-point-card {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

@media screen and (max-width: 575px) {
    /* Single column entry points on mobile */
    .entry-point-card {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Compact daily cash widget */
    .daily-cash-widget .d-flex {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    .daily-cash-widget .stat-value {
        font-size: 1.5rem;
    }
}

/* ==================== Modal Responsive ==================== */

@media screen and (max-width: 575px) {
    .kt-modal-content {
        margin: 0.5rem;
        max-height: calc(100vh - 1rem);
    }
    
    .kt-modal-body {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }
    
    .kt-modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .kt-modal-footer .kt-btn {
        width: 100%;
    }
}

/* ==================== Print Styles ==================== */

@media print {
    /* Hide non-essential elements */
    .finance-context-sidebar,
    .kt-menu,
    .kt-btn:not(.print-visible),
    .pagination,
    .bulk-operations-bar,
    .filter-chips-container,
    nav,
    footer {
        display: none !important;
    }
    
    /* Full width content */
    .kt-container-fixed {
        max-width: 100% !important;
        padding: 0 !important;
    }
    
    /* Remove shadows and borders */
    .kt-card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
    
    /* Ensure table fits on page */
    .kt-table {
        font-size: 10pt;
    }
    
    .kt-table th,
    .kt-table td {
        padding: 4px 8px;
    }
    
    /* Page breaks */
    .kt-card {
        page-break-inside: avoid;
    }
    
    tr {
        page-break-inside: avoid;
    }
    
    /* Show URLs for links */
    a[href]::after {
        content: none; /* Disable for cleaner print */
    }
}

/* ==================== Touch Device Optimizations ==================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .kt-btn {
        min-height: 48px;
        padding: 0.75rem 1.25rem;
    }
    
    /* Remove hover effects that don't work on touch */
    .kt-btn:hover,
    .kt-menu-link:hover,
    .entry-point-card:hover {
        transform: none;
    }
    
    /* Add active states instead */
    .kt-btn:active,
    .kt-menu-link:active,
    .entry-point-card:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
    
    /* Larger checkboxes */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
    }
    
    /* Swipe hint for horizontal scroll */
    .kt-table-wrapper::before {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 40px;
        background: linear-gradient(to right, transparent, rgba(0,0,0,0.05));
        pointer-events: none;
        z-index: 1;
    }
}

/* ==================== Landscape Mobile ==================== */

@media screen and (max-width: 896px) and (orientation: landscape) {
    /* Reduce vertical spacing */
    .kt-card-header,
    .kt-card-body,
    .kt-card-footer {
        padding: 0.75rem;
    }
    
    /* Compact form groups */
    .form-group {
        margin-bottom: 0.75rem;
    }
    
    /* Smaller page title */
    .page-heading {
        font-size: 1.125rem;
    }
}

/* ==================== High DPI / Retina ==================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Sharper borders */
    .kt-card,
    .kt-table,
    .form-control {
        border-width: 0.5px;
    }
}

/* ==================== Reduced Motion ==================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .animate-spin {
        animation: none;
    }
}

/* ==================== Dark Mode Support ==================== */

@media (prefers-color-scheme: dark) {
    .finance-context-sidebar {
        background: var(--kt-background-dark, #1f2937);
        border-color: var(--kt-border-dark, #374151);
    }
    
    .kt-card {
        background: var(--kt-background-dark, #1f2937);
    }
    
    .kt-table th:first-child,
    .kt-table td:first-child {
        background: var(--kt-background-dark, #1f2937);
    }
}
