/**
 * WooCommerce Quick Order - Frontend Styles
 * Modern, mobile-friendly styling with semantic CSS classes
 */

/* CSS Variables for easy customization */
:root {
    --tqo-primary-color: #2271b1;
    --tqo-primary-hover: #135e96;
    --tqo-success-color: #00a32a;
    --tqo-border-color: #ddd;
    --tqo-border-radius: 4px;
    --tqo-spacing: 1rem;
    --tqo-spacing-small: 0.5rem;
    --tqo-spacing-large: 1.5rem;
    --tqo-font-size: 14px;
    --tqo-font-size-small: 12px;
    --tqo-font-size-large: 16px;
}

/* Container */
.tqo-container {
    max-width: 100%;
    margin: var(--tqo-spacing) 0;
}

/* Success Message */
.tqo-message {
    padding: var(--tqo-spacing);
    margin-bottom: var(--tqo-spacing);
    border-radius: var(--tqo-border-radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--tqo-spacing-small);
}

.tqo-message--success {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.tqo-message--error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.tqo-message__text {
    flex: 1;
    font-weight: 500;
    font-size: 14px;
}

.tqo-message__button {
    margin-left: auto;
}

/* Search Bar */
.tqo-search {
    margin-bottom: var(--tqo-spacing);
}

.tqo-search__input {
    width: 100%;
    padding: var(--tqo-spacing-small) var(--tqo-spacing);
    font-size: var(--tqo-font-size);
    border: 1px solid var(--tqo-border-color);
    border-radius: var(--tqo-border-radius);
    box-sizing: border-box;
}

.tqo-search__input:focus {
    outline: none;
    border-color: var(--tqo-primary-color);
    box-shadow: 0 0 0 1px var(--tqo-primary-color);
}

/* Filters */
.tqo-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tqo-spacing);
    margin-bottom: var(--tqo-spacing);
    padding: var(--tqo-spacing);
    background-color: #f9f9f9;
    border-radius: var(--tqo-border-radius);
}

.tqo-filter {
    flex: 1;
}

.tqo-filter__label {
    display: block;
    margin-bottom: var(--tqo-spacing-small);
    font-weight: 500;
    font-size: var(--tqo-font-size-small);
    color: #333;
}

.tqo-filter__select {
    width: 100%;
    padding: var(--tqo-spacing-small);
    font-size: var(--tqo-font-size);
    border: 1px solid var(--tqo-border-color);
    border-radius: var(--tqo-border-radius);
    background-color: #fff;
    box-sizing: border-box;
}

.tqo-filter__select:focus {
    outline: none;
    box-shadow: 0 0 0 1px var(--tqo-primary-color);
}

.tqo-filter--price {
    display: flex;
    flex-direction: column;
}

.tqo-filter__price-inputs {
    display: flex;
    align-items: center;
    gap: var(--tqo-spacing-small);
}

.tqo-filter__price-input {
    flex: 1;
    padding: var(--tqo-spacing-small);
    font-size: var(--tqo-font-size);
    border: 1px solid var(--tqo-border-color);
    border-radius: var(--tqo-border-radius);
    box-sizing: border-box;
}

.tqo-filter__price-input:focus {
    outline: none;
    border-color: var(--tqo-primary-color);
    box-shadow: 0 0 0 1px var(--tqo-primary-color);
}

.tqo-filter__price-separator {
    padding: 0 var(--tqo-spacing-small);
    color: #666;
}

/* Price Slider Styles */
.tqo-filter--price-slider {
    display: flex;
    flex-direction: column;
}

.tqo-filter__price-slider-wrapper {
    width: 100%;
}

.tqo-filter__price-slider {
    margin: var(--tqo-spacing-small) 0;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    position: relative;
}

/* jQuery UI Slider Base Styles */
.tqo-filter__price-slider.ui-slider {
    position: relative;
    background: #e0e0e0;
    border-radius: 3px;
    height: 6px;
    margin: var(--tqo-spacing-small) 10px; /* Add horizontal margin to accommodate handles */
    width: calc(100% - 20px); /* Subtract margin from width */
    box-sizing: border-box;
}

.tqo-filter__price-slider.ui-slider .ui-slider-range {
    position: absolute;
    background: var(--tqo-primary-color);
    height: 100%;
    border-radius: 3px;
    top: 0;
}

.tqo-filter__price-slider.ui-slider .ui-slider-handle {
    position: absolute;
    width: 18px;
    height: 18px;
    background: #fff;
    border: 2px solid var(--tqo-primary-color);
    border-radius: 50%;
    cursor: pointer;
    outline: none;
    top: -6px;
    margin-left: -9px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    /* No transition on position - handle should follow immediately */
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.tqo-filter__price-slider.ui-slider .ui-slider-handle:hover,
.tqo-filter__price-slider.ui-slider .ui-slider-handle:focus {
    border-color: var(--tqo-primary-hover);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    transform: scale(1.1);
}

.tqo-filter__price-slider.ui-slider .ui-slider-handle.ui-state-active {
    border-color: var(--tqo-primary-hover);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.tqo-filter__price-slider-amount {
    margin-top: var(--tqo-spacing-small);
}

.tqo-filter__price-slider-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--tqo-spacing-small);
    font-size: var(--tqo-font-size-small);
    color: #666;
}

.tqo-filter__price-slider-label {
    font-weight: 500;
    color: #333;
}

.tqo-filter__price-slider-label--min {
    text-align: left;
}

.tqo-filter__price-slider-label--max {
    text-align: right;
}

/* Table */
.tqo-table-wrapper {
    overflow-x: auto;
    margin-bottom: var(--tqo-spacing);
    position: relative;
}

.tqo-table {
    width: 100%;
    border-collapse: collapse;
    background-color: #fff;
    border: 1px solid var(--tqo-border-color);
    border-radius: var(--tqo-border-radius);
    overflow: hidden;
}

.tqo-table__head {
    background-color: #f5f5f5;
}

.tqo-table__header {
    padding: var(--tqo-spacing);
    text-align: left;
    font-weight: 600;
    font-size: var(--tqo-font-size-small);
    text-transform: uppercase;
    color: #333;
    border-bottom: 2px solid var(--tqo-border-color);
    cursor: pointer;
    user-select: none;
    position: relative;
    white-space: nowrap;
}

.tqo-table__header[data-sort]:hover {
    background-color: #e9e9e9;
}

.tqo-table__sort-indicator {
    display: inline-block;
    margin-left: var(--tqo-spacing-small);
    opacity: 0.5;
    font-size: 10px;
}

.tqo-table__header[data-sort="title"].tqo-table__header--sorted-asc .tqo-table__sort-indicator::after,
.tqo-table__header[data-sort="sku"].tqo-table__header--sorted-asc .tqo-table__sort-indicator::after,
.tqo-table__header[data-sort="price"].tqo-table__header--sorted-asc .tqo-table__sort-indicator::after,
.tqo-table__header[data-sort="stock"].tqo-table__header--sorted-asc .tqo-table__sort-indicator::after {
    content: ' ▲';
    opacity: 1;
}

.tqo-table__header[data-sort="title"].tqo-table__header--sorted-desc .tqo-table__sort-indicator::after,
.tqo-table__header[data-sort="sku"].tqo-table__header--sorted-desc .tqo-table__sort-indicator::after,
.tqo-table__header[data-sort="price"].tqo-table__header--sorted-desc .tqo-table__sort-indicator::after,
.tqo-table__header[data-sort="stock"].tqo-table__header--sorted-desc .tqo-table__sort-indicator::after {
    content: ' ▼';
    opacity: 1;
}

.tqo-table__row {
    border-bottom: 1px solid var(--tqo-border-color);
}

.tqo-table__row:last-child {
    border-bottom: none;
}

.tqo-table__row:hover {
    background-color: #f9f9f9;
}

.tqo-table__cell {
    padding: var(--tqo-spacing);
    vertical-align: middle;
    font-size: var(--tqo-font-size);
}

/* Column Alignment - Higher specificity to override any default styles */
.tqo-table__header--align-left,
.tqo-table__cell--align-left,
.tqo-table__cell.tqo-table__cell--align-left {
    text-align: left;
}

.tqo-table__header--align-center,
.tqo-table__cell--align-center,
.tqo-table__cell.tqo-table__cell--align-center {
    text-align: center;
}

.tqo-table__header--align-right,
.tqo-table__cell--align-right,
.tqo-table__cell.tqo-table__cell--align-right {
    text-align: right;
}

/* Ensure alignment works for all column types */
.tqo-table__cell.tqo-table__cell--name.tqo-table__cell--align-right,
.tqo-table__cell.tqo-table__cell--sku.tqo-table__cell--align-right,
.tqo-table__cell.tqo-table__cell--stock.tqo-table__cell--align-right,
.tqo-table__cell.tqo-table__cell--price.tqo-table__cell--align-right,
.tqo-table__cell.tqo-table__cell--quantity.tqo-table__cell--align-right {
    text-align: right;
}

.tqo-table__cell.tqo-table__cell--name.tqo-table__cell--align-center,
.tqo-table__cell.tqo-table__cell--sku.tqo-table__cell--align-center,
.tqo-table__cell.tqo-table__cell--stock.tqo-table__cell--align-center,
.tqo-table__cell.tqo-table__cell--price.tqo-table__cell--align-center,
.tqo-table__cell.tqo-table__cell--quantity.tqo-table__cell--align-center {
    text-align: center;
}

.tqo-table__cell--empty {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: var(--tqo-spacing-large);
}

.tqo-table__image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--tqo-border-radius);
    border: 1px solid var(--tqo-border-color);
}

/* Lightbox-enabled images */
.tqo-image--lightbox {
    display: inline-block;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.tqo-image--lightbox:hover {
    opacity: 0.8;
}

.tqo-image--lightbox:focus {
    outline: 2px solid var(--tqo-primary-color, #0073aa);
    outline-offset: 2px;
}

.tqo-image--lightbox .tqo-table__image {
    transition: transform 0.2s ease;
}

.tqo-image--lightbox:hover .tqo-table__image {
    transform: scale(1.05);
}

/* Price Display - Using WooCommerce's default price structure */
.tqo-table__cell--price .price {
    display: inline-block;
}

.tqo-table__cell--price .price del {
    color: #999;
    text-decoration: line-through;
    margin-right: var(--tqo-spacing-small);
    font-size: var(--tqo-font-size-small);
}

.tqo-table__cell--price .price ins {
    color: var(--tqo-success-color);
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
}

/* Quantity Controls */
.tqo-quantity {
    display: flex;
    align-items: center;
    gap: 0;
}
.tqo-quantity button{
    outline: none;
}

/* Align quantity controls based on column alignment */
.tqo-table__cell--align-right .tqo-quantity {
    justify-content: flex-end;
}

.tqo-table__cell--align-center .tqo-quantity {
    justify-content: center;
}

.tqo-table__cell--align-left .tqo-quantity {
    justify-content: flex-start;
}

.tqo-quantity__button {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--tqo-border-color);
    background-color: #fff;
    cursor: pointer;
    font-size: var(--tqo-font-size-large);
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.tqo-quantity__button:hover:not(:disabled) {
    background-color: #f5f5f5;
}

.tqo-quantity__button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tqo-quantity__button--minus {
    border-radius: var(--tqo-border-radius) 0 0 var(--tqo-border-radius);
    border-right: none;
}

.tqo-quantity__button--plus {
    border-radius: 0;
    border-left: none;
}

/* When MAX button is not present, add right border-radius to plus button */
.tqo-quantity__button--plus:last-child {
    border-radius: 0 var(--tqo-border-radius) var(--tqo-border-radius) 0;
}

.tqo-quantity__input {
    width: 60px;
    height: 32px;
    padding: 0 var(--tqo-spacing-small);
    text-align: center;
    border: 1px solid var(--tqo-border-color);
    border-left: none;
    border-right: none;
    font-size: var(--tqo-font-size);
    box-sizing: border-box;
    -moz-appearance: textfield;
}

.tqo-quantity__input::-webkit-outer-spin-button,
.tqo-quantity__input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.tqo-quantity__input:focus {
    outline: none;
}

.tqo-quantity__button--max {
    margin-left: 0;
    padding: 0 var(--tqo-spacing-small);
    font-size: var(--tqo-font-size-small);
    font-weight: 600;
    background-color: #fff;
    color: #333;
    border-left: none;
    border-radius: 0 var(--tqo-border-radius) var(--tqo-border-radius) 0;
    width: auto;
    min-width: 45px;
}

.tqo-quantity__button--max:hover:not(:disabled) {
    background-color: #f5f5f5;
}

/* Buttons */
.tqo-button {
    padding: var(--tqo-spacing-small) var(--tqo-spacing);
    font-size: var(--tqo-font-size);
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--tqo-border-radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.tqo-button--primary {
    background-color: var(--tqo-primary-color);
    color: #fff;
    border-color: var(--tqo-primary-color);
}

.tqo-button--primary:hover:not(:disabled) {
    background-color: var(--tqo-primary-hover);
    border-color: var(--tqo-primary-hover);
}

.tqo-button--add-to-cart {
    background-color: var(--tqo-success-color);
    color: #fff;
    border-color: var(--tqo-success-color);
}

.tqo-button--add-to-cart:hover:not(:disabled) {
    background-color: #008a20;
    border-color: #008a20;
}

.tqo-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tqo-button--bulk-add {
    width: 100%;
    padding: var(--tqo-spacing);
    font-size: var(--tqo-font-size-large);
}

/* Pagination */
.tqo-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--tqo-spacing);
    margin: var(--tqo-spacing-large) 0;
}

.tqo-pagination__button {
    padding: var(--tqo-spacing-small) var(--tqo-spacing);
    font-size: var(--tqo-font-size);
    border: 1px solid var(--tqo-border-color);
    background-color: #fff;
    border-radius: var(--tqo-border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.tqo-pagination__button:hover:not(:disabled) {
    background-color: #f5f5f5;
}

.tqo-pagination__button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tqo-pagination__info {
    font-size: var(--tqo-font-size);
    color: #666;
}

/* Bulk Actions */
.tqo-bulk-actions {
    margin-top: var(--tqo-spacing-large);
    padding-top: var(--tqo-spacing-large);
    border-top: 1px solid var(--tqo-border-color);
}

/* Loading State */
.tqo-loading {
    text-align: center;
    padding: var(--tqo-spacing-large);
    color: #666;
}

.tqo-loading__spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--tqo-primary-color);
    border-radius: 50%;
    animation: tqo-spin 1s linear infinite;
    margin-right: var(--tqo-spacing-small);
    vertical-align: middle;
}

@keyframes tqo-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .tqo-filters {
        flex-direction: column;
    }

    .tqo-filter {
        min-width: 100%;
    }

    .tqo-filter__price-slider.ui-slider {
        margin: var(--tqo-spacing-small) 12px; /* More margin on mobile for larger handles */
        width: calc(100% - 24px); /* Subtract margin from width */
    }

    .tqo-filter__price-slider.ui-slider .ui-slider-handle {
        width: 20px;
        height: 20px;
        margin-left: -10px;
        top: -7px;
    }

    .tqo-table-wrapper {
        overflow-x: scroll;
        -webkit-overflow-scrolling: touch;
    }

    .tqo-table {
        min-width: 600px;
    }

    .tqo-table__cell {
        padding: var(--tqo-spacing-small);
        font-size: var(--tqo-font-size-small);
    }

    .tqo-table__image {
        width: 40px;
        height: 40px;
    }

    .tqo-quantity__input {
        width: 50px;
    }

    .tqo-button {
        padding: var(--tqo-spacing-small);
        font-size: var(--tqo-font-size-small);
    }

    .tqo-pagination {
        flex-wrap: wrap;
    }

    .tqo-message {
        flex-direction: column;
        align-items: flex-start;
    }

    .tqo-message__button {
        margin-left: 0;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .tqo-container {
        margin: var(--tqo-spacing-small) 0;
    }

    .tqo-table__header {
        padding: var(--tqo-spacing-small);
        font-size: 11px;
    }

    .tqo-table__cell {
        padding: var(--tqo-spacing-small);
    }
}

