/* View Toggle Buttons */
.view-toggle-buttons {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

/* DataTables search host (visible for both list & grid) */
.items-search-host {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin: 0 0 10px 0;
}

.items-search-host .dataTables_filter {
    float: none;
    text-align: right;
    margin: 0;
}

.items-search-host .dataTables_filter label {
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.items-search-host .dataTables_filter input {
    margin: 0;
}

.items-search-host #SearchButton {
    margin-left: 6px;
}

/* DataTables length menu (inline display) */
#items-length-host .dataTables_length {
    float: none;
    margin: 0;
}

#items-length-host .dataTables_length label {
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

#items-length-host .dataTables_length select {
    width: auto;
    display: inline-block;
    margin: 0 5px;
}

/* Pagination controls styling */
#items-pagination-host {
    margin-top: 15px;
}

#items-info-host .dataTables_info {
    padding-top: 8px;
    font-weight: 600;
}

#items-paging-host .dataTables_paginate {
    float: none;
    margin: 0;
}

/* Price sort dropdown styling */
#price-sort {
    margin: 10px 0 0 0;
}

.view-toggle-buttons .btn {
    padding: 8px 15px;
    border: 1px solid #ddd;
    background-color: #fff;
    color: #666;
    transition: all 0.3s ease;
}

.view-toggle-buttons .btn:hover {
    background-color: #f5f5f5;
    border-color: #794FB4;
    color: #794FB4;
}

.view-toggle-buttons .btn.active {
    background-color: #794FB4;
    color: #fff;
    border-color: #794FB4;
}

.view-toggle-buttons .btn i {
    margin-right: 5px;
}

/* Grid View Styles */
#items-grid-view {
    display: none;
    margin-top: 20px;
}

.grid-container {
    margin: 0 -10px;
    display: flex;
    flex-wrap: wrap;
}

/* Ignore bootstrap column floats in grid view; flex handles layout */
.grid-item {
    float: none !important;
    padding: 10px;
    margin-bottom: 20px;
    display: flex;
    flex: 0 0 25%;
    max-width: 25%;
}

.grid-card {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.grid-card:hover {
    box-shadow: 0 4px 16px rgba(124, 50, 255, 0.2);
    transform: translateY(-5px);
}

.grid-image-link {
    display: block;
    position: relative;
    padding-top: 75%; /* 4:3 aspect ratio */
    background: #f5f5f5;
    overflow: hidden;
}

.grid-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.grid-card:hover .grid-image {
    transform: scale(1.05);
}

.grid-content {
    padding: 15px;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

/* Fixed text heights to keep every tile the same height (prevents misaligned rows) */
.grid-title {
    font-size: 1.1em;
    margin: 0 0 10px 0;
    font-weight: 600;
    line-height: 1.3em;
    height: 2.6em; /* 2 lines */
    overflow: hidden;
}

.grid-title a {
    color: #333;
    text-decoration: none;
}

.grid-title a:hover {
    color: #794FB4;
}

.grid-qty {
    color: #666;
    font-size: 0.9em;
    margin: 5px 0;
    height: 1.8em; /* 1 line */
    overflow: hidden;
}

.grid-description {
    color: #555;
    font-size: 0.85em;
    line-height: 1.4em;
    margin: 8px 0;
    word-wrap: break-word;
    flex-grow: 1;
}

/* Use line-clamp where supported for title only */
@supports (-webkit-line-clamp: 1) {
    .grid-title {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
}

.grid-price {
    margin: 10px 0 15px 0;
    font-size: 1.2em;
    color: #794FB4;
    font-weight: bold;
    line-height: 1.2em;
    height: auto;
    min-height: 2.4em;
    overflow: visible;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
}

.grid-price span[style*="line-through"] {
    font-size: 0.6em;
    margin: 0;
}

.grid-buttons {
    display: flex;
    gap: 8px;
    margin-top: auto;
    width: 100%;
}

.grid-view-btn {
    flex: 1;
    padding: 8px 15px;
    background-color: transparent;
    color: #333;
    border: 1px solid #ddd;
}

.grid-view-btn:hover {
    background-color: #794FB4;
    color: #fff;
    border-color: #794FB4;
}

.grid-add-cart-icon {
    padding: 8px 12px;
    background-color: #794FB4;
    color: #fff;
    border: 1px solid #794FB4;
}

.grid-add-cart-icon:hover {
    background-color: #5a3a85;
    border-color: #5a3a85;
    color: #fff;
}

/* List View Styles */
#items-list-view {
    display: block;
}

/* Make list view visually closer to grid cards (scoped to itemslist only) */
#items-list-view #itemslist {
    background: transparent;
    border-collapse: separate;
    border-spacing: 0 12px; /* space between “card rows” */
}

/* Only links look clickable (override global #itemslist tr:hover { cursor:pointer } in style.css) */
/* style.css sets #itemslist tr:hover { cursor:pointer } which also hits nested inner-table rows.
   Force a neutral cursor everywhere, then opt-in pointer only on the image/title links. */
#items-list-view #itemslist tr,
#items-list-view #itemslist tr:hover,
#items-list-view #itemslist td,
#items-list-view #itemslist td:hover {
    cursor: default !important;
}

#items-list-view #itemslist a {
    cursor: default;
}

#items-list-view #itemslist > tbody > tr > td:first-child a,
#items-list-view #itemslist > tbody > tr > td:nth-child(2) strong a,
#items-list-view #itemslist > tbody > tr > td:first-child a:hover,
#items-list-view #itemslist > tbody > tr > td:nth-child(2) strong a:hover {
    cursor: pointer;
}

#items-list-view #itemslist thead {
    background-color: #6D6D6D;
    color: #FFFFFF;
}

#items-list-view #itemslist thead th:first-child {
    border-top-left-radius: 8px;
}

#items-list-view #itemslist thead th:last-child {
    border-top-right-radius: 8px;
}

/* Remove bootstrap striping (we want consistent card backgrounds) */
#items-list-view #itemslist.table-striped > tbody > tr:nth-of-type(odd),
#items-list-view #itemslist.table-striped > tbody > tr:nth-of-type(even) {
    background-color: transparent;
}

#items-list-view #itemslist.table > tbody > tr > td {
    background: #fff;
    border-top: none;
    padding: 14px 16px;
}

/* Image column should touch the card edges */
#items-list-view #itemslist.table > tbody > tr > td:first-child {
    padding: 0;
    overflow: hidden; /* clip image zoom to rounded left edge */
}

/* Content column should expand vertically as needed */
#items-list-view #itemslist.table > tbody > tr > td:nth-child(2) {
    vertical-align: top;
    overflow: visible;
    height: auto;
    padding: 8px 5px 8px 10px;
    width: 60%;
}

/* Nested tables inside content column should expand freely */
#items-list-view #itemslist.table > tbody > tr > td:nth-child(2) table {
    height: auto;
}

#items-list-view #itemslist.table > tbody > tr > td:nth-child(2) table td {
    overflow: visible;
    height: auto;
}

/* Remove bootstrap table-hover background highlight (keep only shadow hover) */
#items-list-view #itemslist.table-hover > tbody > tr:hover > td {
    background-color: #fff;
}

#items-list-view #itemslist > tbody > tr {
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    overflow: hidden;
    -webkit-box-shadow: 0 2px 8px rgba(0,0,0,0.10);
    box-shadow: 0 2px 8px rgba(0,0,0,0.10);
    transition: all 0.3s ease;
    position: relative;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

#items-list-view #itemslist > tbody > tr:hover {
    border-color: #794FB4;
    -webkit-box-shadow: 0 6px 20px rgba(121, 79, 180, 0.20);
    box-shadow: 0 6px 20px rgba(121, 79, 180, 0.20);
    -webkit-transform: translateY(-2px) scale(1.005);
    transform: translateY(-2px) scale(1.005);
}

/* Rounded corners for the “card row” */
#items-list-view #itemslist > tbody > tr > td:first-child {
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

#items-list-view #itemslist > tbody > tr > td:last-child {
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
}

/* Match grid link behavior */
#items-list-view #itemslist a {
    color: #333;
    text-decoration: none;
}

#items-list-view #itemslist a:hover {
    color: #794FB4;
    text-decoration: none;
}

/* Make list images feel like grid thumbnails */
#items-list-view #itemslist img {
    background: #fff;
    display: block;
    width: 100% !important;
    height: 100%;
    object-fit: contain;
    object-position: center;
    transition: transform 0.3s ease;
}

/* Let the image column breathe a bit more */
#items-list-view #itemslist > tbody > tr > td:first-child {
    width: 25%;
}

/* Use the anchor as the “image frame” so zoom doesn't spill */
#items-list-view #itemslist > tbody > tr > td:first-child a {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 10px 0 0 10px;
    background: #fff;
    min-height: 200px;
}

/* Hide mobile price row on desktop */
#items-list-view #itemslist tr.sm-price-row {
    display: none;
}

#items-list-view #itemslist > tbody > tr > td:first-child img {
    border-radius: 10px 0 0 10px;
}

/* Grid-like hover zoom on the image only */
#items-list-view #itemslist > tbody > tr > td:first-child a:hover img {
    transform: scale(1.05);
}

/* List text truncation + height locking (keeps list cards aligned) */
#items-list-view #itemslist .list-desc {
    color: #555;
    line-height: 1.4em;
    margin: 8px 0 0;
    height: auto;
}

/* Hide mobile view details button on desktop */
#items-list-view #itemslist tr.sm-details-row {
    display: none;
}

/* Note: do NOT use -webkit-line-clamp here because list content can contain <br> formatting.
   Height + overflow does the truncation while preserving manual line breaks. */

/* Responsive Adjustments */
@media (max-width: 992px) {
    .grid-item {
        flex: 0 0 33.333%;
        max-width: 33.333%;
    }

    .grid-title {
        font-size: 1em;
    }
    
    /* Adjust image container for tablets */
    #items-list-view #itemslist > tbody > tr > td:first-child a {
        min-height: 180px;
    }
}

@media (max-width: 768px) {
    .grid-item {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .view-toggle-buttons {
        justify-content: center;
    }

    .view-toggle-buttons .btn {
        font-size: 0.9em;
        padding: 6px 10px;
    }

    .grid-content {
        padding: 12px;
    }

    .items-search-host {
        justify-content: center;
    }

    .items-search-host .dataTables_filter {
        text-align: center;
    }

    .items-search-host .dataTables_filter label {
        justify-content: center;
    }

    /* 2-column layout for mobile - hide desktop price column */
    #items-list-view #itemslist > tbody > tr > td.dt-price-col {
        display: none !important;
    }
    
    /* Show mobile price row */
    #items-list-view #itemslist tr.sm-price-row {
        display: table-row !important;
    }
    
    #items-list-view #itemslist td.sm-price {
        padding-top: 8px;
        margin-top: 8px;
    }

    /* Add strong visible borders for list view items on mobile iOS */
    #items-list-view #itemslist > tbody > tr {
        background: #fff !important;
        border: 1px solid #e5e5e5 !important;
        outline: 1px solid #f0f0f0 !important;
        border-radius: 10px !important;
        overflow: hidden !important;
        -webkit-box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
        -webkit-transform: translateZ(0) !important;
        transform: translateZ(0) !important;
        margin-bottom: 15px;
        transition: all 0.3s ease !important;
    }
    
    #items-list-view #itemslist > tbody > tr:hover {
        border: 1px solid #794FB4 !important;
        outline: 1px solid #b89dd9 !important;
        -webkit-box-shadow: 0 4px 12px rgba(121, 79, 180, 0.25) !important;
        box-shadow: 0 4px 12px rgba(121, 79, 180, 0.25) !important;
        -webkit-transform: translateY(-2px) !important;
        transform: translateY(-2px) !important;
    }
    
    /* Adjust image container for mobile */
    #items-list-view #itemslist > tbody > tr > td:first-child a {
        min-height: 150px;
    }
    
    /* Make images fill height and crop sides on mobile */
    #items-list-view #itemslist > tbody > tr > td:first-child img {
        object-fit: cover;
        height: 100%;
        width: 100%;
    }

    /* Show full list description on mobile (no truncation) */
    #items-list-view #itemslist .list-desc {
        margin-bottom: 8px;
    }
    
    /* Show mobile view details button and style it */
    #items-list-view #itemslist tr.sm-details-row {
        display: table-row !important;
    }
    
    #items-list-view #itemslist .sm-details-btn,
    #items-list-view #itemslist .sm-cart-btn {
        padding: 8px 15px;
        margin-top: 8px;
        background-color: transparent;
        color: #333;
        border: 1px solid #ddd;
    }
    
    #items-list-view #itemslist .sm-details-btn:hover,
    #items-list-view #itemslist .sm-cart-btn:hover {
        background-color: #794FB4;
        color: #fff;
        border-color: #794FB4;
    }
    
    /* Desktop add to cart button in price column */
    #items-list-view #itemslist .dt-cart-btn {
        background-color: transparent;
        color: #333;
        border: 1px solid #ddd;
    }
    
    #items-list-view #itemslist .dt-cart-btn:hover {
        background-color: #794FB4;
        color: #fff;
        border-color: #794FB4;
    }

    /* Stack sort and pagination controls vertically and center them */
    div[style*="display: flex"][style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: center !important;
    }

    #items-length-host,
    #price-sort-container {
        display: flex !important;
        justify-content: center !important;
        width: 100% !important;
        margin: 8px auto !important;
        visibility: visible !important;
        opacity: 1 !important;
        -webkit-appearance: none;
    }

    #price-sort-container {
        order: -1; /* Put sort on top */
    }

    #items-length-host .dataTables_length,
    #price-sort-container {
        text-align: center;
        width: 100%;
    }

    #items-length-host .dataTables_length label {
        justify-content: center;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    #price-sort {
        width: 100% !important;
        max-width: 280px;
        margin: 0 auto;
        -webkit-appearance: menulist;
        appearance: menulist;
        display: block !important;
        visibility: visible !important;
    }

    #items-length-host .dataTables_length select {
        margin: 0 5px;
    }
}

@media (max-width: 576px) {
    .grid-item {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .grid-content {
        padding: 10px;
    }

    .grid-title {
        font-size: 0.95em;
    }

    .grid-description {
        font-size: 0.82em;
    }

    .grid-view-btn {
        padding: 6px 10px;
        font-size: 0.88em;
    }
    
    .grid-add-cart-icon {
        padding: 6px 10px;
    }

    .items-search-host {
        justify-content: center;
    }

    .items-search-host .dataTables_filter {
        width: 100%;
        text-align: center;
    }

    .items-search-host .dataTables_filter label {
        width: 100%;
        justify-content: center;
        flex-wrap: nowrap;
    }

    .items-search-host .dataTables_filter input.form-control {
        width: 60vw;
        max-width: 260px;
        min-width: 150px;
    }

    /* Stack length and sort controls vertically on small screens */
    #items-length-host,
    #price-sort-container {
        width: 100%;
        margin: 8px 0;
    }

    #price-sort {
        width: 100% !important;
        max-width: 220px;
    }

    /* Center pagination controls */
    #items-pagination-host {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    #items-info-host,
    #items-paging-host {
        text-align: center;
    }
}

@media (max-width: 480px) {
    .view-toggle-buttons .btn i {
        margin-right: 3px;
    }

    .grid-item {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .grid-content {
        padding: 9px;
    }

    .grid-view-btn {
        padding: 6px 8px;
        font-size: 0.86em;
    }
    
    .grid-add-cart-icon {
        padding: 6px 8px;
    }
    
    /* Smaller image container for small phones */
    #items-list-view #itemslist > tbody > tr > td:first-child a {
        min-height: 120px;
    }
    
    /* Make images fill height and crop sides on small phones */
    #items-list-view #itemslist > tbody > tr > td:first-child img {
        object-fit: cover;
        height: 100%;
        width: 100%;
    }
}

/* iOS-specific fixes for shadow rendering */
@supports (-webkit-overflow-scrolling: touch) {
    #items-list-view #itemslist > tbody > tr {
        background: #fff !important;
        border: 1px solid #e5e5e5 !important;
        border-radius: 10px !important;
        overflow: hidden !important;
        -webkit-box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Ensure sort dropdown is visible on iOS */
    #price-sort-container,
    #price-sort {
        display: block !important;
        visibility: visible !important;
        -webkit-appearance: menulist;
        opacity: 1 !important;
    }
}

/* Additional iOS Safari specific fixes */
@media screen and (max-width: 1024px) {
    select#price-sort {
        display: block !important;
        visibility: visible !important;
        height: 34px !important;
        -webkit-appearance: menulist-button !important;
    }
    
    #price-sort-container {
        display: flex !important;
        visibility: visible !important;
        min-height: 50px;
    }
}
