/* ==================================================================
   PAGINATION FIXES - Fix huge pagination arrows
   ================================================================== */
/* Fix huge pagination arrows - apply to all screen sizes */
.pagination .page-item:first-child .page-link,
.pagination .page-item:last-child .page-link {
    min-width: auto !important;
    min-height: auto !important;
    padding: 0.375rem 0.75rem !important;
    font-size: 0.875rem !important;
}

/* Ensure arrow icons/text are reasonable size */
.pagination .page-link i,
.pagination .page-link svg {
    font-size: 0.875rem !important;
    width: 0.875rem !important;
    height: 0.875rem !important;
}

/* Default pagination sizing */
.pagination .page-link {
    min-width: auto;
    min-height: auto;
    padding: 0.375rem 0.75rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==================================================================
   RESPONSIVE LAYOUT - Mobile First Approach
   ================================================================== */

/* Sidebar Base Styles */
#sidebar {
    min-width: 250px;
    max-width: 250px;
    background-color: var(--bs-sidebar-bg, #2c3e50);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 1040; /* Below modals, above content */
}

ul.nav {
    min-width: 180px;
}

/* ==================================================================
   TABLE UTILITIES
   ================================================================== */
.table-responsive {
    overflow-x: auto;
}

.table-responsive > table {
    width: 100%;
}

.table-responsive > table th,
.table-responsive > table td {
    vertical-align: middle;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.card pre,
.card code {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
}

@media (max-width: 575.98px) {
    .table-responsive > table th,
    .table-responsive > table td {
        font-size: 0.85rem;
        padding: 0.5rem 0.25rem;
    }

    .table-responsive > table th {
        white-space: nowrap;
        font-size: 0.75rem;
    }

    .table-responsive .btn-group,
    .table-responsive .btn-group-sm {
        flex-wrap: wrap;
        gap: 0.25rem;
        width: 100%;
    }

    .table-responsive .btn-group .btn,
    .table-responsive .btn-group-sm .btn {
        flex: 1 0 auto;
        min-width: 44px;
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    /* Mobile: Stack table cells vertically for better readability */
    .table-responsive > table {
        display: block;
    }

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

    .table-responsive > table tbody,
    .table-responsive > table tr,
    .table-responsive > table td {
        display: block;
        width: 100%;
    }

    .table-responsive > table tr {
        border: 1px solid var(--bs-border-color);
        margin-bottom: 1rem;
        border-radius: 0.375rem;
        padding: 0.75rem;
        background: var(--bs-card-bg);
    }

    .table-responsive > table td {
        border: none;
        padding: 0.5rem 0;
        text-align: left !important;
    }

    .table-responsive > table td:before {
        content: attr(data-label) ": ";
        font-weight: bold;
        display: inline-block;
        min-width: 100px;
    }

    /* For tables without data-label, use column index */
    .table-responsive > table td:first-child:before {
        content: "";
    }
}

.chart-container {
    position: relative;
    height: 120px;
    width: 100%;
}

/* ==================================================================
   MOBILE RESPONSIVE (< 768px)
   ================================================================== */
@media (max-width: 767.98px) {
    /* Mobile: Sidebar collapses to off-canvas */
    #sidebar {
        position: fixed;
        top: 0;
        left: -250px; /* Hidden by default */
        height: 100vh;
        overflow-y: auto;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }
    
    #sidebar.show {
        left: 0; /* Slide in */
    }
    
    /* Backdrop for mobile sidebar */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1030;
    }
    
    .sidebar-backdrop.show {
        display: block;
    }
    
    /* Mobile: Add hamburger menu button */
    .navbar-mobile-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 8px;
        border: none;
        background: transparent;
        color: inherit;
        cursor: pointer;
        border-radius: 8px;
        transition: background-color 0.2s;
    }
    
    .navbar-mobile-toggle:hover {
        background-color: rgba(255, 255, 255, 0.1);
    }
    
    .navbar-mobile-toggle i {
        font-size: 24px;
    }
    
    /* Mobile: Adjust main content */
    main {
        padding: 1rem !important; /* Smaller padding on mobile */
    }
    
    /* Mobile: Stack cards vertically */
    .row > [class*='col-'] {
        margin-bottom: 1rem;
    }
    
    /* Mobile: Full-width buttons */
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }
    
    .btn-group > .btn {
        width: 100%;
        margin: 0 !important;
    }
    
    /* Mobile: Button groups in headers */
    .d-flex.gap-2 {
        flex-direction: column;
        width: 100%;
    }
    
    .d-flex.gap-2 > .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Mobile: Smaller font sizes */
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }
    
    /* Mobile: Horizontal scroll for wide tables */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
        border-radius: 0.375rem;
    }
    
    /* Mobile: Smaller action buttons in tables */
    .table .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Mobile: Stack form groups */
    .form-row,
    .row.g-3,
    .row.g-4 {
        flex-direction: column;
    }
    
    .row.g-3 > [class*='col-'],
    .row.g-4 > [class*='col-'] {
        width: 100%;
        margin-bottom: 1rem;
    }
    
    /* Mobile: Logo size */
    #sidebar .nav-item img {
        max-width: 100px !important;
    }
    
    /* Mobile: Cards */
    .card {
        margin-bottom: 1rem;
        border-radius: 0.5rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-header {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    /* Mobile: Modals */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }
    
    /* Mobile: Tooltips - disable on very small screens or adjust position */
    [data-bs-toggle="tooltip"] {
        position: relative;
    }
    
    /* Mobile: Disable tooltips on touch devices to prevent overlap issues */
    @media (hover: none) and (pointer: coarse) {
        .tooltip {
            display: none !important;
        }
    }
    
    /* Mobile: Input groups */
    .input-group {
        flex-direction: column;
    }
    
    .input-group > .form-control,
    .input-group > .form-select,
    .input-group > .btn {
        width: 100%;
        border-radius: 0.375rem !important;
        margin-bottom: 0.5rem;
    }
    
    .input-group > .btn:last-child {
        margin-bottom: 0;
    }
    
    /* Mobile: Badges and labels */
    .badge {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
        word-break: break-word;
    }
    
    /* Mobile: Alerts */
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        word-break: break-word;
    }
    
    /* Mobile: Dashboard widgets */
    .col-6.col-md-4.col-lg-2 {
        width: 100%;
        margin-bottom: 1rem;
    }
    
    /* Mobile: Kanban board (Tickets) - already handled in tickets/index.blade.php but ensure */
    .kanban-board {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    .kanban-column {
        min-height: 300px;
    }
    
    /* Mobile: Search forms */
    form.d-flex {
        flex-direction: column;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    form.d-flex > input,
    form.d-flex > button,
    form.d-flex > a {
        width: 100%;
        margin-bottom: 0.5rem;
        margin-right: 0 !important;
    }
    
    /* Mobile: Documentation cards */
    .col-md-4.mb-3,
    .col-md-8 {
        width: 100%;
    }
    
    /* Mobile: Text breaking */
    .text-break,
    .text-nowrap {
        word-break: break-word;
        overflow-wrap: anywhere;
    }
    
    /* Mobile: Code blocks */
    pre,
    code {
        white-space: pre-wrap;
        word-break: break-word;
        overflow-x: auto;
        font-size: 0.85rem;
    }
    
    /* Mobile: Pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .pagination .page-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Note: Pagination arrow fixes are in the general section at top of file */
    
    /* Mobile: Filter forms */
    .card-body form.row {
        margin: 0;
    }
    
    .card-body form.row > [class*='col-'] {
        padding-left: 0;
        padding-right: 0;
        margin-bottom: 1rem;
    }
    
    /* Mobile: Action buttons in table cells */
    td .btn-group {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    
    td .btn-group .btn {
        flex: 0 0 auto;
        min-width: 36px;
    }
    
    /* Mobile: Avatar images */
    .avatar-sm {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    /* Mobile: Breadcrumbs */
    .breadcrumb {
        font-size: 0.85rem;
        flex-wrap: wrap;
    }
    
    .breadcrumb-item {
        word-break: break-word;
    }
}

/* ==================================================================
   TABLET RESPONSIVE (768px - 991.98px)
   ================================================================== */
@media (min-width: 768px) and (max-width: 991.98px) {
    #sidebar {
        min-width: 200px;
        max-width: 200px;
    }
    
    .nav-link {
        font-size: 0.9rem;
    }
    
    .nav-link i {
        font-size: 1rem;
    }
    
    main {
        padding: 2rem !important;
    }
    
    /* Tablet: 2 columns for cards */
    .col-lg-4 {
        width: 50%;
    }
    
    .col-lg-3 {
        width: 50%;
    }
    
    /* Tablet: Better table handling */
    .table-responsive {
        overflow-x: auto;
    }
    
    .table-responsive > table th,
    .table-responsive > table td {
        font-size: 0.9rem;
        padding: 0.75rem 0.5rem;
        word-break: break-word;
    }
    
    /* Tablet: Modals */
    .modal-dialog {
        max-width: 90%;
    }
    
    /* Tablet: Button groups */
    .btn-group {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    
    /* Tablet: Forms */
    .row.g-3 > [class*='col-md-'] {
        margin-bottom: 1rem;
    }
}

/* ==================================================================
   LAPTOP/DESKTOP (992px - 1399.98px)
   ================================================================== */
@media (min-width: 992px) and (max-width: 1399.98px) {
    #sidebar {
        min-width: 230px;
        max-width: 230px;
    }
    
    main {
        padding: 3rem !important;
    }
}

/* ==================================================================
   LARGE DESKTOP (>= 1400px)
   ================================================================== */
@media (min-width: 1400px) {
    #sidebar {
        min-width: 260px;
        max-width: 260px;
    }
    
    main {
        padding: 3rem 4rem !important;
    }
    
    .container-fluid {
        max-width: 1600px;
        margin: 0 auto;
    }
}

/* ==================================================================
   TOUCH DEVICE OPTIMIZATIONS
   ================================================================== */
@media (hover: none) and (pointer: coarse) {
    /* Touch: Larger touch targets */
    .btn {
        min-height: 44px;
        padding: 12px 20px;
    }
    
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom */
    }
    
    .nav-link {
        padding: 12px 16px;
        min-height: 44px;
    }
    
    /* Touch: No hover effects */
    .nav-link:hover {
        background-color: transparent;
    }
    
    .nav-link:active {
        background-color: rgba(52, 73, 94, 0.8);
    }
}

/* ==================================================================
   PRINT STYLES
   ================================================================== */
@media print {
    #sidebar,
    .navbar,
    .btn,
    .floating-help-btn {
        display: none !important;
    }
    
    main {
        padding: 0 !important;
    }
    
    .table {
        font-size: 10pt;
    }
    
    .card {
        border: 1px solid #000;
        break-inside: avoid;
    }
}

/* ==================================================================
   ACCESSIBILITY - REDUCED MOTION
   ================================================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================================================================
   HIGH CONTRAST MODE
   ================================================================== */
@media (prefers-contrast: high) {
    .nav-link {
        border: 2px solid currentColor;
    }
    
    .btn {
        border-width: 2px;
    }
    
    .card {
        border-width: 2px;
    }
}
