/**
 * RankUp B2B Frontend Styles
 */

/* Sticky Table Header */
.b2b-table thead,
.wp-list-table thead,
table.widefat thead,
table.striped thead {
    position: sticky;
    top: 0;
    /* z-index: 10; */
    /* background: #131e25; */
    /* Dark background matching current design */
    /* color: #fff; */
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.2);
    padding: 10px;
    /* Ensure padding is present */
}

/* Ensure table has relative positioning context if needed */
.b2b-table,
.wp-list-table {
    border-collapse: collapse;
}

/* Sticky header fix for admin bar if present */
body.admin-bar .b2b-table thead th,
body.admin-bar .wp-list-table thead th {
    top: 32px;
}

@media screen and (max-width: 782px) {

    body.admin-bar .b2b-table thead th,
    body.admin-bar .wp-list-table thead th {
        top: 46px;
    }
}

/* ==========================================================================
   Product Table Layout (Migrated from product-table.php)
   ========================================================================== */
.rankup-b2b-frontend-page {
    max-width: 1400px;
    margin: 0 auto;
}

.rankup-admin-grid {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 20px;
    margin-top: 20px;
    align-items: stretch;
    /* Ensure columns are equal height */
}

.rankup-admin-main {
    min-width: 0;
}

.rankup-admin-section {
    background: #fff;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #ccd0d4;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
}

/* Force height for testing scrolling behavior per request */
.rankup-admin-main .rankup-admin-section:last-child {
    /* min-height: 2000px; */
}

.rankup-admin-section h2 {
    margin-top: 0;
    font-size: 18px;
    font-weight: 600;
}

.category-tabs {
    border-bottom: 1px solid #ccd0d4;
    margin-bottom: 15px;
}

.tab-button {
    background: none;
    border: none;
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab-button.active {
    border-bottom-color: #2271b1;
    color: #2271b1;
    font-weight: 600;
}

.product-table-container {
    max-height: 1200px;
    /* Increased height per user request */
    overflow-y: auto;
}

.product-row.selected {
    background: #f0f6fc;
}

.product-qty {
    width: 60px;
}

.rankup-admin-sidebar {
    position: relative;
    /* Context */
    /* height: 100%; - Removed to let grid handle stretch */
}

.order-preview-box {
    background: #fff;
    padding: 20px;
    border: 1px solid #ccd0d4;
    position: -webkit-sticky;
    /* Safari support */
    position: sticky;
    top: 100px;
    /* Offset from top */
    z-index: 90;
    width: 100%;
    /* Ensure full width of sidebar */
    height: fit-content;
    /* Critical: element must be shorter than container */
    max-height: 80vh;
    /* Prevent it from being taller than viewport */
    overflow-y: auto;
    /* Scroll internal content if too tall */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    /* Better visibility */
}

.order-preview-box h3 {
    margin-top: 0;
}

#order-preview-content {
    min-height: 200px;
    margin-bottom: 15px;
}

.preview-items {
    margin-bottom: 15px;
}

.preview-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.item-name {
    flex: 1;
    font-weight: 500;
}

.item-qty {
    margin: 0 10px;
    color: #666;
}

.preview-totals {
    border-top: 2px solid #ccd0d4;
    padding-top: 10px;
    margin-top: 10px;
}

.total-line {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
}

.total-line.grand {
    font-weight: 700;
    font-size: 16px;
    color: #2271b1;
    border-top: 1px solid #eee;
    padding-top: 10px;
    margin-top: 5px;
}

.preview-actions button {
    width: 100%;
    margin-bottom: 10px;
}

.no-items {
    color: #888;
    text-align: center;
    padding: 40px 0;
}

/* Mobile responsive */
@media (max-width: 1024px) {
    .rankup-admin-grid {
        grid-template-columns: 1fr;
    }

    .rankup-admin-sidebar {
        order: -1;
    }

    .order-preview-box {
        position: relative;
        top: 0;
    }
}

/* ==========================================================================
   Category Filter Dropdown (New)
   ========================================================================== */
.category-filter-container {
    position: relative;
    /* margin-bottom: 20px; */
    display: inline-block;
}

.category-filter-btn {
    background: #fff !important;
    border: 1px solid #ccd0d4 !important;
    color: #3c434a !important;
    padding: 10px 15px !important;
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
}

.category-filter-btn:hover {
    background: #f0f0f1 !important;
    border-color: #8c8f94 !important;
    color: #2271b1 !important;
}

.category-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 5px;
    width: 320px;
    background: #fff;
    border: 1px solid #ccd0d4;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
    overflow: hidden;
    /* For swipe effect */
}

.category-dropdown.open {
    display: block;
}

.dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    background: #f9f9f9;
}

.dropdown-header .header-title {
    font-weight: 600;
    font-size: 14px;
    flex: 1;
    text-align: center;
}

.dropdown-header .back-btn {
    background: none;
    border: none;
    padding: 0;
    color: #2271b1;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.dropdown-header .close-dropdown-btn {
    background: none;
    border: none;
    padding: 0;
    color: #666;
    cursor: pointer;
}

.dropdown-content-wrapper {
    position: relative;
    width: 200%;
    /* Two panels wide */
    height: 350px;
    /* Fixed height */
    display: flex;
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    transform: translateX(0);
}

.dropdown-slide {
    width: 50%;
    /* Each panel takes half of 200% width = 100% of container */
    height: 100%;
    overflow-y: auto;
    padding: 10px 0;
    box-sizing: border-box;
    flex-shrink: 0;
}

/* Category Items */
.cat-item {
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background 0.1s;
    font-size: 14px;
    border-bottom: 1px solid #f5f5f5;
    color: #3c434a;
    background: none;
    width: 100%;
    text-align: left;
    border-top: none;
    border-left: none;
    border-right: none;
}

.cat-item:last-child {
    border-bottom: none;
}

.cat-item:hover {
    background: #f0f6fc;
    color: #2271b1;
}

.cat-item .cat-name {
    flex: 1;
}

.cat-item .cat-arrow {
    background: none;
    border: none;
    color: #ccc;
    font-size: 18px;
    padding: 0;
    margin-left: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    height: 30px;
    margin: -15px;
    aspect-ratio: 1;
}

.cat-item:hover .cat-arrow {
    color: #2271b1;
}

/* Selected State */
.cat-item.selected {
    font-weight: 600;
    color: #2271b1;
    background: #f0f6fc;
}

/* Toolbar (Filter + Search) */
.rankup-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.category-filter-container {
    flex-shrink: 0;
}

.product-search-box {
    flex-grow: 1;
    /* max-width: 300px; */
    /* Optional: limit search box width so it doesn't stretch too wide */
    margin-bottom: 0 !important;
    /* Override any legacy margins */
}

/* Ensure dropdown doesn't get cut off or misplaced */
.category-filter-container {
    position: relative;
    z-index: 10;
}

/* Responsive adjustment for mobile */
@media (max-width: 768px) {
    .rankup-toolbar {
        flex-direction: column-reverse;
        /* Search on top for mobile, or column for stack */
        align-items: stretch;
        gap: 10px;
    }

    .product-search-box {
        max-width: 100%;
    }
}

/* ==========================================================================
   Quick Order Specific Styles
   ========================================================================== */

/* Step Indicators */
.quick-order-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.quick-order-steps .step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 25px;
    background: #fff;
    border: 2px solid #ddd;
    color: #666;
    transition: all 0.3s;
}

.quick-order-steps .step.active {
    background: #2271b1;
    border-color: #2271b1;
    color: #fff;
}

.quick-order-steps .step.completed {
    background: #46b450;
    border-color: #46b450;
    color: #fff;
}

.quick-order-steps .step-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.quick-order-steps .step.active .step-number,
.quick-order-steps .step.completed .step-number {
    background: rgba(255, 255, 255, 0.3);
}

.quick-order-steps .step-divider {
    width: 60px;
    height: 2px;
    background: #ddd;
    margin: 0 10px;
}

/* Quick Order Steps Content */
.quick-order-step {
    display: none;
}

.quick-order-step.active {
    display: block;
}

/* Quick Order Product Table - Now applies to all frontend product tables */
.quick-order-table,
.rankup-b2b-frontend-page .wp-list-table,
.rankup-b2b-frontend-page table.widefat {
    width: 100%;
    border-collapse: collapse;
}

.quick-order-table thead th,
.rankup-b2b-frontend-page .wp-list-table thead th,
.rankup-b2b-frontend-page table.widefat thead th {
    text-align: left;
    padding: 12px 10px;
    background: #f8f9fa;
    border-bottom: 2px solid #e5e7eb;
    font-weight: 600;
    color: #374151;
    font-size: 13px;
}

.quick-order-table tbody td,
.rankup-b2b-frontend-page .wp-list-table tbody td,
.rankup-b2b-frontend-page table.widefat tbody td,
.quick-order-table tbody td {
    padding: 12px 10px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
    font-size: 14px;
}

/* Alternating row colors (zebra stripes) */
.quick-order-table tbody tr:nth-child(even),
.rankup-b2b-frontend-page .wp-list-table tbody tr:nth-child(even),
.rankup-b2b-frontend-page table.widefat tbody tr:nth-child(even) {
    background: #f9fafb;
}

.quick-order-table tbody tr:hover,
.rankup-b2b-frontend-page .wp-list-table tbody tr:hover,
.rankup-b2b-frontend-page table.widefat tbody tr:hover {
    background: #f0f6fc;
}

.qo-product-image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
}

.qo-product-qty {
    width: 70px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
}

/* Order Preview (Step 2) - Invoice Style */
.order-preview-container {
    background: #f5f5f5;
    padding: 30px;
    border-radius: 8px;
}

.order-preview-paper {
    background: #fff;
    max-width: 900px;
    margin: 0 auto;
    padding: 40px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.preview-logo img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 8px;
}

.preview-company .company-name {
    font-weight: 800;
    font-size: 15px;
    text-transform: uppercase;
    margin-top: 10px;
}

.preview-meta {
    text-align: right;
    font-size: 12px;
    color: #6b7280;
}

.preview-accent-line {
    height: 8px;
    border-radius: 4px;
    margin: 15px 0;
    background: #2271b1;
}

.preview-title {
    font-size: 26px;
    margin: 10px 0 25px 0;
    font-weight: 700;
    color: #111;
}

.preview-items-table {
    width: 100%;
    border-collapse: collapse;
}

.preview-items-table thead th {
    font-size: 12px;
    text-align: left;
    padding: 12px 8px;
    border-bottom: 2px solid #e8ecef;
    color: #6b7280;
    font-weight: 600;
}

.preview-items-table tbody td {
    padding: 14px 8px;
    border-bottom: 1px solid #f2f4f6;
    font-size: 13px;
}

.preview-items-table .text-right {
    text-align: right;
}

.preview-totals-large {
    text-align: right;
    margin-top: 20px;
    font-size: 14px;
}

.preview-totals-large .totals-row {
    padding: 6px 10px;
    color: #6b7280;
}

.preview-totals-large .total-row {
    font-size: 20px;
    font-weight: 700;
    color: #111;
    padding-top: 12px;
    border-top: 2px solid #e8ecef;
    margin-top: 10px;
}

.preview-actions-bottom {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.preview-actions-bottom .button-large {
    padding: 12px 30px;
    font-size: 16px;
}

/* Success Step */
.order-success-container {
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.success-icon {
    width: 80px;
    height: 80px;
    background: #46b450;
    color: #fff;
    font-size: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.order-success-container h2 {
    margin: 0 0 10px 0;
    color: #1d2327;
}

.order-success-container p {
    color: #6b7280;
    margin-bottom: 30px;
}

.success-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.success-actions .button-large {
    padding: 12px 30px;
    font-size: 15px;
}

/* Responsive for Quick Order */
@media (max-width: 768px) {
    .quick-order-steps .step-label {
        display: none;
    }

    .quick-order-steps .step {
        padding: 10px;
    }

    .order-preview-paper {
        padding: 20px;
    }

    .preview-actions-bottom {
        flex-direction: column;
        gap: 10px;
    }

    .success-actions {
        flex-direction: column;
    }
}