/**
 * AuctLect Platform - Mobile Optimization Fixes
 * Phase 11A: Responsive improvements
 * Phase 11B: Touch optimization
 * Phase 11C: Performance optimization (Lazy Loading styles)
 */

/* ===== Global Mobile Improvements ===== */

/* Remove Bootstrap 5 dropdown gap (default margin-top: 0.125rem causes a gap below navbar) */
.navbar .dropdown-menu {
    --bs-dropdown-spacer: 0;
    margin-top: 0;
}

/* Fix mobile navbar element order: Brand | LangSelector | Hamburger | AccountIcon */
@media (max-width: 991.98px) {
    .user-dropdown {
        order: 3;
        margin-left: 0.5rem;
    }
}

/* Prevent horizontal scroll on all pages */
html {
    overflow-x: hidden;
}
body {
    overflow-x: hidden; /* Fallback for older browsers */
    overflow-x: clip;   /* Modern browsers: visually clips overflow WITHOUT creating a scroll
                           container, so position: sticky (navbar sticky-top) keeps working */
    max-width: 100%;
    position: relative; /* Required for iOS Safari overflow-x: hidden fallback */
}

/* Ensure minimum touch target size (44px) */
@media (max-width: 768px) {
    .btn,
    .nav-link,
    .dropdown-item,
    .form-select,
    .form-control {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 38px;
        padding: 0.5rem 0.75rem;
    }

    /* Better spacing for mobile */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* ===== Phase 11B-1: Enhanced Touch Targets ===== */

@media (max-width: 768px) {
    /* All clickable elements - minimum 44px touch target */
    a:not(.navbar-brand),
    button,
    [role="button"],
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    .clickable,
    .card-link,
    .list-group-item-action {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Links in text - add padding for easier tapping */
    p a,
    li a,
    td a {
        padding: 0.25rem 0;
        margin: -0.25rem 0;
        display: inline;
        min-height: auto;
    }

    /* Button spacing - ensure 8px gap between tap targets */
    .btn + .btn,
    .btn + a,
    a + .btn {
        margin-left: 0.5rem;
    }

    /* Vertical button groups */
    .btn-group-vertical .btn {
        margin-bottom: 0.5rem;
    }

    .btn-group-vertical .btn:last-child {
        margin-bottom: 0;
    }

    /* Action buttons in cards */
    .card-footer .btn,
    .card-body .btn {
        margin-bottom: 0.5rem;
    }

    .card-footer .btn:last-child,
    .card-body .btn:last-child {
        margin-bottom: 0;
    }

    /* Checkbox and Radio - larger tap area */
    .form-check {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-left: 2rem;
        margin-bottom: 0.5rem;
    }

    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        margin-top: 0;
        margin-left: -2rem;
        cursor: pointer;
    }

    .form-check-label {
        padding: 0.5rem 0;
        padding-left: 0.5rem;
        cursor: pointer;
        flex: 1;
    }

    /* Switch toggle - larger */
    .form-switch .form-check-input {
        width: 2.5rem;
        height: 1.5rem;
    }

    /* Dropdown items */
    .dropdown-menu {
        padding: 0.5rem 0;
    }

    .dropdown-item {
        padding: 0.75rem 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Pagination */
    .pagination {
        gap: 0.25rem;
    }

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

    /* Badge links */
    a.badge {
        padding: 0.5rem 0.75rem;
        min-height: 32px;
    }

    /* List group items */
    .list-group-item {
        padding: 0.875rem 1rem;
        min-height: 44px;
    }

    .list-group-item-action {
        cursor: pointer;
    }

    /* Breadcrumb links */
    .breadcrumb-item a {
        padding: 0.25rem 0.5rem;
        margin: -0.25rem -0.5rem;
        border-radius: 0.25rem;
    }

    /* Close buttons */
    .btn-close {
        width: 44px;
        height: 44px;
        padding: 0.75rem;
    }

    /* Icon buttons */
    .btn-icon,
    .icon-btn,
    [class*="btn-outline-"] i:only-child {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Tab navigation */
    .nav-tabs .nav-link,
    .nav-pills .nav-link {
        padding: 0.75rem 1rem;
        min-height: 44px;
    }

    /* Accordion buttons */
    .accordion-button {
        min-height: 48px;
        padding: 1rem 1.25rem;
    }

    /* Toast close button */
    .toast .btn-close {
        width: 32px;
        height: 32px;
        padding: 0.5rem;
    }
}

/* ===== Phase 11B-2: Touch Feedback ===== */

@media (max-width: 768px) {
    /* Active state feedback for buttons */
    .btn:active {
        transform: scale(0.97);
        transition: transform 0.1s ease;
    }

    .btn-lg:active {
        transform: scale(0.98);
    }

    .btn-sm:active {
        transform: scale(0.95);
    }

    /* Primary button active feedback */
    .btn-primary:active,
    .btn-accent:active {
        box-shadow: 0 0 0 3px rgba(139, 115, 85, 0.3);
    }

    /* Outline button active feedback */
    [class*="btn-outline-"]:active {
        box-shadow: 0 0 0 3px rgba(139, 115, 85, 0.2);
    }

    /* Card tap feedback */
    .card-clickable:active,
    .work-card:active,
    .notification-item:active {
        transform: scale(0.99);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        transition: all 0.15s ease;
    }

    /* List item tap feedback */
    .list-group-item-action:active {
        background-color: rgba(139, 115, 85, 0.1);
        transition: background-color 0.1s ease;
    }

    /* Nav link tap feedback */
    .nav-link:active {
        background-color: rgba(139, 115, 85, 0.1);
        border-radius: 0.5rem;
        transition: background-color 0.1s ease;
    }

    /* Dropdown item tap feedback */
    .dropdown-item:active {
        background-color: rgba(139, 115, 85, 0.15);
        color: inherit;
    }

    /* Checkbox/Radio tap feedback */
    .form-check:active {
        background-color: rgba(139, 115, 85, 0.05);
        border-radius: 0.5rem;
        transition: background-color 0.1s ease;
    }

    /* Pagination tap feedback */
    .page-link:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }

    /* Accordion button tap feedback */
    .accordion-button:active {
        background-color: rgba(139, 115, 85, 0.1);
    }

    /* FAQ item tap feedback */
    .faq-question:active {
        background-color: rgba(139, 115, 85, 0.1);
    }

    /* Notification action button feedback */
    .notification-actions .btn:active {
        transform: scale(0.95);
        background-color: rgba(139, 115, 85, 0.1);
    }

    /* Ripple effect base (applied via JS) */
    .touch-ripple {
        position: relative;
        overflow: hidden;
    }

    .touch-ripple::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        transform: translate(-50%, -50%);
        opacity: 0;
    }

    .touch-ripple:active::after {
        width: 200%;
        height: 200%;
        opacity: 1;
        transition: width 0.3s ease, height 0.3s ease, opacity 0.3s ease;
    }

    /* Disable hover effects on touch devices */
    @media (hover: none) {
        .btn:hover,
        .nav-link:hover,
        .dropdown-item:hover,
        .list-group-item-action:hover {
            background-color: inherit;
            color: inherit;
        }

        /* Keep focus styles for accessibility */
        .btn:focus,
        .nav-link:focus,
        .dropdown-item:focus,
        .list-group-item-action:focus {
            outline: 2px solid var(--color-accent, #8B7355);
            outline-offset: 2px;
        }
    }
}

/* ===== Navigation Mobile Improvements ===== */
@media (max-width: 991px) {
    .navbar-custom .navbar-collapse {
        background: var(--color-bg-card, #fff);
        padding: 1rem;
        margin-top: 0.5rem;
        border-radius: 0.5rem;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    .navbar-custom .navbar-nav {
        margin-bottom: 1rem;
    }

    .navbar-custom .nav-link {
        padding: 0.75rem 1rem !important;
        border-radius: 0.5rem;
        margin-bottom: 0.25rem;
    }

    .navbar-custom .d-flex {
        flex-direction: column;
        gap: 0.5rem !important;
        width: 100%;
    }

    .navbar-custom .d-flex .btn {
        width: 100%;
        justify-content: center;
    }

    .navbar-custom .language-selector {
        width: 100%;
    }

    /* Better hamburger button styling */
    .navbar-toggler {
        border: 2px solid var(--color-accent, #8B7355);
        padding: 0.5rem 0.75rem;
        border-radius: 0.5rem;
    }

    .navbar-toggler:focus {
        box-shadow: 0 0 0 3px rgba(139, 115, 85, 0.2);
    }

    .navbar-toggler-icon {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%238B7355' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
    }
}

/* ===== Table Responsive Fixes ===== */
.table-responsive-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    /* Make tables scrollable */
    .user-table,
    .revenue-table,
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .user-table th,
    .user-table td,
    .revenue-table th,
    .revenue-table td {
        min-width: 100px;
    }

    /* Card-style table for very small screens */
    .table-card-mobile tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e0e0e0;
        border-radius: 0.5rem;
        padding: 1rem;
    }

    .table-card-mobile tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border: none;
    }

    .table-card-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: 1rem;
    }

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

/* ===== Admin Dashboard Mobile ===== */
@media (max-width: 768px) {
    /* Mobile menu toggle button */
    .admin-menu-toggle {
        display: flex !important;
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        z-index: 1001;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        cursor: pointer;
    }

    .admin-menu-toggle:active {
        transform: scale(0.95);
    }

    /* Overlay when sidebar is open */
    .admin-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .admin-overlay.active {
        display: block;
    }

    /* Sidebar open state */
    .admin-sidebar.open {
        transform: translateX(0);
    }

    /* Stats grid mobile */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    .stat-card {
        padding: 1rem !important;
    }

    .stat-card .icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.2rem !important;
    }

    .stat-card .info h3 {
        font-size: 1.3rem !important;
    }

    .stat-card .info p {
        font-size: 0.75rem !important;
    }

    /* Panel header mobile */
    .panel-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .panel-header .d-flex {
        width: 100%;
        flex-wrap: wrap;
    }

    .panel-header .form-select,
    .panel-header .form-control {
        flex: 1;
        min-width: 120px;
    }

    /* Filter stats mobile */
    .filter-stats {
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    .filter-stats .stat-btn {
        flex: 1;
        min-width: calc(50% - 0.5rem);
        text-align: center;
        padding: 0.5rem !important;
        font-size: 0.8rem;
    }

    /* Admin header mobile */
    .admin-header {
        padding: 0.75rem 1rem !important;
    }

    #current-section-title {
        font-size: 1rem;
    }

    /* Quick actions mobile */
    .quick-actions {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    .quick-action-btn {
        padding: 1rem !important;
    }

    .quick-action-btn i {
        font-size: 1.25rem !important;
    }

    /* Work/DMCA cards mobile */
    .work-card,
    .dmca-card,
    .translation-card {
        padding: 1rem !important;
    }

    .work-card .d-flex,
    .dmca-card .d-flex,
    .translation-card .d-flex {
        flex-direction: column;
        gap: 0.75rem;
    }

    .work-card .d-flex > div:last-child,
    .dmca-card .d-flex > div:last-child,
    .translation-card .d-flex > div:last-child {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Finance cards mobile */
    .finance-card {
        padding: 1.5rem !important;
    }

    .finance-card h3 {
        font-size: 1.75rem !important;
    }

    /* Modal mobile */
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-xl {
        max-width: calc(100% - 1rem);
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    .quick-actions {
        grid-template-columns: 1fr !important;
    }

    .filter-stats .stat-btn {
        min-width: 100%;
    }
}

/* ===== Dashboard Mobile ===== */
@media (max-width: 768px) {
    .welcome-banner {
        padding: 1.25rem !important;
        text-align: center;
    }

    .welcome-banner h1 {
        font-size: 1.25rem !important;
    }

    .welcome-banner .d-flex {
        justify-content: center !important;
    }

    .dashboard-section .section-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .work-item {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .work-item .work-cover {
        margin-bottom: 0.75rem;
    }

    .work-item .work-stats {
        width: 100%;
        display: flex;
        justify-content: space-between;
        padding-top: 0.75rem;
        margin-top: 0.75rem;
        border-top: 1px solid var(--color-border, #e0e0e0);
    }

    .usage-card {
        padding: 1rem !important;
    }

    .usage-count {
        font-size: 2rem !important;
    }
}

/* ===== Notifications Mobile ===== */
@media (max-width: 768px) {
    /* Notification page layout */
    .notification-container .page-header .d-flex {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .notification-container .page-header .btn {
        margin-top: 0.5rem;
    }

    /* Stats row */
    .notification-container .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Filter bar */
    .notification-container .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .notification-container .filter-left,
    .notification-container .filter-right {
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Notification item */
    .notification-item {
        padding: 1rem;
        flex-wrap: wrap;
    }

    /* Icon smaller on mobile */
    .notification-icon {
        width: 40px;
        height: 40px;
        margin-right: 0.75rem;
    }

    .notification-icon i {
        font-size: 1rem;
    }

    /* Content takes full width, text wraps normally */
    .notification-content {
        flex: 1;
        min-width: 0;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .notification-title {
        font-size: 0.95rem;
        flex-wrap: wrap;
    }

    .notification-message {
        font-size: 0.85rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
    }

    .notification-meta {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Actions always visible on mobile */
    .notification-actions {
        width: 100%;
        margin-left: 0;
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid var(--color-border, #e0e0e0);
        display: flex;
        gap: 0.5rem;
    }

    .notification-actions .btn {
        opacity: 1;
        flex: 1;
    }
}

@media (max-width: 576px) {
    .notification-container .stats-row {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .stat-mini {
        padding: 0.75rem;
    }

    .stat-mini .stat-value {
        font-size: 1.25rem;
    }
}

/* ===== Analytics Mobile ===== */
@media (max-width: 768px) {
    /* Chart containers */
    .chart-container {
        height: 250px !important;
        min-height: 250px;
    }

    /* Period selector */
    .period-selector {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .period-selector .btn {
        flex: 1;
        min-width: calc(33% - 0.5rem);
    }
}

/* ===== Account Settings Mobile ===== */
@media (max-width: 768px) {
    .settings-nav {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 0.5rem;
        margin-bottom: 1rem;
        border-bottom: 1px solid var(--color-border, #e0e0e0);
    }

    .settings-nav .nav-link {
        white-space: nowrap;
        padding: 0.5rem 1rem;
    }

    .settings-section {
        padding: 1rem;
    }
}

/* ===== Support Pages Mobile ===== */
@media (max-width: 768px) {
    .faq-item {
        padding: 1rem;
    }

    .faq-question {
        font-size: 0.95rem;
    }

    .support-card {
        padding: 1rem;
    }

    .ticket-item {
        padding: 1rem;
    }

    /* Only apply to ticket items, not notification items */
    .ticket-item > .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ===== Forms Mobile ===== */
@media (max-width: 576px) {
    .form-row {
        flex-direction: column;
    }

    .form-row > * {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Only apply to search/button input groups, not password fields */
    .search-input-group,
    .input-group-search {
        flex-direction: column;
    }

    .search-input-group .form-control,
    .search-input-group .btn,
    .input-group-search .form-control,
    .input-group-search .btn {
        width: 100%;
        border-radius: 0.5rem !important;
    }

    .search-input-group .btn,
    .input-group-search .btn {
        margin-top: 0.5rem;
    }
}

/* ===== Login & Register Pages Mobile ===== */
@media (max-width: 576px) {
    /* Login/Register card adjustments */
    .login-card,
    .register-card {
        margin: 0.5rem;
        padding: 1.5rem !important;
    }

    /* Register form: Stack name fields vertically */
    .register-card .row .col-6 {
        width: 100%;
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Add spacing between stacked name fields */
    .register-card .row .col-6:first-child {
        margin-bottom: 0;
    }

    /* Role selector: Make touch-friendly */
    .role-selector {
        gap: 0.5rem !important;
    }

    .role-option {
        padding: 0.75rem !important;
        min-height: 80px;
    }

    .role-option i {
        font-size: 1.25rem !important;
    }

    .role-option .role-title {
        font-size: 0.85rem;
    }

    .role-option .role-desc {
        font-size: 0.7rem;
    }

    /* Password toggle button positioning fix */
    .login-card .input-group,
    .register-card .input-group {
        flex-direction: row !important;
        flex-wrap: nowrap;
    }

    .login-card .input-group .form-control,
    .register-card .input-group .form-control {
        border-radius: 0.5rem !important;
    }

    /* Social buttons */
    .social-buttons {
        gap: 0.5rem !important;
    }

    .btn-social {
        padding: 0.75rem !important;
        font-size: 0.9rem;
    }

    /* Form labels */
    .login-card .form-label,
    .register-card .form-label {
        font-size: 0.85rem;
    }

    /* Header text */
    .login-header h1,
    .register-header h1 {
        font-size: 1.25rem;
    }

    .login-header p,
    .register-header p {
        font-size: 0.85rem;
    }
}

/* ===== Hero & CTA Section Mobile ===== */
@media (max-width: 576px) {
    /* Hero buttons stack vertically */
    .hero-section .d-flex.justify-content-center {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem !important;
    }

    .hero-section .btn-lg {
        width: 100%;
        max-width: 280px;
    }

    /* Hero title line break handling */
    .hero-section h1 br {
        display: none;
    }

    /* Language badges wrap better */
    .hero-section .d-flex.flex-wrap {
        justify-content: center;
        gap: 0.5rem !important;
    }

    .hero-section .badge {
        font-size: 0.7rem;
        padding: 0.35rem 0.6rem;
    }
}

/* CTA Section Mobile */
@media (max-width: 576px) {
    section.py-5.text-center .d-flex.justify-content-center {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem !important;
    }

    section.py-5.text-center .btn-lg {
        width: 100%;
        max-width: 280px;
    }
}

/* ===== Footer Mobile ===== */
@media (max-width: 768px) {
    .footer-custom {
        text-align: center;
    }

    .footer-custom .row > div {
        margin-bottom: 1.5rem;
    }

    .footer-custom h6 {
        margin-top: 0.5rem;
    }

    .footer-custom ul {
        padding-left: 0;
    }

    .footer-custom .d-flex {
        justify-content: center !important;
    }
}

/* ===== Phase 11B-3: Swipe Actions (CSS Part) ===== */

@media (max-width: 768px) {
    /* Swipeable notification item */
    .notification-item.swipeable {
        position: relative;
        overflow: hidden;
        touch-action: pan-y;
        transition: transform 0.2s ease;
    }

    /* Swipe action backgrounds */
    .swipe-action-left,
    .swipe-action-right {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 80px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        font-size: 1.25rem;
    }

    .swipe-action-left {
        left: 0;
        background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    }

    .swipe-action-right {
        right: 0;
        background: linear-gradient(135deg, #dc3545 0%, #e74c3c 100%);
    }

    /* Swipe hint animation */
    .swipe-hint {
        animation: swipeHint 2s ease-in-out infinite;
    }

    @keyframes swipeHint {
        0%, 100% {
            transform: translateX(0);
        }
        50% {
            transform: translateX(-10px);
        }
    }

    /* Swipeable list items */
    .list-group-item.swipeable {
        position: relative;
        overflow: hidden;
        touch-action: pan-y;
    }

    /* Ticket item swipe */
    .ticket-item.swipeable {
        position: relative;
        overflow: hidden;
        touch-action: pan-y;
        transition: transform 0.2s ease;
    }

    /* Swipe delete indicator */
    .swipe-delete-indicator {
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        color: #dc3545;
        font-size: 1.5rem;
        opacity: 0;
        transition: opacity 0.2s ease;
    }

    .swipeable.swiping-left .swipe-delete-indicator {
        opacity: 1;
    }

    /* Prevent text selection during swipe */
    .swipeable.swiping {
        user-select: none;
        -webkit-user-select: none;
    }
}

/* ===== Pull to Refresh Indicator ===== */

@media (max-width: 768px) {
    .pull-refresh-indicator {
        position: fixed;
        top: 0;
        left: 50%;
        transform: translateX(-50%) translateY(-100%);
        width: 40px;
        height: 40px;
        background: var(--color-bg-card, #fff);
        border-radius: 50%;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1000;
        transition: transform 0.2s ease;
    }

    .pull-refresh-indicator.visible {
        transform: translateX(-50%) translateY(60px);
    }

    .pull-refresh-indicator.refreshing {
        animation: spin 1s linear infinite;
    }

    @keyframes spin {
        from {
            transform: translateX(-50%) translateY(60px) rotate(0deg);
        }
        to {
            transform: translateX(-50%) translateY(60px) rotate(360deg);
        }
    }

    .pull-refresh-indicator i {
        color: var(--color-accent, #8B7355);
        font-size: 1.25rem;
    }
}

/* ===== Bottom Action Bar (Mobile) ===== */

@media (max-width: 768px) {
    /* Fixed bottom action bar for forms */
    .bottom-action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 1rem;
        background: var(--color-bg-card, #fff);
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
        z-index: 100;
        display: flex;
        gap: 0.75rem;
    }

    .bottom-action-bar .btn {
        flex: 1;
    }

    /* Add padding to body when bottom action bar is present */
    body.has-bottom-action-bar {
        padding-bottom: 80px;
    }
}

/* ===== Floating Action Button ===== */
/* NOTE: Renamed .fab → .fab-btn to avoid collision with Font Awesome's .fab (brand icons) */

@media (max-width: 768px) {
    .fab-btn {
        position: fixed;
        bottom: 1.5rem;
        right: 1.5rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--color-accent, #8B7355) 0%, #6d5a43 100%);
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(139, 115, 85, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        z-index: 100;
        transition: all 0.2s ease;
    }

    .fab-btn:active {
        transform: scale(0.95);
        box-shadow: 0 2px 8px rgba(139, 115, 85, 0.4);
    }

    .fab-btn:hover {
        background: linear-gradient(135deg, #6d5a43 0%, var(--color-accent, #8B7355) 100%);
    }

    /* FAB with label */
    .fab-btn-extended {
        width: auto;
        padding: 0 1.25rem;
        border-radius: 28px;
        gap: 0.5rem;
    }

    .fab-btn-extended span {
        font-size: 0.9rem;
        font-weight: 500;
    }
}

/* ===== Phase 11C-1: Lazy Loading Styles ===== */

/* Base lazy image styles */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-image.lazy-loaded {
    opacity: 1;
}

.lazy-image.lazy-loading {
    opacity: 0.5;
}

.lazy-image.lazy-error {
    opacity: 1;
    background: #f0f0f0;
}

/* Placeholder skeleton animation */
.lazy-placeholder {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Manga page placeholder */
.manga-page-placeholder {
    background: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 2rem;
}

.manga-page-placeholder::before {
    content: '';
    width: 40px;
    height: 40px;
    border: 3px solid #555;
    border-top-color: #888;
    border-radius: 50%;
    animation: spin-loader 1s linear infinite;
}

@keyframes spin-loader {
    to {
        transform: rotate(360deg);
    }
}

/* Thumbnail placeholder */
.thumbnail-placeholder {
    background: #444;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumbnail-placeholder::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #555;
    border-top-color: #777;
    border-radius: 50%;
    animation: spin-loader 1s linear infinite;
}

/* Book cover placeholder */
.book-cover-placeholder {
    background: linear-gradient(135deg, #e0d6cc 0%, #d4c9bd 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-accent, #8B7355);
}

.book-cover-placeholder i {
    font-size: 2rem;
    opacity: 0.5;
}

/* Image container with aspect ratio */
.lazy-image-container {
    position: relative;
    overflow: hidden;
    background: #f5f5f5;
}

.lazy-image-container.ratio-4-3 {
    aspect-ratio: 4 / 3;
}

.lazy-image-container.ratio-3-4 {
    aspect-ratio: 3 / 4;
}

.lazy-image-container.ratio-16-9 {
    aspect-ratio: 16 / 9;
}

.lazy-image-container.ratio-1-1 {
    aspect-ratio: 1 / 1;
}

.lazy-image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Loading spinner overlay */
.lazy-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border: 3px solid rgba(139, 115, 85, 0.2);
    border-top-color: var(--color-accent, #8B7355);
    border-radius: 50%;
    animation: spin-loader 1s linear infinite;
}

/* Error state */
.lazy-error-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #999;
}

.lazy-error-state i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.lazy-error-state span {
    font-size: 0.75rem;
    display: block;
}

/* Manga viewer specific */
.manga-page.lazy-image {
    max-width: 100%;
    max-height: calc(100vh - 140px);
    object-fit: contain;
}

/* Thumbnail lazy loading */
.thumbnail img.lazy-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Native lazy loading support indicator */
img[loading="lazy"] {
    /* Modern browsers support native lazy loading */
}

/* ===== RTL (Arabic) Support for Pattern C Navbar ===== */
[dir="rtl"] .user-menu {
    right: auto;
    left: 0;
}

@media (max-width: 991.98px) {
    [dir="rtl"] .user-menu {
        right: auto;
        left: 10px;
    }
}

/* ===== Print Styles ===== */
@media print {
    .admin-sidebar,
    .admin-menu-toggle,
    .navbar,
    .footer-custom,
    .btn,
    .no-print {
        display: none !important;
    }

    .admin-main {
        margin-left: 0 !important;
    }

    body {
        font-size: 12pt;
    }
}
