/**
 * Global Responsive Utilities
 * Additional responsive styles for forms, filters, tables, and common components
 */

/*--------------------------------------------------------------
# Responsive Forms & Filters
--------------------------------------------------------------*/
.filter-form,
.search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}

@media (max-width: 767.98px) {
    .filter-form,
    .search-form {
        flex-direction: column;
        gap: 12px;
    }

    .filter-form > *,
    .search-form > * {
        width: 100%;
    }

    .filter-form .form-group,
    .search-form .form-group {
        margin-bottom: 0;
    }

    .filter-form .btn,
    .search-form .btn {
        width: 100%;
    }
}

/*--------------------------------------------------------------
# Responsive Tables
--------------------------------------------------------------*/
.table-responsive-card {
    display: block;
}

@media (max-width: 767.98px) {
    /* Card-like table view on mobile */
    .table-responsive-card table {
        border: 0;
    }

    .table-responsive-card table thead {
        display: none;
    }

    .table-responsive-card table tr {
        display: block;
        margin-bottom: 15px;
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        padding: 15px;
    }

    .table-responsive-card table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid #eee;
    }

    .table-responsive-card table td:last-child {
        border-bottom: none;
    }

    .table-responsive-card table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #333;
        flex: 1;
        margin-right: 10px;
    }

    .table-responsive-card table td .btn-group,
    .table-responsive-card table td .action-buttons {
        display: flex;
        gap: 5px;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

/*--------------------------------------------------------------
# Responsive Action Buttons
--------------------------------------------------------------*/
.action-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

@media (max-width: 575.98px) {
    .action-buttons {
        justify-content: center;
        width: 100%;
    }

    .action-buttons .btn {
        flex: 1;
        min-width: 40px;
    }
}

/*--------------------------------------------------------------
# Responsive Page Header
--------------------------------------------------------------*/
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

@media (max-width: 575.98px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header .btn,
    .page-header .btn-group {
        width: 100%;
    }

    .page-header .btn-group .btn {
        flex: 1;
    }
}

/*--------------------------------------------------------------
# Responsive Cards Grid
--------------------------------------------------------------*/
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

@media (max-width: 575.98px) {
    .cards-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

/*--------------------------------------------------------------
# Responsive Stats/Info Boxes
--------------------------------------------------------------*/
.stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.stat-box {
    flex: 1;
    min-width: 150px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    text-align: center;
}

@media (max-width: 575.98px) {
    .stats-row {
        gap: 10px;
    }

    .stat-box {
        min-width: calc(50% - 5px);
        padding: 12px;
    }

    .stat-box h3,
    .stat-box .stat-value {
        font-size: 1.2rem;
    }

    .stat-box p,
    .stat-box .stat-label {
        font-size: 0.8rem;
    }
}

/*--------------------------------------------------------------
# Responsive Modal Adjustments
--------------------------------------------------------------*/
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-dialog-centered {
        min-height: calc(100% - 1rem);
    }

    .modal-header {
        padding: 12px 15px;
    }

    .modal-title {
        font-size: 1.1rem;
    }

    .modal-body {
        padding: 15px;
    }

    .modal-footer {
        padding: 12px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 100px;
    }

    /* Full screen modal on mobile */
    .modal-fullscreen-sm-down {
        width: 100vw;
        max-width: none;
        height: 100%;
        margin: 0;
    }

    .modal-fullscreen-sm-down .modal-content {
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    .modal-fullscreen-sm-down .modal-body {
        overflow-y: auto;
    }
}

/*--------------------------------------------------------------
# Responsive Breadcrumb
--------------------------------------------------------------*/
@media (max-width: 575.98px) {
    .breadcrumb {
        font-size: 0.75rem;
        padding: 0;
        margin-bottom: 10px;
    }

    .breadcrumb-item + .breadcrumb-item::before {
        padding: 0 4px;
    }
}

/*--------------------------------------------------------------
# Responsive List Groups
--------------------------------------------------------------*/
@media (max-width: 575.98px) {
    .list-group-item {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .list-group-item .badge {
        font-size: 0.7rem;
    }
}

/*--------------------------------------------------------------
# Responsive Nav Tabs
--------------------------------------------------------------*/
@media (max-width: 575.98px) {
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs .nav-item {
        flex-shrink: 0;
    }

    .nav-tabs .nav-link {
        padding: 8px 12px;
        font-size: 0.85rem;
        white-space: nowrap;
    }
}

/*--------------------------------------------------------------
# Responsive Quick Actions
--------------------------------------------------------------*/
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 575.98px) {
    .quick-actions {
        flex-direction: column;
    }

    .quick-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

/*--------------------------------------------------------------
# Responsive Date/Time Inputs
--------------------------------------------------------------*/
@media (max-width: 575.98px) {
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        min-height: 44px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/*--------------------------------------------------------------
# Responsive Select2 / Chosen
--------------------------------------------------------------*/
@media (max-width: 575.98px) {
    .select2-container {
        width: 100% !important;
    }

    .select2-container .select2-selection--single {
        height: 44px;
        padding: 8px 12px;
    }

    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 26px;
    }

    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 42px;
    }
}

/*--------------------------------------------------------------
# Touch-Friendly Utilities
--------------------------------------------------------------*/
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn-touch {
        min-height: 48px;
        min-width: 48px;
        padding: 12px 20px;
    }

    .form-check-input {
        width: 1.25em;
        height: 1.25em;
    }

    .form-check-label {
        padding-left: 0.5em;
    }

    /* Disable hover effects on touch devices */
    .btn:hover,
    .card:hover,
    .list-group-item:hover {
        transform: none;
    }
}

/*--------------------------------------------------------------
# Print Utilities
--------------------------------------------------------------*/
@media print {
    .no-print,
    .sidebar,
    .header,
    .footer,
    .btn:not(.btn-print),
    .pagination,
    .filter-form,
    .search-form {
        display: none !important;
    }

    .card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }

    .table {
        font-size: 10pt;
    }

    .table th,
    .table td {
        padding: 4px 8px !important;
    }

    a[href]::after {
        content: none !important;
    }
}

/*--------------------------------------------------------------
# Landscape Orientation Fixes
--------------------------------------------------------------*/
@media (max-height: 500px) and (orientation: landscape) {
    .modal-body {
        max-height: 50vh;
        overflow-y: auto;
    }

    .section-card {
        max-height: 60vh;
    }

    .scroll-content {
        max-height: 45vh;
    }
}
