/**
 * Storefront Collaborator (CTV / Affiliate) Module Styles
 * Strictly standardized to 1688buyer Order Pages:
 * - frontend/views/buyer-account/orders.php
 * - frontend/views/buyer-consignment/index.php
 * - frontend/views/buyer-payment-support/index.php
 * - frontend/web/css/modules/buyer-account.css
 */

/* -------------------------------------------------------------------------
   1. Toolbar & Buttons (Exact parity with orders.php & consignments/index.php)
   ------------------------------------------------------------------------- */
.ctv-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ctv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.35;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none !important;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ctv-btn--lg {
    min-height: 36px;
    padding: 8px 20px;
}

.ctv-btn--sm {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 12px;
}

.ctv-btn--primary {
    background: #ff5000;
    color: #ffffff !important;
    border-color: #ff5000;
}

.ctv-btn--primary:hover:not(:disabled) {
    background: #e04600;
    border-color: #e04600;
    color: #ffffff !important;
}

.ctv-btn--secondary,
.ctv-btn--gray {
    background: #f3f4f6;
    color: #374151 !important;
    border-color: #eaedf1;
}

.ctv-btn--secondary:hover:not(:disabled),
.ctv-btn--gray:hover:not(:disabled) {
    background: #e5e7eb;
    border-color: #d1d5db;
    color: #111827 !important;
}

.ctv-btn--outline,
.ctv-btn--ghost {
    background: #ffffff;
    color: #374151 !important;
    border-color: #d1d5db;
}

.ctv-btn--outline:hover:not(:disabled),
.ctv-btn--ghost:hover:not(:disabled) {
    border-color: #ff5000;
    color: #ff5000 !important;
    background: #fffaf5;
}

.ctv-btn--soft-orange {
    background: #fff5ef;
    color: #ff5000 !important;
    border-color: #ffd8bf;
}

.ctv-btn--soft-orange:hover:not(:disabled) {
    background: #ff5000;
    color: #ffffff !important;
    border-color: #ff5000;
}

.ctv-btn--danger-outline {
    background: #ffffff;
    color: #ef4444 !important;
    border-color: #fecaca;
}

.ctv-btn--danger-outline:hover:not(:disabled) {
    background: #fef2f2;
    border-color: #ef4444;
    color: #dc2626 !important;
}

.ctv-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* -------------------------------------------------------------------------
   2. Header Meta & Status Badges (Exact parity with orders.php & transactions.php)
   ------------------------------------------------------------------------- */
.ctv-header-submeta {
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    line-height: 1.45;
}

.ctv-meta-sep {
    color: #d1d5db;
    margin: 0 2px;
}

.ctv-code-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 1px 6px;
    margin: -1px 0;
    border-radius: 4px;
    background: transparent;
    border: 1px solid transparent;
    color: #111827;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ctv-code-badge:hover {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #111827;
}

.ctv-code-badge:hover .app-copy-icon {
    color: #ff5000;
}

.ctv-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 2px;
    font-size: 12px;
    font-weight: 400;
    border: 1px solid transparent;
    white-space: nowrap;
}

.ctv-pill--paid {
    background: #f0fdf4;
    color: #16a34a;
    border-color: #bbf7d0;
}

.ctv-pill--unpaid {
    background: #fff5ef;
    color: #ff5000;
    border-color: #ffd8bf;
}

.ctv-pill--pending {
    background: #fffbeb;
    color: #d97706;
    border-color: #fde68a;
}

.ctv-pill--approved {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.ctv-pill--rejected,
.ctv-pill--cancelled,
.ctv-pill--voided {
    background: #fff1f0;
    color: #cf1322;
    border-color: #ffa39e;
}

/* -------------------------------------------------------------------------
   3. Panes, KPI Grid & Order-Card Rows
   ------------------------------------------------------------------------- */
.ctv-tab-pane,
.ctv-info-pane {
    display: none;
}

.ctv-tab-pane.is-active,
.ctv-info-pane.is-active {
    display: block;
}

.ctv-metrics-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.ctv-metrics-grid-4 .account-metric-card {
    margin-bottom: 0;
}

.ctv-empty-card {
    text-align: center;
    padding: 46px 20px;
    color: #9ca3af;
}

.ctv-empty-icon {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
    color: #9ca3af;
}

.ctv-empty-title {
    font-size: 15px;
    margin: 0 0 8px;
    color: #4b5563;
    font-weight: 400;
}

.ctv-empty-desc {
    font-size: 13px;
    margin: 0 auto 18px;
    color: #6b7280;
    max-width: 540px;
    line-height: 1.55;
}

/* Order-Card Body Rows (Matches consignments/index.php parcel rows) */
.ctv-order-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ctv-spec-rows {
    padding: 6px 20px;
}

.ctv-spec-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 11px 0;
    border-bottom: 1px dashed #f1f5f9;
    flex-wrap: wrap;
}

.ctv-spec-row:last-child {
    border-bottom: none;
}

.ctv-spec-left {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.ctv-spec-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 7px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 3px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.5px;
    font-weight: 400;
    color: #334155;
    flex-shrink: 0;
    margin-top: 1px;
}

.ctv-spec-title {
    font-size: 13px;
    font-weight: 400;
    color: #111827;
}

.ctv-spec-sub {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
    line-height: 1.45;
}

.ctv-spec-right {
    font-size: 12.5px;
    color: #374151;
    font-weight: 400;
    text-align: right;
    flex-shrink: 0;
}

/* Deep-Link & QR Builder */
.ctv-deeplink-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 176px;
    gap: 20px;
    align-items: start;
}

.ctv-deeplink-copy-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.ctv-qr-card {
    text-align: center;
    padding: 12px;
    border: 1px solid #eaedf1;
    border-radius: 4px;
    background: #fafbfc;
}

.ctv-qr-card img {
    width: 140px;
    height: 140px;
    border-radius: 4px;
    border: 1px solid #eaedf1;
    background: #ffffff;
    display: block;
    margin: 0 auto;
}

/* Orders Filter Toolbar inside Tab 3 */
.ctv-orders-filter-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.ctv-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.ctv-filter-bar .search-select-box,
.ctv-filter-bar select {
    width: 175px;
}

.ctv-filter-bar > input[type="text"] {
    flex: 1 1 200px;
    min-width: 160px;
    height: 35px;
    padding: 6px 12px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px;
}

.ctv-cell-val {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Ledger Tables (Matches transactions.php & buyer-payment-support.css) */
.ctv-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ctv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

.ctv-table th {
    padding: 10px 12px;
    background: #fafbfc;
    color: #6b7280;
    font-weight: 400;
    font-size: 12.5px;
    border-bottom: 1px solid #eaedf1;
    white-space: nowrap;
}

.ctv-table td {
    padding: 12px;
    border-bottom: 1px solid #f3f4f6;
    color: #1f2937;
    vertical-align: middle;
}

.ctv-table tbody tr:last-child td {
    border-bottom: none;
}

.ctv-table tbody tr.is-clickable {
    cursor: pointer;
    transition: background-color 0.12s ease;
}

.ctv-table tbody tr.is-clickable:hover {
    background: #fffcf8;
}

/* -------------------------------------------------------------------------
   4. Popup Modals & Slide-over Drawers (Matches .account-modal-* in buyer-account.css)
   ------------------------------------------------------------------------- */
.ctv-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: var(--overlay-backdrop-bg, rgba(15, 23, 42, 0.28));
    backdrop-filter: blur(var(--overlay-backdrop-blur, 1px));
    -webkit-backdrop-filter: blur(var(--overlay-backdrop-blur, 1px));
    z-index: var(--z-drawer, 180);
    display: none;
}

.ctv-drawer-backdrop.is-open {
    display: block;
}

.ctv-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(480px, 100dvw);
    height: 100dvh;
    background: #ffffff;
    z-index: 182;
    border-left: 1px solid #e6e8eb;
    box-shadow: -6px 0 24px rgba(15, 23, 42, 0.14);
    transform: translateX(102%);
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    overscroll-behavior: contain;
}

.ctv-drawer.is-open {
    transform: translateX(0);
}

.ctv-drawer-head {
    padding: 14px 20px;
    background: #fafbfc;
    border-bottom: 1px solid #eaedf1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.ctv-drawer-body {
    padding: 18px 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    flex: 1;
}

.ctv-drawer-foot {
    padding: 12px 20px max(12px, env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #eaedf1;
    background: #fafbfc;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.ctv-modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-backdrop-bg, rgba(15, 23, 42, 0.35));
    backdrop-filter: blur(var(--overlay-backdrop-blur, 1px));
    -webkit-backdrop-filter: blur(var(--overlay-backdrop-blur, 1px));
    z-index: var(--z-modal-backdrop, 220);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overscroll-behavior: contain;
}

.ctv-modal-overlay.is-open {
    display: flex;
}

.ctv-modal-box {
    background: #ffffff;
    border: 1px solid #e6e8eb;
    border-radius: 4px;
    width: min(520px, 100%);
    max-height: min(90dvh, 760px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.ctv-modal-drag-handle {
    display: none;
    width: 36px;
    height: 4px;
    border-radius: 99px;
    background: #d1d5db;
    margin: 8px auto 0;
    flex-shrink: 0;
}

.ctv-modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eaedf1;
    background: #fafbfc;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.ctv-modal-title {
    margin: 0;
    font-family: var(--font-heading, inherit);
    font-size: 16px;
    font-weight: 400;
    color: #111827;
    line-height: 1.35;
}

.ctv-modal-subtitle {
    margin: 3px 0 0;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.45;
}

.ctv-modal-close-btn {
    border: none;
    background: transparent;
    padding: 4px;
    border-radius: 4px;
    color: #9ca3af;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ctv-modal-close-btn:hover {
    color: #374151;
    background: #f3f4f6;
}

.ctv-modal-body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    flex: 1;
}

.ctv-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #eaedf1;
    background: #fafbfc;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ctv-modal-account-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    margin-bottom: 16px;
    border-radius: 4px;
    background: #fafbfc;
    border: 1px solid #eaedf1;
    font-size: 12.5px;
    color: #374151;
}

.ctv-char-counter {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-top: 5px;
    font-size: 11.5px;
    color: #9ca3af;
    line-height: 1.4;
}

.ctv-char-counter #ctv-reg-note-count {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.ctv-formula-box {
    background: #fafbfc;
    border: 1px solid #eaedf1;
    border-radius: 4px;
    padding: 14px;
    margin: 12px 0;
}

/* -------------------------------------------------------------------------
   5. Guest Landing Page (/collaborator) — Clean B2B System
   ------------------------------------------------------------------------- */
.ctv-landing-wrap {
    background: #f5f6f8;
    padding: 24px 0 56px;
}

.ctv-landing-container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 20px;
}

.ctv-landing-hero-card {
    background: #ffffff;
    border: 1px solid #e6e8eb;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    margin-bottom: 16px;
}

.ctv-landing-hero-head {
    padding: 12px 24px;
    background: #fafbfc;
    border-bottom: 1px solid #eaedf1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12.5px;
    color: #6b7280;
}

.ctv-landing-hero-body {
    padding: 28px 24px;
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.85fr);
    gap: 28px;
    align-items: center;
}

.ctv-landing-title {
    font-family: var(--font-heading, inherit);
    font-size: 24px;
    line-height: 1.35;
    font-weight: 400;
    color: #111827;
    margin: 0 0 10px;
}

.ctv-text-accent {
    color: #ff5000;
}

.ctv-landing-desc {
    margin: 0 0 20px;
    color: #4b5563;
    font-size: 13.5px;
    line-height: 1.6;
}

.ctv-landing-desc code {
    background: #fff5ef;
    border: 1px solid #ffd8bf;
    color: #ff5000;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 12.5px;
}

.ctv-landing-cta-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.ctv-landing-summary-box {
    background: #fafbfc;
    border: 1px solid #eaedf1;
    border-radius: 4px;
    padding: 16px 18px;
}

.ctv-landing-summary-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 13px;
    color: #374151;
}

.ctv-landing-summary-list li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.45;
}

.ctv-landing-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

/* -------------------------------------------------------------------------
   6. Responsive Adaptations (<= 1100px, <= 768px, <= 640px)
   ------------------------------------------------------------------------- */
@media (max-width: 1100px) {
    .ctv-metrics-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ctv-landing-hero-body,
    .ctv-landing-grid-3 {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 768px) {
    .ctv-toolbar-actions {
        width: 100%;
    }

    .ctv-toolbar-actions > .ctv-btn,
    .ctv-toolbar-actions > a {
        flex: 1 1 auto;
    }

    .ctv-deeplink-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .ctv-deeplink-copy-row {
        flex-direction: column;
    }

    .ctv-deeplink-copy-row .ctv-btn {
        width: 100%;
    }

    .ctv-filter-bar .search-select-box,
    .ctv-filter-bar select,
    .ctv-filter-bar > input[type="text"],
    .ctv-filter-bar .ctv-btn {
        width: 100%;
        flex: 1 1 100%;
    }

    .ctv-spec-rows {
        padding: 4px 14px;
    }

    .ctv-spec-right {
        width: 100%;
        text-align: left;
        padding-left: 34px;
    }

    /* Mobile Stacked Table Cards (Matches buyer-payment-support.css <= 767px) */
    .ctv-table--responsive thead {
        display: none;
    }

    .ctv-table--responsive,
    .ctv-table--responsive tbody {
        display: block;
        width: 100%;
    }

    .ctv-table--responsive tbody tr.ctv-data-row {
        display: block;
        border: 1px solid #eaedf1;
        border-radius: 4px;
        padding: 10px 12px;
        margin-bottom: 10px;
        background: #ffffff;
    }

    .ctv-table--responsive tbody tr.ctv-data-row:last-child {
        margin-bottom: 0;
    }

    .ctv-table--responsive tbody tr.ctv-data-row td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        padding: 5px 0 !important;
        border-bottom: 1px dashed #f3f4f6;
        text-align: right !important;
    }

    .ctv-table--responsive tbody tr.ctv-data-row td:last-child {
        border-bottom: none;
    }

    .ctv-table--responsive tbody tr.ctv-data-row td::before {
        content: attr(data-label);
        font-size: 12px;
        color: #6b7280;
        font-weight: 400;
        text-align: left;
        flex-shrink: 0;
    }
}

@media (max-width: 640px) {
    .ctv-metrics-grid-4 {
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
    }

    .ctv-landing-container {
        padding: 0 12px;
    }

    .ctv-landing-hero-head {
        padding: 10px 14px;
    }

    .ctv-landing-hero-body {
        padding: 18px 14px;
        gap: 18px;
    }

    .ctv-landing-cta-row {
        flex-direction: column;
        align-items: stretch;
    }

    .ctv-landing-cta-row .ctv-btn {
        width: 100%;
        box-sizing: border-box;
    }

    /* Mobile Bottom-Sheet Modal */
    .ctv-modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .ctv-modal-box {
        width: 100%;
        max-height: 90dvh;
        border-radius: 16px 16px 0 0;
        border-bottom: none;
        touch-action: pan-y;
        overscroll-behavior-y: contain;
        animation: sheetSlideUpMobile 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    }

    .ctv-modal-drag-handle {
        display: block;
        position: relative;
        width: 38px;
        height: 4px;
        background: #cbd5e1;
        margin: 10px auto 4px;
        cursor: grab;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
    }

    .ctv-modal-header {
        padding: 12px 16px;
    }

    .ctv-modal-body {
        padding: 16px;
    }

    .ctv-modal-footer {
        align-items: stretch;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .ctv-modal-footer .ctv-btn,
    .ctv-modal-footer .btn-primary,
    .ctv-modal-footer .btn-secondary {
        flex: 1;
        padding: 9px 12px;
        white-space: nowrap;
    }

    .ctv-drawer {
        width: 100%;
    }
}

@media (max-width: 375px) {
    .ctv-btn,
    .ctv-modal-footer .ctv-btn,
    .ctv-modal-footer .btn-primary,
    .ctv-modal-footer .btn-secondary {
        white-space: normal;
        text-align: center;
    }
}
