/* ============================================================
   GGZ ADMIN PORTAL — PRODUCTS PAGE STYLES
   Enforces Rule #1 (Separation), Rule #6 (5-Tier Responsive Architecture & Zero Horizontal Scroll).
   ============================================================ */

/* Page header with flex layout */
.products-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 14px;
    flex-wrap: wrap;
}

.products-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary, #fff);
    margin: 0;
    letter-spacing: -0.3px;
}

/* Bulk margin card */
.bulk-margin-card {
    background: var(--theme-bg-card, var(--bg-surface, rgba(22, 24, 34, 0.8)));
    border: 1px solid var(--theme-border, var(--border, rgba(255, 255, 255, 0.08)));
    border-radius: 14px;
    padding: 16px 20px;
    margin-bottom: 16px;
    transition: all 0.2s ease;
}

.bulk-margin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    gap: 12px;
}

.bulk-margin-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bulk-margin-title-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.bulk-margin-subtitle {
    font-size: 11.5px;
    color: var(--text-muted, #94a3b8);
    display: block;
    margin-top: 2px;
}

.bulk-margin-toggle-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bulk-margin-badge {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--primary-light, #818cf8);
    background: var(--primary-glow, rgba(99, 102, 241, 0.12));
    border: 1px solid var(--primary-glow, rgba(99, 102, 241, 0.25));
    padding: 2px 8px;
    border-radius: 6px;
}

.bulk-margin-chevron {
    color: var(--text-muted, #94a3b8);
    transition: transform 0.25s ease;
}

.bulk-margin-card.is-open .bulk-margin-chevron {
    transform: rotate(180deg);
}

.bulk-tax-quick-actions {
    display: flex;
    gap: 8px;
    margin: 12px 0;
    flex-wrap: wrap;
}

.btn-tax-free {
    font-size: 12px;
    padding: 6px 12px;
    background: rgba(52, 211, 153, 0.12);
    border: 1px solid rgba(52, 211, 153, 0.3);
    color: #34d399;
    cursor: pointer;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-tax-free:hover {
    background: rgba(52, 211, 153, 0.22);
}

.btn-taxable {
    font-size: 12px;
    padding: 6px 12px;
    background: var(--primary-glow, rgba(99, 102, 241, 0.12));
    border: 1px solid var(--primary-glow, rgba(99, 102, 241, 0.3));
    color: var(--primary-light, #a5b4fc);
    cursor: pointer;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-taxable:hover {
    background: var(--primary-glow, rgba(99, 102, 241, 0.22));
}

@media (min-width: 769px) {
    .bulk-margin-content {
        display: block !important;
        margin-top: 14px;
        border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.05));
        padding-top: 12px;
    }
    .bulk-margin-toggle-indicator {
        display: none;
    }
    .bulk-margin-header {
        cursor: default;
    }
}

.bulk-margin-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.bulk-margin-row .form-group {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 150px;
}

.bulk-margin-row .form-group label {
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text-muted, #94a3b8);
}

.bulk-margin-row select,
.bulk-margin-row input[type="number"] {
    padding: 8px 12px;
    background: var(--theme-input-bg, var(--theme-bg-input, var(--bg-hover)));
    border: 1px solid var(--theme-input-border, var(--theme-border, var(--border)));
    border-radius: 8px;
    color: var(--text-primary, #fff);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
    width: 100%;
}

.bulk-margin-row select:focus,
.bulk-margin-row input[type="number"]:focus {
    border-color: var(--primary, #6366f1);
}

.btn-success {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s;
    white-space: nowrap;
    min-height: 36px;
}

.btn-success:hover:not(:disabled) {
    background: rgba(16, 185, 129, 0.25);
    border-color: rgba(16, 185, 129, 0.4);
}

.btn-success:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Products Table Card & Toolbar */
.products-table-card {
    background: var(--theme-bg-card, var(--bg-surface, rgba(22, 24, 34, 0.8)));
    border: 1px solid var(--theme-border, var(--border, rgba(255, 255, 255, 0.08)));
    border-radius: 14px;
    padding: 18px 20px;
    overflow: hidden;
    margin-bottom: 24px;
}

.products-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.products-toolbar-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.product-search-input {
    flex: 1 1 200px;
    min-width: 150px;
    padding: 8px 14px;
    background: var(--theme-input-bg, var(--theme-bg-input, var(--bg-hover)));
    border: 1px solid var(--theme-input-border, var(--theme-border, var(--border)));
    border-radius: 8px;
    color: var(--text-primary, #fff);
    font-size: 13px;
    outline: none;
}

.product-search-input:focus {
    border-color: var(--primary, #6366f1);
}

.product-filter-select {
    padding: 8px 12px;
    background: var(--theme-input-bg, var(--theme-bg-input, var(--bg-hover)));
    border: 1px solid var(--theme-input-border, var(--theme-border, var(--border)));
    border-radius: 8px;
    color: var(--text-secondary, #cbd5e1);
    font-size: 12.5px;
    cursor: pointer;
    outline: none;
}

.product-filter-select:focus {
    border-color: var(--primary, #6366f1);
}

/* Fluid Table Container with zero horizontal clipping */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-glow, rgba(99, 102, 241, 0.3)) transparent;
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: var(--primary-glow, rgba(99, 102, 241, 0.3));
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-track {
    background: transparent;
}

.products-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    text-align: left;
    table-layout: auto;
}

.products-table th {
    padding: 12px 14px;
    background: var(--bg-hover, rgba(15, 17, 23, 0.85));
    color: var(--theme-text-muted, #94a3b8);
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--theme-border, var(--border, rgba(255, 255, 255, 0.08)));
    white-space: nowrap;
}

.products-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--theme-border-subtle, var(--border, rgba(255, 255, 255, 0.04)));
    color: var(--theme-text-secondary, #cbd5e1);
    vertical-align: middle;
    white-space: nowrap;
}

.products-table td.col-product-name {
    white-space: normal;
    min-width: 180px;
}

/* Row states & Expandable Rows across all viewports */
.product-row-summary {
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.product-row-summary:hover {
    background: rgba(99, 102, 241, 0.04) !important;
}

.product-row-summary.is-expanded {
    background: rgba(99, 102, 241, 0.08) !important;
}

.product-row-summary.is-expanded td {
    border-bottom-color: rgba(99, 102, 241, 0.25) !important;
}

/* Expand chevron toggle */
.col-expand {
    width: 36px;
    padding: 8px 4px !important;
    text-align: center;
}

.btn-row-toggle {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.btn-row-toggle:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.4);
    color: #fff;
    transform: scale(1.05);
}

.chevron-icon {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.product-row-summary.is-expanded .chevron-icon {
    transform: rotate(180deg);
    stroke: #818cf8;
}

/* Provider Badges */
.badge-provider {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: capitalize;
    white-space: nowrap;
}

.badge-provider--digiflazz {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: #a5b4fc;
}

.badge-provider--apigames {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #6ee7b7;
}

.badge-provider--razer {
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #fcd34d;
}

.badge-provider--manual {
    background: rgba(148, 163, 184, 0.15);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: #cbd5e1;
}

/* Product Info Cell */
.product-cell-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.product-name-title {
    font-weight: 600;
    color: #f8fafc;
    line-height: 1.35;
    word-break: normal;
    font-size: 13.5px;
}

.product-meta-sub {
    font-size: 11px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 2px;
}

/* Dynamic Profit / Loss Sell Price Highlighting */
.product-price-cell {
    font-weight: 600;
    font-size: 13.5px;
    font-variant-numeric: tabular-nums;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.18s ease;
}

.product-price--profit {
    color: #34d399 !important;
}

.product-price--loss {
    color: #f87171 !important;
    font-weight: 700 !important;
}

.product-price--loss::after {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    vertical-align: -1px;
    margin-left: 3px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23f87171' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z'%3E%3C/path%3E%3Cline x1='12' y1='9' x2='12' y2='13'%3E%3C/line%3E%3Cline x1='12' y1='17' x2='12.01' y2='17'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
}

/* SKU code styling */
.products-table code,
.product-drawer-content code {
    background: rgba(99, 102, 241, 0.12);
    color: #a5b4fc;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11.5px;
    font-family: 'JetBrains Mono', monospace;
    display: inline-block;
}

/* Margin inline edit */
.margin-edit-container {
    display: inline-flex;
    align-items: center;
}

.margin-text {
    cursor: pointer;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.3);
    padding-bottom: 1px;
    transition: color 0.15s;
    font-variant-numeric: tabular-nums;
}

.margin-text:hover {
    color: #818cf8;
    border-bottom-color: #818cf8;
}

.margin-type-select {
    padding: 4px 8px !important;
    font-size: 12px !important;
    border-radius: 6px !important;
    background: #1e2235 !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    color: #f8fafc !important;
    color-scheme: dark;
    outline: none;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
}

.margin-type-select option {
    background-color: #1e2235 !important;
    color: #f8fafc !important;
    padding: 6px 10px;
}

.margin-input {
    width: 72px !important;
    padding: 4px 8px !important;
    font-size: 13px !important;
    border-radius: 6px !important;
    text-align: center;
    background: rgba(15, 17, 23, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* Expandable Drawer (Sub-row) */
.product-row-drawer {
    display: none;
    background: linear-gradient(135deg, rgba(16, 20, 35, 0.98) 0%, rgba(11, 14, 25, 0.99) 100%);
    border-bottom: 1px solid rgba(99, 102, 241, 0.2);
}

.product-row-drawer.is-open {
    display: table-row;
    animation: drawerFadeIn 0.2s ease forwards;
}

@keyframes drawerFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.product-row-drawer td {
    padding: 0 !important;
}

.product-drawer-content {
    padding: 16px 20px 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-left: 3px solid #6366f1;
}

.product-drawer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    background: transparent;
    padding: 0;
    border: none;
}

.product-drawer-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
    box-sizing: border-box;
}

.product-drawer-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-drawer-val {
    font-size: 13.5px;
    color: #f8fafc;
    font-weight: 600;
    word-break: break-word;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-drawer-desc-box {
    background: rgba(0, 0, 0, 0.3);
    border: 1px dashed rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 12px 16px;
    color: #cbd5e1;
    font-size: 12.5px;
    line-height: 1.5;
}

/* Interactive Status Toggle Buttons */
button.btn-toggle-product-status.badge {
    cursor: pointer;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 6px;
    transition: all 0.18s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

button.btn-toggle-product-status.badge:hover {
    transform: scale(1.08);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

.btn-status-drawer--active {
    background: rgba(52, 211, 153, 0.15);
    border: 1px solid rgba(52, 211, 153, 0.35);
    color: #34d399;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.18s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-status-drawer--active:hover {
    background: rgba(52, 211, 153, 0.25);
    transform: scale(1.02);
}

.btn-status-drawer--off {
    background: rgba(248, 113, 113, 0.15);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #f87171;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.18s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-status-drawer--off:hover {
    background: rgba(248, 113, 113, 0.25);
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.4);
    transform: scale(1.02);
}

.btn-toggle-tax-exempt {
    max-width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Pagination */
.product-pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 16px;
    margin-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 13px;
    color: #94a3b8;
    gap: 12px;
    flex-wrap: wrap;
}

.product-pagination-btns {
    display: flex;
    gap: 6px;
}

.btn-page {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #cbd5e1;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 500;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.btn-page:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.btn-page.is-active {
    background: var(--primary, #6366f1);
    border-color: transparent;
    color: #fff;
}

.btn-page:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Spinner */
.btn-spinner,
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   5-Tier Responsive Architecture (Rule #6)
   ============================================================ */

/* Desktop / Laptop (>= 769px) */
@media (min-width: 769px) {
    .product-row-summary {
        cursor: pointer;
    }
}

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .products-header { gap: 12px; }
    .bulk-margin-row { flex-wrap: wrap; }
    .col-hide-tablet { display: none !important; }
}

/* Mobile Landscape & Portrait (< 768px): Hide desktop-only columns */
@media (max-width: 768px) {
    .col-hide-mobile,
    .col-hide-tablet {
        display: none !important;
    }

    .col-show-mobile {
        display: flex !important;
    }

    .products-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        margin-bottom: 14px;
    }

    .products-header > button {
        width: 100%;
        justify-content: center;
    }

    /* Bulk margin card compact and collapsible on mobile */
    .bulk-margin-card {
        padding: 12px 14px;
        margin-bottom: 12px;
        border-radius: 12px;
    }

    .bulk-margin-content {
        display: none;
        margin-top: 12px;
        border-top: 1px solid rgba(255, 255, 255, 0.06);
        padding-top: 12px;
    }

    .bulk-margin-card.is-open .bulk-margin-content {
        display: block;
    }

    .bulk-tax-quick-actions {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 12px;
    }

    .bulk-tax-quick-actions button {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .bulk-margin-row {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .bulk-margin-row .form-group {
        gap: 3px;
    }

    .bulk-margin-row .fg-category {
        flex: 1 1 100%;
        width: 100%;
    }

    .bulk-margin-row .fg-type {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }

    .bulk-margin-row .fg-value {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }

    .bulk-margin-row select,
    .bulk-margin-row input[type="number"] {
        width: 100%;
        padding: 8px 10px;
        font-size: 12.5px;
    }

    .btn-apply-margin,
    .btn-success {
        width: 100%;
        justify-content: center;
        padding: 9px 14px;
        min-height: 40px;
        margin-top: 4px;
    }

    .products-table-card {
        padding: 12px 14px;
        border-radius: 12px;
    }

    .products-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-bottom: 12px;
    }

    .products-toolbar-filters {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
        width: 100%;
    }

    .product-search-input {
        width: 100%;
        flex: 1 1 100%;
        padding: 9px 12px;
        font-size: 13px;
    }

    .product-filter-select {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
        padding: 9px 10px;
        font-size: 12.5px;
    }

    .products-table th,
    .products-table td {
        padding: 8px 6px;
    }

    .product-pagination-bar {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 8px;
        padding-top: 12px;
        margin-top: 8px;
    }

    .product-drawer-grid {
        grid-template-columns: 1fr;
        padding: 8px 10px;
    }
}

/* Mobile Portrait (320px - 480px) */
@media (max-width: 480px) {
    .products-header h1 { font-size: 1.25rem; }
    .bulk-margin-card { padding: 10px 12px; }
    .products-table-card { padding: 10px 12px; }
}
