/* ===================================
   RESPONSIVE FORMS AND TABLES
   ===================================
   Enhanced responsive design for forms and tables
   without changing existing content
*/

/* ===================================
   RESPONSIVE FORMS
   =================================== */

/* Form container responsive improvements */
.form-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem;
}

@media (max-width: 767.98px) {
    .form-container {
        padding: 0.5rem;
    }
}

/* Form group responsive improvements */
.form-group,
.mb-3,
.mb-4 {
    margin-bottom: 1rem;
}

@media (max-width: 767.98px) {
    .form-group,
    .mb-3,
    .mb-4 {
        margin-bottom: 0.75rem;
    }
}

/* Form control responsive improvements */
.form-control,
.form-select,
.form-check-input {
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

@media (max-width: 767.98px) {
    .form-control,
    .form-select,
    .form-check-input {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px; /* Better touch targets */
        padding: 0.5rem 0.75rem;
    }
}

/* Form control focus states */
.form-control:focus,
.form-select:focus {
    color: #212529;
    background-color: #fff;
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Form label responsive improvements */
.form-label,
label {
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #212529;
}

@media (max-width: 767.98px) {
    .form-label,
    label {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }
}

/* Form check responsive improvements */
.form-check {
    position: relative;
    display: block;
    padding-left: 1.25em;
}

@media (max-width: 767.98px) {
    .form-check {
        padding-left: 1.5em;
        margin-bottom: 0.5rem;
    }
    
    .form-check-input {
        width: 1.25em;
        height: 1.25em;
        margin-top: 0.125em;
        vertical-align: top;
        background-color: #fff;
        background-repeat: no-repeat;
        background-position: center;
        background-size: contain;
        border: 1px solid rgba(0, 0, 0, 0.25);
        appearance: none;
        color-adjust: exact;
    }
    
    .form-check-input:checked {
        background-color: #0d6efd;
        border-color: #0d6efd;
    }
}

/* Form check label responsive improvements */
.form-check-label {
    color: #212529;
    cursor: pointer;
}

@media (max-width: 767.98px) {
    .form-check-label {
        font-size: 0.9rem;
        line-height: 1.4;
    }
}

/* Input group responsive improvements */
.input-group {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    width: 100%;
}

@media (max-width: 767.98px) {
    .input-group {
        flex-direction: column;
    }
    
    .input-group > .form-control,
    .input-group > .form-select {
        border-radius: 0.25rem;
        margin-bottom: 0.5rem;
    }
    
    .input-group > .form-control:not(:last-child),
    .input-group > .form-select:not(:last-child) {
        border-top-right-radius: 0.25rem;
        border-bottom-right-radius: 0.25rem;
    }
    
    .input-group > .form-control:not(:first-child),
    .input-group > .form-select:not(:first-child) {
        border-top-left-radius: 0.25rem;
        border-bottom-left-radius: 0.25rem;
    }
}

/* Input group text responsive improvements */
.input-group-text {
    display: flex;
    align-items: center;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    text-align: center;
    white-space: nowrap;
    background-color: #e9ecef;
    border: 1px solid #ced4da;
}

@media (max-width: 767.98px) {
    .input-group-text {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
        border-radius: 0.25rem;
        margin-bottom: 0.5rem;
    }
}

/* Button responsive improvements */
.btn {
    display: inline-block;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    background-color: transparent;
    border: 1px solid transparent;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

@media (max-width: 767.98px) {
    .btn {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 1rem;
        border-radius: 0.375rem;
    }
    
    .btn-sm {
        min-height: 36px;
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    
    .btn-lg {
        min-height: 52px;
        padding: 1rem 1.5rem;
        font-size: 1.125rem;
    }
}

/* Button group responsive improvements */
.btn-group {
    position: relative;
    display: inline-flex;
    vertical-align: middle;
}

@media (max-width: 767.98px) {
    .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group > .btn {
        border-radius: 0.25rem;
        margin-bottom: 0.5rem;
    }
    
    .btn-group > .btn:not(:last-child) {
        border-top-right-radius: 0.25rem;
        border-bottom-right-radius: 0.25rem;
    }
    
    .btn-group > .btn:not(:first-child) {
        border-top-left-radius: 0.25rem;
        border-bottom-left-radius: 0.25rem;
    }
}

/* ===================================
   RESPONSIVE TABLES
   =================================== */

/* Table responsive wrapper */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
    .table-responsive {
        border: none;
        margin: -1rem;
        padding: 1rem;
    }
}

/* Table responsive improvements */
.table {
    width: 100%;
    margin-bottom: 1rem;
    color: #212529;
    vertical-align: top;
    border-color: #dee2e6;
}

@media (max-width: 767.98px) {
    .table {
        font-size: 0.875rem;
        margin-bottom: 0;
        border-collapse: collapse;
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.25rem;
        vertical-align: top;
        border-top: 1px solid #dee2e6;
        white-space: nowrap;
    }
    
    .table thead th {
        vertical-align: bottom;
        border-bottom: 2px solid #dee2e6;
        background-color: #f8f9fa;
        font-weight: 600;
    }
    
    .table tbody + tbody {
        border-top: 2px solid #dee2e6;
    }
}

/* Table striped responsive improvements */
.table-striped > tbody > tr:nth-of-type(odd) > td,
.table-striped > tbody > tr:nth-of-type(odd) > th {
    color: #212529;
    background-color: rgba(0, 0, 0, 0.05);
}

@media (max-width: 767.98px) {
    .table-striped > tbody > tr:nth-of-type(odd) > td,
    .table-striped > tbody > tr:nth-of-type(odd) > th {
        background-color: rgba(0, 0, 0, 0.02);
    }
}

/* Table hover responsive improvements */
.table-hover > tbody > tr:hover > td,
.table-hover > tbody > tr:hover > th {
    color: #212529;
    background-color: rgba(0, 0, 0, 0.075);
}

@media (max-width: 767.98px) {
    .table-hover > tbody > tr:hover > td,
    .table-hover > tbody > tr:hover > th {
        background-color: rgba(0, 0, 0, 0.05);
    }
}

/* Table bordered responsive improvements */
.table-bordered {
    border: 1px solid #dee2e6;
}

@media (max-width: 767.98px) {
    .table-bordered {
        border: none;
    }
    
    .table-bordered th,
    .table-bordered td {
        border: 1px solid #dee2e6;
    }
    
    .table-bordered thead th,
    .table-bordered thead td {
        border-bottom-width: 2px;
    }
}

/* Table borderless responsive improvements */
.table-borderless th,
.table-borderless td,
.table-borderless thead th,
.table-borderless tbody + tbody {
    border: 0;
}

@media (max-width: 767.98px) {
    .table-borderless th,
    .table-borderless td {
        border-top: 1px solid #dee2e6;
    }
}

/* Table small responsive improvements */
.table-sm th,
.table-sm td {
    padding: 0.25rem;
}

@media (max-width: 767.98px) {
    .table-sm th,
    .table-sm td {
        padding: 0.375rem 0.25rem;
        font-size: 0.8rem;
    }
}

/* Table large responsive improvements */
.table-lg th,
.table-lg td {
    padding: 1rem;
}

@media (max-width: 767.98px) {
    .table-lg th,
    .table-lg td {
        padding: 0.75rem 0.5rem;
        font-size: 1rem;
    }
}

/* ===================================
   RESPONSIVE DATA TABLES
   =================================== */

/* Data table responsive improvements */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

@media (max-width: 767.98px) {
    .data-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .data-table thead {
        display: none;
    }
    
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }
    
    .data-table tr {
        border: 1px solid #dee2e6;
        border-radius: 0.25rem;
        margin-bottom: 1rem;
        padding: 1rem;
        background-color: #fff;
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    }
    
    .data-table td {
        border: none;
        padding: 0.5rem 0;
        text-align: left;
        white-space: normal;
    }
    
    .data-table td:before {
        content: attr(data-label) ": ";
        font-weight: 600;
        color: #495057;
        display: inline-block;
        width: 40%;
        margin-right: 1rem;
    }
}

/* ===================================
   RESPONSIVE CARD TABLES
   =================================== */

/* Card table responsive improvements */
.card-table {
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
    overflow: hidden;
}

@media (max-width: 767.98px) {
    .card-table {
        border: none;
        border-radius: 0;
        box-shadow: none;
    }
    
    .card-table .table {
        margin-bottom: 0;
    }
    
    .card-table .table th,
    .card-table .table td {
        padding: 0.75rem 0.5rem;
        border-top: 1px solid #dee2e6;
    }
    
    .card-table .table thead th {
        background-color: #f8f9fa;
        border-bottom: 2px solid #dee2e6;
        font-weight: 600;
        font-size: 0.875rem;
    }
}

/* ===================================
   RESPONSIVE PAGINATION
   =================================== */

/* Pagination responsive improvements */
.pagination {
    display: flex;
    padding-left: 0;
    list-style: none;
    border-radius: 0.25rem;
}

@media (max-width: 767.98px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        margin: 1rem 0;
    }
    
    .pagination .page-item {
        margin: 0.125rem;
    }
    
    .pagination .page-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
        border-radius: 0.25rem;
        min-width: 44px;
        text-align: center;
    }
}

/* ===================================
   RESPONSIVE SEARCH AND FILTER
   =================================== */

/* Search form responsive improvements */
.search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (max-width: 767.98px) {
    .search-form {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .search-form .form-control {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .search-form .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* Filter form responsive improvements */
.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: 0.25rem;
}

@media (max-width: 767.98px) {
    .filter-form {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem;
    }
    
    .filter-form .form-control,
    .filter-form .form-select {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .filter-form .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ===================================
   RESPONSIVE MODAL FORMS
   =================================== */

/* Modal form responsive improvements */
.modal-form .form-group {
    margin-bottom: 1rem;
}

@media (max-width: 767.98px) {
    .modal-form .form-group {
        margin-bottom: 0.75rem;
    }
    
    .modal-form .form-control,
    .modal-form .form-select {
        font-size: 16px;
        min-height: 44px;
    }
    
    .modal-form .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ===================================
   RESPONSIVE FORM VALIDATION
   =================================== */

/* Form validation responsive improvements */
.was-validated .form-control:valid,
.form-control.is-valid {
    border-color: #198754;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='m2.3 6.73.94-.94 1.88-1.88L6.73 2.3l.94.94L4.12 6.73l-.94.94-.94-.94z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.was-validated .form-control:invalid,
.form-control.is-invalid {
    border-color: #dc3545;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath d='m5.8 4.6 1.4 1.4 1.4-1.4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

@media (max-width: 767.98px) {
    .was-validated .form-control:valid,
    .form-control.is-valid,
    .was-validated .form-control:invalid,
    .form-control.is-invalid {
        padding-right: calc(1.5em + 1rem);
        background-position: right calc(0.5em + 0.25rem) center;
        background-size: calc(1em + 0.5rem) calc(1em + 0.5rem);
    }
}

/* Validation feedback responsive improvements */
.valid-feedback,
.invalid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #198754;
}

.invalid-feedback {
    color: #dc3545;
}

.was-validated .form-control:valid ~ .valid-feedback,
.was-validated .form-control:valid ~ .valid-tooltip,
.form-control.is-valid ~ .valid-feedback,
.form-control.is-valid ~ .valid-tooltip {
    display: block;
}

.was-validated .form-control:invalid ~ .invalid-feedback,
.was-validated .form-control:invalid ~ .invalid-tooltip,
.form-control.is-invalid ~ .invalid-feedback,
.form-control.is-invalid ~ .invalid-tooltip {
    display: block;
}

@media (max-width: 767.98px) {
    .valid-feedback,
    .invalid-feedback {
        font-size: 0.8rem;
        margin-top: 0.125rem;
    }
}

/* ===================================
   RESPONSIVE FORM LAYOUTS
   =================================== */

/* Form row responsive improvements */
.form-row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -0.5rem;
    margin-left: -0.5rem;
}

@media (max-width: 767.98px) {
    .form-row {
        flex-direction: column;
        margin-right: 0;
        margin-left: 0;
    }
    
    .form-row > .col,
    .form-row > [class*="col-"] {
        padding-right: 0;
        padding-left: 0;
        margin-bottom: 1rem;
    }
}

/* Form inline responsive improvements */
.form-inline {
    display: flex;
    flex-flow: row wrap;
    align-items: center;
}

@media (max-width: 767.98px) {
    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }
    
    .form-inline .form-control {
        display: block;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .form-inline .form-check {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ===================================
   RESPONSIVE FORM ACCESSIBILITY
   =================================== */

/* Form accessibility responsive improvements */
@media (max-width: 767.98px) {
    .form-control:focus,
    .form-select:focus,
    .form-check-input:focus {
        outline: 2px solid #0d6efd;
        outline-offset: 2px;
    }
    
    .btn:focus {
        outline: 2px solid #0d6efd;
        outline-offset: 2px;
    }
    
    .form-check-input:focus {
        border-color: #86b7fe;
        outline: 0;
        box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
    }
}

/* ===================================
   RESPONSIVE FORM PERFORMANCE
   =================================== */

/* Form performance responsive improvements */
@media (max-width: 767.98px) {
    .form-control,
    .form-select,
    .btn {
        transition: none;
    }
    
    .form-control:focus,
    .form-select:focus,
    .btn:focus {
        transition: none;
    }
}

/* ===================================
   RESPONSIVE FORM PRINT
   =================================== */

@media print {
    .form-control,
    .form-select,
    .btn {
        border: 1px solid #000 !important;
        background-color: #fff !important;
        color: #000 !important;
    }
    
    .table {
        border-collapse: collapse !important;
    }
    
    .table th,
    .table td {
        border: 1px solid #000 !important;
    }
}
