/**
 * Responsive Table Styles for Bull Categories
 * Handles mobile view for data tables with horizontal scrolling
 */

/* Table wrapper for horizontal scrolling - use !important to override conflicting styles */
.angus-data-table,
.australian-sires-data-table,
.international-sires-data-table {
    width: 100%;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    position: relative;
    margin-bottom: 20px;
}

/* Override when table is visible - ensure Safari compatibility */
.angus-data-table.visible,
.australian-sires-data-table.visible,
.international-sires-data-table.visible {
    display: block !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch !important;
}

/* Safari-specific fixes for table visibility */
@supports (-webkit-touch-callout: none) {
    .angus-data-table.visible,
    .australian-sires-data-table.visible,
    .international-sires-data-table.visible {
        display: block !important;
        position: relative !important;
        width: 100% !important;
    }
}

/* Ensure tables maintain minimum width for readability */
.angus-table,
.australian-sires-table,
.international-sires-table {
    min-width: 800px; /* Minimum width to prevent cramping */
    width: 100%;
    border-collapse: collapse;
}

/* Sticky first column (Name/Title) for better context while scrolling */
@media (max-width: 768px) {
    .angus-table th.column-title,
    .angus-table td.column-title,
    .australian-sires-table th.column-title,
    .australian-sires-table td.column-title,
    .international-sires-table th.column-title,
    .international-sires-table td.column-title {
        position: sticky;
        left: 0;
        z-index: 10;
        background-color: inherit;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    }
    
    /* Ensure sticky column has proper background */
    .angus-table thead th.column-title {
        background-color: #333;
    }
    
    .angus-table tbody tr:nth-child(odd) td.column-title {
        background-color: #5e6d78;
    }
    
    .angus-table tbody tr:nth-child(even) td.column-title {
        background-color: #4a5761;
    }
    
    .angus-table tbody tr:hover td.column-title {
        background-color: #3a464f;
    }
    
    /* Similar for Australian Sires tables */
    .australian-sires-table thead th.column-title {
        background-color: #003c71;
    }
    
    .australian-sires-table tbody tr:nth-child(odd) td.column-title {
        background-color: #f9f9f9;
    }
    
    .australian-sires-table tbody tr:nth-child(even) td.column-title {
        background-color: #fff;
    }
}

/* Visual scroll indicators - shadows on edges */
.angus-data-table::before,
.angus-data-table::after,
.australian-sires-data-table::before,
.australian-sires-data-table::after,
.international-sires-data-table::before,
.international-sires-data-table::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    z-index: 5;
    display: none;
}

/* Left shadow (shows when scrolled right) */
.angus-data-table::before,
.australian-sires-data-table::before,
.international-sires-data-table::before {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.15), transparent);
}

/* Right shadow (shows when can scroll right) */
.angus-data-table::after,
.australian-sires-data-table::after,
.international-sires-data-table::after {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.15), transparent);
}

/* Show shadows on mobile when scrollable */
@media (max-width: 768px) {
    .angus-data-table.scrollable-left::before,
    .australian-sires-data-table.scrollable-left::before,
    .international-sires-data-table.scrollable-left::before {
        display: block;
    }
    
    .angus-data-table.scrollable-right::after,
    .australian-sires-data-table.scrollable-right::after,
    .international-sires-data-table.scrollable-right::after {
        display: block;
    }
}

/* Scroll hint message for mobile */
.table-scroll-hint {
    display: none;
    text-align: center;
    padding: 10px;
    background: #f0f0f0;
    border-radius: 4px;
    margin-bottom: 10px;
    font-size: 14px;
    color: #666;
}

@media (max-width: 768px) {
    .table-scroll-hint {
        display: block;
    }
}

/* Improve table cell padding on mobile */
@media (max-width: 768px) {
    .angus-table th,
    .angus-table td,
    .australian-sires-table th,
    .australian-sires-table td,
    .international-sires-table th,
    .international-sires-table td {
        padding: 8px 10px;
        white-space: nowrap; /* Prevent text wrapping in cells */
        font-size: 14px;
    }
    
    /* Make action buttons smaller on mobile */
    .angus-table .select-options,
    .australian-sires-table .select-options,
    .international-sires-table .select-options {
        padding: 5px 10px;
        font-size: 12px;
    }
    
    /* Reduce image size in table on mobile */
    .angus-table .column-image img,
    .australian-sires-table .column-image img,
    .international-sires-table .column-image img {
        width: 40px;
        height: 40px;
    }
}

/* Extra small devices */
@media (max-width: 576px) {
    .angus-table,
    .australian-sires-table,
    .international-sires-table {
        font-size: 12px;
    }
    
    .angus-table th,
    .angus-table td,
    .australian-sires-table th,
    .australian-sires-table td,
    .international-sires-table th,
    .international-sires-table td {
        padding: 6px 8px;
    }
    
    /* Ensure wrapper allows scrolling on mobile */
    .angus-data-table,
    .australian-sires-data-table,
    .international-sires-data-table {
        max-width: 100vw !important;
        margin-left: -15px;
        margin-right: -15px;
        padding-left: 15px;
        padding-right: 15px;
    }
}

/* Wrapper for table with fixed indicators */
.table-responsive-wrapper {
    position: relative;
    width: 100%;
    overflow: visible; /* Don't clip the indicators */
}

/* Ensure the scrollable container is properly contained */
.table-responsive-wrapper .angus-data-table,
.table-responsive-wrapper .australian-sires-data-table,
.table-responsive-wrapper .international-sires-data-table {
    position: relative; /* Needed for proper indicator positioning */
}

/* Optional: Add horizontal scroll indicator arrows */
.table-scroll-indicator {
    display: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    background: rgba(22, 65, 112, 0.9);
    color: white;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    z-index: 15;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    pointer-events: all; /* Ensure clickable even over scrollable content */
}

.table-scroll-indicator.left {
    left: 10px;
}

.table-scroll-indicator.right {
    right: 10px;
}

@media (max-width: 768px) {
    .table-scroll-indicator.visible {
        display: flex;
    }
}

/* Ensure table container doesn't cause page overflow */
@media (max-width: 768px) {
    .angus-page-container,
    .australian-sires-page-container,
    .international-sires-page-container {
        overflow-x: hidden;
    }
    
    .angus-main-content,
    .australian-sires-main-content,
    .international-sires-main-content {
        overflow-x: visible;
    }
}