/* Mobile Optimizations for Flashcard Filtering */

/* Base mobile styles */
@media (max-width: 768px) {
    /* Container adjustments */
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Header layout */
    .d-flex.justify-content-between {
        flex-direction: column !important;
        gap: 1rem !important;
        align-items: stretch !important;
    }

    .d-flex.justify-content-between .d-flex {
        flex-direction: column;
        width: 100%;
    }

    /* Typography scaling */
    h2 {
        font-size: 1.75rem;
        margin-bottom: 0.5rem;
    }

    h5 {
        font-size: 1.125rem;
    }

    h6 {
        font-size: 1rem;
    }

    /* Filter form mobile layout */
    .filter-form {
        padding: 1rem;
    }

    .row.g-3 > .col-md-4,
    .row.g-3 > .col-md-3,
    .row.g-3 > .col-md-2 {
        margin-bottom: 1rem;
    }

    /* Form controls mobile */
    .form-control,
    .form-select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.875rem 1rem;
        min-height: 48px; /* Touch target size */
    }

    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
        display: block;
    }

    /* Quick filter buttons */
    .quick-filter {
        font-size: 0.75rem;
        padding: 0.625rem 1rem;
        min-height: 44px; /* Touch target size */
        margin-bottom: 0.5rem;
        flex: 1;
        min-width: 0;
    }

    .d-flex.flex-wrap.gap-2 {
        gap: 0.5rem !important;
    }

    /* Advanced filters mobile */
    #advancedFilters {
        padding: 1rem;
    }

    #advancedFilters .col-md-6,
    #advancedFilters .col-md-4 {
        margin-bottom: 1.5rem;
    }

    .filter-section-title {
        font-size: 0.875rem;
        margin-bottom: 1rem;
    }

    /* Statistics dashboard mobile */
    .stats-dashboard .row.g-3 {
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
        margin-bottom: 0.5rem;
    }

    .stat-number {
        font-size: 1.5rem;
    }

    /* Flashcard grid mobile */
    .col-md-6.col-lg-4.col-xl-3 {
        width: 100%;
        margin-bottom: 1rem;
    }

    .flashcard-item {
        margin-bottom: 1rem;
    }

    .flashcard-item .card-title {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }

    .flashcard-item .card-text {
        font-size: 0.875rem;
        margin-bottom: 1rem;
    }

    /* Button groups mobile */
    .btn-group.w-100 {
        display: flex;
        width: 100%;
    }

    .btn-group .btn {
        flex: 1;
        font-size: 0.75rem;
        padding: 0.625rem 0.5rem;
        min-height: 44px;
    }

    /* Pagination mobile */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }

    .pagination .page-link {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Modal mobile */
    .modal-dialog {
        margin: 1rem;
        max-width: calc(100% - 2rem);
    }

    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }

    /* Preview card mobile */
    .flashcard-content {
        height: 250px;
    }

    .flashcard-front h4,
    .flashcard-back h4 {
        font-size: 1.125rem;
    }

    /* Stats display mobile */
    .row.text-center.small.text-muted.mb-3 {
        font-size: 0.75rem;
    }

    .stats-row .col-4 {
        flex: 0 0 33.333333%;
        max-width: 33.333333%;
    }

    /* Badges mobile */
    .badge {
        font-size: 0.625rem;
        padding: 0.25rem 0.5rem;
        margin-bottom: 0.25rem;
    }

    /* Alert messages mobile */
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }

    .alert .d-flex {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start !important;
    }

    /* Loading state mobile */
    #loadingState {
        padding: 2rem 1rem;
    }

    .spinner-border {
        width: 2.5rem;
        height: 2.5rem;
    }

    /* Empty state mobile */
    .empty-state {
        padding: 2rem 1rem;
    }

    .empty-state-icon {
        font-size: 3rem;
    }

    .empty-state-title {
        font-size: 1.25rem;
    }

    .empty-state-text {
        font-size: 0.875rem;
    }

    /* Mobile-specific touch targets */
    .btn,
    .preview-btn,
    .quick-filter {
        touch-action: manipulation; /* Prevents double-tap zoom */
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }

    /* Form checkboxes mobile */
    .form-check {
        margin-bottom: 1rem;
        padding: 0.75rem;
        background: #f8f9fa;
        border-radius: 0.5rem;
        border: 2px solid transparent;
        transition: all 0.2s ease;
    }

    .form-check:hover {
        border-color: #0d6efd;
        background: white;
    }

    .form-check-input {
        width: 20px;
        height: 20px;
        margin-right: 0.75rem;
    }

    .form-check-label {
        font-size: 0.875rem;
        line-height: 1.4;
        cursor: pointer;
        display: flex;
        align-items: center;
    }

    /* Mobile navigation improvements */
    .navbar {
        padding: 0.5rem 1rem;
    }

    .navbar-brand {
        font-size: 1.125rem;
    }

    .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}

/* Small mobile phones (portrait) */
@media (max-width: 480px) {
    /* Extra tight spacing */
    .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Typography adjustments */
    h2 {
        font-size: 1.5rem;
    }

    h5 {
        font-size: 1rem;
    }

    /* Form controls extra small */
    .form-control,
    .form-select {
        padding: 0.75rem 0.875rem;
        font-size: 16px; /* Keep 16px to prevent zoom */
    }

    /* Quick filters stacked */
    .quick-filter {
        font-size: 0.625rem;
        padding: 0.5rem 0.75rem;
        min-width: calc(50% - 0.25rem);
        margin-right: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .quick-filter:nth-child(even) {
        margin-right: 0;
    }

    /* Flashcard cards extra compact */
    .flashcard-item {
        margin-bottom: 0.75rem;
    }

    .flashcard-item .card-body {
        padding: 1rem;
    }

    .flashcard-item .card-title {
        font-size: 0.875rem;
        line-height: 1.3;
    }

    .flashcard-item .card-text {
        font-size: 0.75rem;
    }

    /* Stats extra compact */
    .row.text-center.small.text-muted.mb-3 {
        font-size: 0.625rem;
        gap: 0.25rem;
    }

    .stat-number {
        font-size: 1.125rem;
    }

    /* Button groups extra compact */
    .btn-group .btn {
        font-size: 0.625rem;
        padding: 0.5rem 0.375rem;
        min-height: 40px;
    }

    /* Badges extra small */
    .badge {
        font-size: 0.5625rem;
        padding: 0.1875rem 0.375rem;
    }

    /* Modal small screens */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-header {
        padding: 0.75rem 1rem;
    }

    .modal-body {
        padding: 0.75rem;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
        order: 2;
    }

    .modal-footer .btn-secondary {
        order: 1;
    }

    /* Preview card small screens */
    .flashcard-content {
        height: 200px;
    }

    .flashcard-front h4,
    .flashcard-back h4 {
        font-size: 1rem;
    }

    .flashcard-front p,
    .flashcard-back p {
        font-size: 0.75rem;
    }

    /* Advanced filters collapsible */
    #advancedFilters {
        padding: 0.75rem;
    }

    .filter-section-title {
        font-size: 0.75rem;
    }

    /* Stats dashboard small screens */
    .stat-card {
        padding: 0.75rem;
    }

    .stat-number {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* Pagination small screens */
    .pagination {
        gap: 0.125rem;
    }

    .pagination .page-link {
        font-size: 0.75rem;
        padding: 0.375rem 0.625rem;
        min-width: 40px;
        min-height: 40px;
    }

    /* Loading state small screens */
    #loadingState {
        padding: 1.5rem 0.5rem;
    }

    .spinner-border {
        width: 2rem;
        height: 2rem;
    }

    /* Empty state small screens */
    .empty-state {
        padding: 1.5rem 0.5rem;
    }

    .empty-state-icon {
        font-size: 2.5rem;
    }

    .empty-state-title {
        font-size: 1.125rem;
    }

    /* Touch targets minimum sizes */
    .btn,
    .preview-btn,
    .form-control,
    .form-select,
    .quick-filter {
        min-height: 44px;
        min-width: 44px;
    }

    /* Safe area insets for notched phones */
    @supports (padding: max(0px)) {
        .container-fluid {
            padding-left: max(0.5rem, env(safe-area-inset-left));
            padding-right: max(0.5rem, env(safe-area-inset-right));
        }

        .modal-dialog {
            margin-left: max(0.5rem, env(safe-area-inset-left));
            margin-right: max(0.5rem, env(safe-area-inset-right));
        }

        .navbar {
            padding-left: max(0.5rem, env(safe-area-inset-left));
            padding-right: max(0.5rem, env(safe-area-inset-right));
        }
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce vertical spacing */
    .row.mb-4 {
        margin-bottom: 1.5rem;
    }

    .card-body {
        padding: 1rem;
    }

    /* Compact preview cards */
    .flashcard-content {
        height: 180px;
    }

    /* More compact filter form */
    .filter-form {
        padding: 0.75rem;
    }

    .row.g-3 > * {
        margin-bottom: 0.75rem;
    }

    /* Landscape modal adjustments */
    .modal-dialog {
        margin: 0.5rem auto;
        max-width: 90%;
        max-height: 90vh;
    }

    .modal-content {
        max-height: 90vh;
        overflow: hidden;
    }

    .modal-body {
        max-height: calc(90vh - 140px);
        overflow-y: auto;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Sharper borders for retina displays */
    .flashcard-item,
    .btn,
    .form-control,
    .form-select {
        border-width: 1px;
    }

    .badge {
        border-width: 0.5px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .filter-form {
        background: #1a1a1a;
        color: #ffffff;
    }

    .form-control,
    .form-select {
        background-color: #2d2d2d;
        border-color: #404040;
        color: #ffffff;
    }

    .form-control:focus,
    .form-select:focus {
        background-color: #333333;
        border-color: #0d6efd;
        color: #ffffff;
    }

    .flashcard-item {
        background: #1a1a1a;
        border-color: #404040;
    }

    .flashcard-item .card-header {
        background: linear-gradient(135deg, #2d2d2d, #1f1f1f);
        border-bottom-color: #404040;
    }

    .stats-dashboard {
        background: #1a1a1a;
    }

    .stat-card {
        background: #2d2d2d;
        border-color: #404040;
    }

    .modal-content {
        background: #1a1a1a;
        color: #ffffff;
    }

    .modal-header {
        background: #2d2d2d;
        border-bottom-color: #404040;
    }
}

/* Accessibility animations respect */
@media (prefers-reduced-motion: reduce) {
    .flashcard-item,
    .quick-filter,
    .btn,
    .fade-in,
    .slide-up {
        transition: none;
        animation: none;
    }
}