/* Mobile Table Optimizations */
@media (max-width: 768px) {
    /* Responsive Table Container */
    .table-responsive {
        border: none;
        border-radius: 1rem;
        overflow: hidden;
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
        margin-bottom: 1.5rem;
    }
    
    .table {
        font-size: 0.875rem;
        margin: 0;
        background: var(--bg-primary);
    }
    
    .table th {
        padding: 1rem 0.75rem;
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        background: var(--bg-secondary);
        border-bottom: 2px solid var(--border-light);
        color: var(--text-primary);
        white-space: nowrap;
    }
    
    .table td {
        padding: 1rem 0.75rem;
        border-bottom: 1px solid var(--border-light);
        vertical-align: middle;
        color: var(--text-primary);
    }
    
    .table tbody tr {
        transition: background-color 0.2s ease;
    }
    
    .table tbody tr:hover {
        background: var(--bg-secondary);
    }
    
    .table tbody tr:last-child td {
        border-bottom: none;
    }
    
    /* Action buttons in tables */
    .table .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
        margin: 0.125rem;
        border-radius: 0.5rem;
        width: auto;
    }
    
    .table .btn-group {
        flex-direction: row;
        gap: 0.25rem;
    }
    
    .table .btn-group .btn {
        margin: 0;
    }
}

/* Stack table on very small screens */
@media (max-width: 576px) {
    .table-responsive.stack-mobile table,
    .table-responsive.stack-mobile thead,
    .table-responsive.stack-mobile tbody,
    .table-responsive.stack-mobile th,
    .table-responsive.stack-mobile td,
    .table-responsive.stack-mobile tr {
        display: block;
    }
    
    .table-responsive.stack-mobile thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    .table-responsive.stack-mobile tr {
        border: 1px solid var(--border-light);
        border-radius: 1rem;
        margin-bottom: 1rem;
        padding: 1rem;
        background: var(--bg-primary);
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    }
    
    .table-responsive.stack-mobile td {
        border: none;
        position: relative;
        padding: 0.75rem 0 0.75rem 35%;
        text-align: right;
        border-bottom: 1px solid var(--border-light);
    }
    
    .table-responsive.stack-mobile td:last-child {
        border-bottom: none;
    }
    
    .table-responsive.stack-mobile td:before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 30%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    /* Action buttons in stacked tables */
    .table-responsive.stack-mobile .btn-group {
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }
    
    .table-responsive.stack-mobile .btn {
        width: 100%;
        margin: 0;
        padding: 0.75rem;
        font-size: 0.875rem;
    }
}

/* Admin List Tables */
@media (max-width: 768px) {
    .admin-table-container {
        padding: 0.5rem;
        margin: 0;
    }
    
    .admin-table-header {
        padding: 1rem;
        background: var(--bg-secondary);
        border-radius: 1rem 1rem 0 0;
        border-bottom: 1px solid var(--border-light);
    }
    
    .admin-table-header h3 {
        font-size: 1.125rem;
        margin: 0;
        color: var(--text-primary);
        font-weight: 600;
    }
    
    .admin-table-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 1rem;
        background: var(--bg-secondary);
        border-radius: 0 0 1rem 1rem;
        border-top: 1px solid var(--border-light);
    }
    
    .admin-table-actions .btn {
        width: 100%;
        padding: 0.875rem;
        font-size: 0.875rem;
        border-radius: 0.75rem;
        margin: 0;
    }
    
    /* Search and filter forms */
    .admin-search-form {
        padding: 1rem;
        background: var(--bg-primary);
        border-radius: 1rem;
        margin-bottom: 1rem;
        border: 1px solid var(--border-light);
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    }
    
    .admin-search-form .form-control {
        margin-bottom: 0.75rem;
        border-radius: 0.75rem;
        padding: 0.875rem 1rem;
        font-size: 0.875rem;
    }
    
    .admin-search-form .btn {
        width: 100%;
        padding: 0.875rem;
        border-radius: 0.75rem;
        font-size: 0.875rem;
        margin: 0;
    }
}

/* Pagination Mobile */
@media (max-width: 768px) {
    .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.25rem;
        padding: 1rem;
    }
    
    .page-item {
        margin: 0;
    }
    
    .page-link {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        border-radius: 0.75rem;
        margin: 0;
        border: 1px solid var(--border-light);
        color: var(--text-primary);
        background: var(--bg-primary);
        transition: all 0.2s ease;
    }
    
    .page-link:hover {
        background: var(--primary);
        color: white;
        border-color: var(--primary);
        transform: translateY(-1px);
        box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
    }
    
    .page-item.active .page-link {
        background: var(--primary);
        border-color: var(--primary);
        color: white;
        box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
    }
    
    .page-item.disabled .page-link {
        opacity: 0.5;
        pointer-events: none;
    }
    
    /* Hide page numbers on very small screens, keep only prev/next */
    @media (max-width: 480px) {
        .page-item:not(.page-item-prev):not(.page-item-next) {
            display: none;
        }
        
        .page-item:nth-child(-n+3),
        .page-item:nth-last-child(-n+3) {
            display: block;
        }
    }
}

/* Form Mobile Enhancements */
@media (max-width: 768px) {
    .form-container {
        padding: 1rem;
        background: var(--bg-primary);
        border-radius: 1rem;
        margin: 0.5rem;
        border: 1px solid var(--border-light);
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    }
    
    .form-header {
        text-align: center;
        padding: 1rem 0 1.5rem 0;
        border-bottom: 1px solid var(--border-light);
        margin-bottom: 1.5rem;
    }
    
    .form-header h2 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
        color: var(--text-primary);
        font-weight: 600;
    }
    
    .form-header p {
        font-size: 0.875rem;
        color: var(--text-secondary);
        margin: 0;
    }
    
    .form-group {
        margin-bottom: 1.5rem;
    }
    
    .form-label {
        font-size: 0.875rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
        display: block;
        color: var(--text-primary);
    }
    
    .form-control {
        padding: 1rem;
        font-size: 0.875rem;
        border-radius: 0.75rem;
        width: 100%;
        border: 2px solid var(--border-light);
        background: var(--bg-primary);
        color: var(--text-primary);
        transition: all 0.3s ease;
    }
    
    .form-control:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
        transform: translateY(-1px);
    }
    
    .form-control::placeholder {
        color: var(--text-muted);
    }
    
    .form-text {
        font-size: 0.75rem;
        color: var(--text-muted);
        margin-top: 0.375rem;
        line-height: 1.4;
    }
    
    .form-check {
        margin-bottom: 1rem;
        padding-right: 1.5rem;
    }
    
    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        margin-top: 0.125rem;
        border: 2px solid var(--border-medium);
        border-radius: 0.375rem;
    }
    
    .form-check-input:checked {
        background-color: var(--primary);
        border-color: var(--primary);
    }
    
    .form-check-label {
        font-size: 0.875rem;
        color: var(--text-primary);
        margin-right: 0.5rem;
        line-height: 1.4;
    }
    
    .input-group {
        margin-bottom: 1.5rem;
    }
    
    .input-group .form-control {
        border-radius: 0.75rem 0 0 0.75rem;
    }
    
    .input-group-text {
        padding: 1rem;
        font-size: 0.875rem;
        border-radius: 0 0.75rem 0.75rem 0;
        background: var(--bg-secondary);
        border: 2px solid var(--border-light);
        border-right: none;
        color: var(--text-secondary);
    }
    
    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding-top: 1.5rem;
        border-top: 1px solid var(--border-light);
        margin-top: 1.5rem;
    }
    
    .form-actions .btn {
        width: 100%;
        padding: 1rem;
        font-size: 0.875rem;
        border-radius: 0.75rem;
        margin: 0;
        font-weight: 600;
    }
    
    .form-actions .btn-primary {
        order: -1;
    }
}

/* Select and Textarea Mobile */
@media (max-width: 768px) {
    select.form-control {
        padding: 1rem 0.75rem;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
        background-position: left 0.75rem center;
        background-repeat: no-repeat;
        background-size: 16px 12px;
        padding-left: 2.5rem;
    }
    
    textarea.form-control {
        min-height: 120px;
        resize: vertical;
        line-height: 1.5;
    }
    
    .form-floating {
        position: relative;
    }
    
    .form-floating > .form-control {
        padding: 1.5rem 1rem 0.5rem 1rem;
    }
    
    .form-floating > label {
        position: absolute;
        top: 0;
        right: 1rem;
        height: 100%;
        padding: 1rem 0;
        pointer-events: none;
        border: 1px solid transparent;
        transform-origin: 100% 0;
        transition: opacity 0.1s ease-in-out, transform 0.1s ease-in-out;
        color: var(--text-muted);
        font-size: 0.875rem;
    }
    
    .form-floating > .form-control:focus ~ label,
    .form-floating > .form-control:not(:placeholder-shown) ~ label {
        opacity: 0.65;
        transform: scale(0.85) translateY(-0.5rem) translateX(0.15rem);
    }
}

/* File Input Mobile */
@media (max-width: 768px) {
    .form-file {
        position: relative;
        display: inline-block;
        width: 100%;
        margin-bottom: 1rem;
    }
    
    .form-file-input {
        position: absolute;
        z-index: -1;
        opacity: 0;
    }
    
    .form-file-label {
        display: block;
        width: 100%;
        padding: 1rem;
        font-size: 0.875rem;
        font-weight: 600;
        color: var(--text-primary);
        background: var(--bg-secondary);
        border: 2px dashed var(--border-medium);
        border-radius: 0.75rem;
        cursor: pointer;
        text-align: center;
        transition: all 0.3s ease;
    }
    
    .form-file-label:hover {
        border-color: var(--primary);
        background: var(--bg-tertiary);
    }
    
    .form-file-input:focus + .form-file-label {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    }
    
    .form-file-text {
        display: block;
        margin-top: 0.5rem;
        font-size: 0.75rem;
        color: var(--text-muted);
    }
}

/* Error States Mobile */
@media (max-width: 768px) {
    .is-invalid {
        border-color: var(--danger) !important;
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
    }
    
    .invalid-feedback {
        display: block;
        width: 100%;
        margin-top: 0.375rem;
        font-size: 0.75rem;
        color: var(--danger);
        line-height: 1.4;
    }
    
    .is-valid {
        border-color: var(--success) !important;
        box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
    }
    
    .valid-feedback {
        display: block;
        width: 100%;
        margin-top: 0.375rem;
        font-size: 0.75rem;
        color: var(--success);
        line-height: 1.4;
    }
}

/* Loading States Mobile */
@media (max-width: 768px) {
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 9999;
    }
    
    .loading-spinner {
        background: var(--bg-primary);
        padding: 2rem;
        border-radius: 1rem;
        text-align: center;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    }
    
    .loading-spinner .spinner-border {
        width: 3rem;
        height: 3rem;
        color: var(--primary);
    }
    
    .loading-text {
        margin-top: 1rem;
        font-size: 0.875rem;
        color: var(--text-secondary);
    }
}