/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1565c0;
    --primary-dark: #0d47a1;
    --primary-light: #e3f2fd;
    --accent: #f57c00;
    --accent-dark: #e65100;
    --text: #1a1a2e;
    --text-light: #555;
    --text-muted: #999;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --border: #e0e0e0;
    --border-light: #eee;
    --success: #2e7d32;
    --danger: #c62828;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.12);
    --font: 'Noto Sans SC', 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: #fff;
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.logo { display: flex; align-items: center; gap: 0.75rem; }
.logo-icon { font-size: 2rem; }
.logo-text h1 { font-size: 1.1rem; font-weight: 700; line-height: 1.3; }
.logo-text p { font-size: 0.78rem; opacity: 0.85; }

.lang-switcher { display: flex; gap: 0.25rem; }
.lang-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: #fff;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s;
}
.lang-btn:hover { background: rgba(255,255,255,0.3); }
.lang-btn.active { background: #fff; color: var(--primary-dark); }

/* ===== Container ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* ===== Tabs ===== */
.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
}
.tab-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-light);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}
.tab-btn:hover { background: var(--primary-light); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 700;
}
.tab-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    font-size: 0.72rem;
    font-weight: 700;
}
.tab-btn.active .tab-num { background: var(--primary-dark); }

/* ===== Tab Panels ===== */
.tab-panel { display: none; animation: fadeIn 0.3s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Card ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.card-title { font-size: 1.2rem; font-weight: 700; color: var(--text); margin-bottom: 0.4rem; }
.card-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* === Editing-mode banner === */
.editing-banner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: linear-gradient(135deg, #fff7e6 0%, #ffe7ba 100%);
    border: 1px solid #ffa940;
    color: #ad4e00;
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 2px 6px rgba(255, 169, 64, 0.15);
}
.editing-banner-icon { font-size: 1.1rem; }
.editing-banner-text { flex: 1; }
.form-type-switch { display: flex; gap: 1rem; }
.switch-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 500;
}
.switch-label input { accent-color: var(--primary); }

/* ===== Raw Input ===== */
.raw-input {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    line-height: 1.7;
    resize: vertical;
    transition: border-color 0.2s;
}
.raw-input:focus { outline: none; border-color: var(--primary); }
.raw-input::placeholder { color: var(--text-muted); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(21,101,192,0.3); }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); }

.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }

.btn-ghost { background: transparent; color: var(--text-light); }
.btn-ghost:hover { background: var(--border-light); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.7rem 1.5rem; font-size: 1rem; font-weight: 700; }

.input-actions, .form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* ===== Form ===== */
.form-section { margin-bottom: 1.5rem; }
.form-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--primary-light);
}
.form-section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--primary-light);
}
.form-section-title-row .form-section-title { margin-bottom: 0; padding-bottom: 0; border: none; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}
.form-field { display: flex; flex-direction: column; gap: 0.3rem; }
.form-field.full { grid-column: 1 / -1; }
.form-field label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-light);
}
.form-input {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.88rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
    color: var(--text);
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(21,101,192,0.12);
}
textarea.form-input { resize: vertical; min-height: 60px; }

/* ===== Product Table ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.product-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    min-width: 720px;
}
.product-table th {
    background: var(--primary-dark);
    color: #fff;
    padding: 0.5rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    white-space: nowrap;
    position: sticky;
    top: 0;
}
.product-table td { padding: 0.35rem 0.4rem; border-bottom: 1px solid var(--border-light); }
.product-table tbody tr:hover { background: var(--primary-light); }
.product-table input, .product-table select {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    padding: 0.3rem 0.35rem;
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.82rem;
    color: var(--text);
}
.product-table input:focus, .product-table select:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 2px rgba(21,101,192,0.1);
}
.product-table .col-amount { font-weight: 700; color: var(--primary-dark); }
.product-table .btn-del-row {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}
.product-table .btn-del-row:hover { background: #ffebee; }

/* === Product Image Cell (form) === */
.p-img-cell { padding: 0.25rem !important; text-align: center; }
.p-img-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
}
.p-img-thumb {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: border-color 0.2s;
}
.p-img-thumb:hover { border-color: var(--primary); }
.p-img-btn {
    width: 42px;
    height: 42px;
    border: 1px dashed var(--border);
    border-radius: 4px;
    background: #f8f9fb;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.p-img-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.p-img-del {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: none;
    font-size: 0.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}
.p-img-del:hover { opacity: 0.8; }

/* === Spec Detail Row === */
.product-spec-row { background: #f8f9fb; }
.product-spec-row td { padding: 0.5rem 0.6rem !important; border-bottom: 2px solid var(--border); }
.spec-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.4rem 0.6rem;
}
.spec-field { display: flex; flex-direction: column; gap: 0.15rem; }
.spec-field label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-light);
    white-space: nowrap;
}
.spec-field input {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    padding: 0.25rem 0.35rem;
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.78rem;
    color: var(--text);
}
.spec-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(21,101,192,0.1);
}
/* Hide arm/light fields for flagpole */
.product-spec-row.is-flagpole .spec-arm,
.product-spec-row.is-flagpole .spec-light {
    display: none;
}
/* Hide ALL pole spec fields for wooden box; show only L/W/H */
.product-spec-row.is-wooden-box .spec-top-dia,
.product-spec-row.is-wooden-box .spec-bottom-dia,
.product-spec-row.is-wooden-box .spec-thickness,
.product-spec-row.is-wooden-box .spec-base-spec,
.product-spec-row.is-wooden-box .spec-arm,
.product-spec-row.is-wooden-box .spec-embedded-spec,
.product-spec-row.is-wooden-box .spec-light {
    display: none;
}
/* Show L/W/H fields ONLY for wooden box */
.product-spec-row .spec-wooden-box {
    display: none;
}
.product-spec-row.is-wooden-box .spec-wooden-box {
    display: flex;
}

/* ===== Bank Info Section (PI only) ===== */
.bank-info-section {
    display: none;
}
.bank-info-section.visible {
    display: block;
}
/* Vertical (single-column) layout for bank info fields */
.bank-info-vertical {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.bank-info-vertical .form-field {
    width: 100%;
}

/* Bank info in document preview — two sub-sections with titled headers:
   Section 1: BANK ACCOUNT INFORMATION (bank name, address, A/C, code, SWIFT)
   Section 2: BENEFICIARY COMPANY INFORMATION (beneficiary name, address)
   All left-aligned: labels and values both start from the left edge,
   values wrap cleanly within the remaining column space.
   Account no. & SWIFT never wrap; addresses wrap to the next line. */
.doc-bank-vertical {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    font-size: 0.82rem;
    text-align: left;
}
.doc-bank-vertical .bank-group {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    text-align: left;
}
/* Sub-section title bar — left-aligned, plain uppercase */
.doc-bank-vertical .bank-group-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #222;
    margin-bottom: 0.35rem;
    padding-bottom: 0.2rem;
    text-align: left;
    align-self: flex-start;
}
/* Solid separator between the two sub-sections */
.doc-bank-vertical .bank-group + .bank-group {
    padding-top: 0.6rem;
    border-top: 1px solid #d0d0d0;
}
.doc-bank-vertical .field-row {
    display: flex;
    justify-content: flex-start;     /* left-align, not space-between */
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.1rem 0;
    text-align: left;
}
.doc-bank-vertical .field-label {
    font-weight: 600;
    color: #555;
    flex: 0 0 auto;
    min-width: 135px;
    white-space: nowrap;
    text-align: left;
}
.doc-bank-vertical .field-value {
    text-align: left;                /* left-aligned values */
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.55;
}
/* Account no. & SWIFT: keep on ONE complete line (no wrapping) */
.doc-bank-vertical .field-value.bank-code {
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: keep-all;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    flex: 0 1 auto;
}
/* Address rows: wrap to next line(s) within value column, stay left-aligned */
.doc-bank-vertical .field-row.addr-row {
    align-items: flex-start;
}
.doc-bank-vertical .field-row.addr-row .field-label {
    align-self: flex-start;
    padding-top: 0.05rem;
}
.doc-bank-vertical .field-row.addr-row .field-value {
    max-width: 65%;
}
/* RTL: mirror alignment to the right side */
.doc.rtl .doc-bank-vertical,
.doc.rtl .doc-bank-vertical .bank-group,
.doc.rtl .doc-bank-vertical .bank-group-title,
.doc.rtl .doc-bank-vertical .field-row,
.doc.rtl .doc-bank-vertical .field-label,
.doc.rtl .doc-bank-vertical .field-value {
    text-align: right;
}
.doc.rtl .doc-bank-vertical .field-row {
    flex-direction: row-reverse;
}

/* ===== Parse Result ===== */
.parse-result {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary);
    font-size: 0.85rem;
}
.parse-result-title { font-weight: 700; color: var(--primary-dark); margin-bottom: 0.5rem; }
.parse-result-item { display: flex; gap: 0.5rem; margin-bottom: 0.25rem; }
.parse-result-item .key { font-weight: 600; color: var(--text-light); min-width: 100px; }
.parse-result-item .val { color: var(--text); }

/* ===== Preview ===== */
.preview-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-light);
}
.preview-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.preview-area {
    background: #f5f5f5;
    padding: 2rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

/* === Preview Document === */
.doc {
    background: #fff;
    width: 210mm;
    min-height: 297mm;
    max-width: 100%;
    margin: 0 auto;
    padding: 20mm 18mm;
    box-shadow: 0 2px 20px rgba(0,0,0,0.1);
    font-size: 11pt;
    color: #222;
    line-height: 1.6;
}
.doc.rtl { direction: rtl; text-align: right; }

.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid var(--primary-dark);
}
.doc-header .company-info h2 { font-size: 1.3rem; color: var(--primary-dark); margin-bottom: 0.2rem; }
.doc-header .company-info p { font-size: 0.75rem; color: #666; line-height: 1.5; }
.doc-header .doc-meta { text-align: right; }
.doc.rtl .doc-meta { text-align: left; }
.doc-header .doc-meta .doc-type {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 0.3rem;
}
.doc-header .doc-meta .doc-meta-row { font-size: 0.78rem; color: #555; }
.doc-header .doc-meta .doc-meta-row strong { color: #333; }

.doc-section { margin-bottom: 1rem; }
.doc-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary-dark);
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid #ddd;
}
.doc-customer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem 1.5rem;
    font-size: 0.82rem;
}
.doc-customer-grid .field-row { display: flex; gap: 0.3rem; }
.doc-customer-grid .field-label { font-weight: 600; color: #555; min-width: 70px; }
.doc.rtl .doc-customer-grid .field-label { min-width: auto; }

.doc-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
    font-size: 0.78rem;
}
.doc-table th {
    background: var(--primary-dark);
    color: #fff;
    padding: 0.5rem 0.4rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
}
.doc.rtl .doc-table th { text-align: right; }
.doc-table td {
    padding: 0.45rem 0.4rem;
    border-bottom: 1px solid #e0e0e0;
}
.doc-table tbody tr:nth-child(even) { background: #f9f9f9; }
.doc-table .text-right { text-align: right; }
.doc-table .text-center { text-align: center; }
.doc-table td:nth-child(4) { font-size: 0.72rem; line-height: 1.5; color: #444; }
/* Long unbreakable tokens (Galvanized+Powder, 2*340WH+180WH, long model codes)
   used to push the table's min-content width past the page content area,
   clipping the Amount column off the right edge of the PDF. Product table
   therefore uses a FIXED layout with proportional columns: the table always
   spans exactly the page content width and long words wrap inside cells. */
.doc-table th, .doc-table td { overflow-wrap: break-word; }
.doc-prod-table { table-layout: fixed; }
.doc-prod-table th:nth-child(1)  { width: 4%; }   /* # */
.doc-prod-table th:nth-child(2)  { width: 8%; }   /* image */
.doc-prod-table th:nth-child(3)  { width: 12%; }  /* product */
.doc-prod-table th:nth-child(4)  { width: 23%; }  /* detail specs */
.doc-prod-table th:nth-child(5)  { width: 7%; }   /* dimensions */
.doc-prod-table th:nth-child(6)  { width: 11%; }  /* material */
.doc-prod-table th:nth-child(7)  { width: 6%; }   /* qty */
.doc-prod-table th:nth-child(8)  { width: 7%; }   /* unit */
.doc-prod-table th:nth-child(9)  { width: 10%; }  /* unit price */
.doc-prod-table th:nth-child(10) { width: 12%; }  /* amount */
.doc-prod-table td.text-right { font-size: 0.72rem; padding-left: 3px; padding-right: 3px; } /* money fits its column */
.doc-prod-table td.text-center:nth-child(7) { padding-left: 2px; padding-right: 2px; } /* qty */

/* Product image in preview table */
.doc-prod-img {
    width: 45px;
    height: 45px;
    object-fit: cover;
    border-radius: 3px;
    border: 1px solid #ddd;
}

.doc-totals {
    margin-top: 0.8rem;
    margin-left: auto;
    width: 280px;
    font-size: 0.85rem;
    break-inside: avoid;
    page-break-inside: avoid;
}
.doc.rtl .doc-totals { margin-left: 0; margin-right: auto; }

/* ===== Product table: never split a single row, in either export path =====
   These rules live OUTSIDE @media print so the PDF export (html2canvas)
   also sees them. Otherwise the PDF would show a row broken mid-cell. */
.doc-table tr { break-inside: avoid; page-break-inside: avoid; }
.doc-table thead { display: table-header-group; }
/* Atomic blocks: header, footer, totals, bank, signature, sections */
.doc-section,
.doc-header,
.doc-footer,
.doc-bank-section,
.doc-signature,
.doc-terms .term-item { break-inside: avoid; page-break-inside: avoid; }
.doc-totals .total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    border-bottom: 1px solid #eee;
}
.doc-totals .total-row.grand {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-dark);
    border-bottom: 2px solid var(--primary-dark);
    padding-top: 0.5rem;
}

.doc-terms {
    margin-top: 1.2rem;
    font-size: 0.78rem;
    line-height: 1.7;
}
.doc-terms .term-item { margin-bottom: 0.3rem; }
.doc-terms .term-label { font-weight: 700; color: #333; }

.doc-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: #666;
}
.doc-signature {
    text-align: center;
    margin-top: 2rem;
}
.doc-signature .sig-line {
    border-top: 1px solid #333;
    width: 200px;
    margin: 2.5rem auto 0.3rem;
}
.doc-signature .sig-label { font-size: 0.78rem; color: #555; }

/* ===== History ===== */
.history-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.history-count-badge {
    font-size: 0.82rem;
    color: var(--text-light);
    background: var(--bg);
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}
.history-search-input {
    width: 220px;
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
}
.history-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.8rem; }
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary);
    transition: all 0.2s;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.history-item:hover { box-shadow: var(--shadow); }
.history-item-info { flex: 1; min-width: 200px; }
.history-item-info .hi-docno { font-weight: 700; color: var(--primary-dark); font-size: 0.9rem; }
.history-item-info .hi-customer { font-size: 0.85rem; color: var(--text-light); }
.history-item-info .hi-date { font-size: 0.75rem; color: var(--text-muted); }
.history-item-info .hi-amount { font-size: 0.9rem; font-weight: 600; color: var(--accent-dark); }
.history-item-actions { display: flex; gap: 0.3rem; }

.history-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.history-empty .empty-icon { font-size: 3rem; margin-bottom: 0.5rem; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: #fff;
    padding: 0.7rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== Print Only ===== */
.print-only { display: none; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    html { font-size: 15px; }
    .container { padding: 0.5rem; }
    .card { padding: 1rem; }
    .logo-text h1 { font-size: 0.95rem; }
    .logo-text p { font-size: 0.7rem; }
    .logo-icon { font-size: 1.5rem; }
    .tab-btn { padding: 0.5rem 0.7rem; font-size: 0.78rem; }
    .form-grid { grid-template-columns: 1fr; }
    .spec-grid { grid-template-columns: 1fr 1fr; }
    .preview-area { padding: 0.5rem; }
    .doc { padding: 10mm 8mm; font-size: 10pt; }
    .doc-customer-grid { grid-template-columns: 1fr; }
    .doc-table { font-size: 0.72rem; }
    .doc-table th, .doc-table td { padding: 0.3rem 0.25rem; }
    .btn { padding: 0.5rem 0.85rem; font-size: 0.82rem; }
    .btn-lg { width: 100%; justify-content: center; }
    .preview-actions { width: 100%; }
    .preview-actions .btn { flex: 1; justify-content: center; }
    .preview-toolbar { flex-direction: column; align-items: stretch; }
    .card-header-row { flex-direction: column; align-items: stretch; }
    .form-type-switch { justify-content: center; }
    .history-item { flex-direction: column; align-items: stretch; }
    .history-item-actions { justify-content: flex-end; }
    .history-toolbar { width: 100%; }
    .history-search-input { width: 100%; }
}

@media (max-width: 480px) {
    .lang-btn { padding: 0.25rem 0.5rem; font-size: 0.72rem; }
    .tab-btn span:not(.tab-num) { display: none; }
    .tab-btn { padding: 0.5rem; }
    .doc-totals { width: 100%; }
}

/* ===== Print Styles =====
   Goal: printed output matches the on-screen preview exactly.
   Fixed A4 portrait paper; bank-info & signature blocks never split
   across pages; product table header repeats on every page. */
@media print {
    body * { visibility: hidden; }
    #printContainer, #printContainer * { visibility: visible; }
    #printContainer {
        display: block !important;
        position: absolute;
        left: 0; top: 0; width: 100%;
    }
    .print-only { display: block; }
    /* Keep .doc layout identical to preview — only drop shadow.
       Use @page margin instead of zeroing internal padding, so the
       printed doc has the same internal padding as on screen. */
    .doc {
        box-shadow: none;
        width: 100%;
        min-height: auto;
        margin: 0 auto;
        /* keep padding from screen styles (20mm 18mm) */
    }
    /* Strip preview-area gray background — paper is white */
    .preview-area { background: #fff !important; padding: 0 !important; }

    /* Fixed A4 portrait paper */
    @page { size: A4 portrait; margin: 0; }

    /* --- Anti-splitting rules (sync with jsPDF export layout) --- */
    /* Bank info block: never cut across pages */
    .doc-bank-section,
    .doc-bank-vertical { break-inside: avoid; page-break-inside: avoid; }
    /* Signature / seal area: never cut across pages */
    .doc-footer,
    .doc-signature { break-inside: avoid; page-break-inside: avoid; }
    /* Header, customer info, totals: keep each atomic */
    .doc-header,
    .doc-totals { break-inside: avoid; page-break-inside: avoid; }
    /* Terms: break per-item, not mid-line */
    .doc-terms .term-item { break-inside: avoid; page-break-inside: avoid; }

    /* --- Product table: repeat <thead> on every page ---
       NOTE: break-inside:avoid for tr and atomic block rules above
       already live OUTSIDE @media print so PDF export (html2canvas)
       benefits from them too. We only need display:table-header-group
       which is print-specific. */
    .doc-table thead { display: table-header-group; }
}

/* ===== jsPDF page container (one-click PDF export) =====
   Each page is an exact A4 portrait sheet rendered by html2canvas.
   - min-height (NOT fixed height): page can grow if a chunk is
     borderline tall, so a row is NEVER clipped by overflow.
   - overflow: visible: never hide content — the packer is the
     single source of truth for page breaks.
   - page-break-after: always: backup safety for browser print mode. */
.doc.pdf-page {
    box-shadow: none;
    width: 210mm;
    min-height: 297mm;
    height: auto;
    padding: 20mm 18mm;
    overflow: visible;
    margin: 0;
    page-break-after: always;
}
.doc.pdf-page:last-child { page-break-after: auto; }

/* ===== Bank Account Picker (in PI bank-info form section) ===== */
.bank-account-picker {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    margin-bottom: 0.8rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px dashed #d0d0d0;
}
.bank-account-picker .form-field {
    flex: 1;
    margin-bottom: 0;
}
.bank-account-picker select {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 0.92rem;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s;
}
.bank-account-picker select:focus {
    outline: none;
    border-color: var(--primary);
}
.bank-account-picker select option {
    padding: 0.3rem;
}
.bank-account-picker .btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
}
.bank-account-hint {
    margin: -0.4rem 0 0.8rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    min-height: 1.2em;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    background: transparent;
    transition: background 0.15s;
}
.bank-account-hint.active {
    background: #fff8e1;
    color: #795548;
    border-left: 3px solid var(--accent);
    padding-left: 0.7rem;
}

/* ===== Bank Account Manager Modal ===== */
.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2vh 2vw;
    overflow-y: auto;
}
.modal-mask[hidden] { display: none; }
.modal-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 1100px;
    max-height: 96vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 1rem 1.4rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--primary-light);
    border-radius: var(--radius) var(--radius) 0 0;
}
.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--primary-dark);
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.2rem 0.6rem;
    line-height: 1;
}
.modal-close:hover { color: var(--danger); }
.modal-body {
    padding: 1.2rem 1.4rem;
    overflow-y: auto;
    flex: 1;
}
.modal-body h4 {
    margin: 0 0 0.5rem;
    color: var(--primary-dark);
    font-size: 0.95rem;
    border-left: 3px solid var(--primary);
    padding-left: 0.5rem;
}

.bank-bulk-section { margin-bottom: 1.4rem; }
.bank-bulk-section .form-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.bank-bulk-section .form-textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Consolas', 'Menlo', monospace;
    font-size: 0.82rem;
    resize: vertical;
}
.bank-bulk-section .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
}
.bulk-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.6rem;
}
.bulk-stat {
    font-size: 0.82rem;
    color: var(--success);
    margin-left: 0.4rem;
}

.bank-list-section { margin-bottom: 1.4rem; }
.bank-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.bank-list-header > div {
    display: flex;
    gap: 0.4rem;
}
.bank-list-count {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left: 0.3rem;
}
.bank-list {
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    max-height: 280px;
    overflow-y: auto;
    background: #fafbfc;
}
.bank-item {
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    background: #fff;
    transition: background 0.1s;
}
.bank-item:hover { background: #f5f7fa; }
.bank-item:last-child { border-bottom: none; }
.bank-item-info {
    flex: 1;
    min-width: 0;
}
.bank-item-label {
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
    margin-bottom: 0.15rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.bank-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.bank-item-remark {
    color: var(--accent-dark);
    font-style: italic;
}
.bank-item-actions {
    display: flex;
    gap: 0.3rem;
    flex: 0 0 auto;
}
.bank-item-actions .btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.78rem;
}
.bank-currency-tag {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--primary-light);
    color: var(--primary-dark);
    letter-spacing: 0.04em;
}
.bank-currency-tag.MULTI { background: #fff3e0; color: var(--accent-dark); }
.bank-currency-tag.USD   { background: #e8f5e9; color: #2e7d32; }
.bank-currency-tag.CNY   { background: #ffebee; color: var(--danger); }
.bank-currency-tag.HKD   { background: #fce4ec; color: #c2185b; }

.bank-edit-section {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 0.5rem;
    background: #fafbfc;
    border-radius: var(--radius-sm);
    padding: 1rem;
}
.bank-edit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 0.7fr;
    gap: 0.7rem;
    margin-bottom: 0.8rem;
}
.bank-edit-grid .form-field { margin-bottom: 0; }
.bank-edit-grid .form-field.full { grid-column: span 4; }
.bank-edit-grid .form-field:not(.full) { grid-column: span 2; }
.bank-edit-grid .form-field:nth-child(4) { grid-column: span 1; }
.bank-edit-grid .form-field:nth-child(n+5):not(.full) { grid-column: span 2; }
.bank-edit-grid .form-field.full { grid-column: 1 / -1; }
.bank-edit-actions {
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--border-light);
    padding-top: 0.6rem;
}

@media (max-width: 800px) {
    .bank-account-picker { flex-direction: column; align-items: stretch; }
    .bank-account-picker .btn { width: 100%; }
    .bank-edit-grid { grid-template-columns: 1fr; }
    .bank-edit-grid .form-field,
    .bank-edit-grid .form-field.full { grid-column: 1; }
}

/* ===== Topbar "更多功能" dropdown ===== */
.topbar-right { display:flex; align-items:center; gap:0.8rem; }
.more-menu { position:relative; }
.more-btn {
    background:transparent; border:1px solid rgba(255,255,255,0.3); border-radius:6px;
    color:#fff; font-size:0.82rem; font-weight:500; padding:0.35rem 0.7rem; cursor:pointer;
    display:flex; align-items:center; gap:0.3rem; transition:background .2s;
}
.more-btn:hover { background:rgba(255,255,255,0.12); }
.more-caret { font-size:0.7rem; opacity:.7; }
.more-dropdown {
    position:absolute; top:calc(100% + 4px); right:0; min-width:160px;
    background:#fff; border-radius:8px; box-shadow:0 6px 24px rgba(0,0,0,.18);
    padding:0.3rem 0; z-index:9999; overflow:hidden;
}
.more-item {
    display:block; width:100%; text-align:left; background:transparent; border:none;
    padding:0.5rem 0.9rem; font-size:0.82rem; color:#333; cursor:pointer; transition:background .15s;
}
.more-item:hover { background:#f0f4ff; color:var(--primary-dark); }

/* ===== Converter Modal ===== */
.converter-box {
    width:96vw; max-width:1280px; max-height:92vh; overflow-y:auto;
    display:flex; flex-direction:column;
}
.converter-body { padding:0.6rem 1rem 1rem; }
.conv-section {
    margin-bottom:0.8rem; border:1px solid #e2e6ea; border-radius:8px; padding:0.6rem 0.7rem;
    background:#faffbf;
}
.conv-section-title {
    font-size:0.92rem; font-weight:700; color:var(--primary-dark);
    margin-bottom:0.5rem; padding-bottom:0.3rem; border-bottom:2px solid var(--primary-dark);
}
.conv-table-wrap { overflow-x:auto; }
.conv-table {
    width:100%; border-collapse:collapse; font-size:0.75rem; table-layout:auto;
}
.conv-table th {
    background:var(--primary-dark); color:#fff; font-weight:600;
    padding:0.35rem 0.3rem; text-align:center; white-space:nowrap;
    border:1px solid #cbd5e0; position:sticky; top:0; z-index:2;
}
.conv-table td {
    padding:0.2rem 0.25rem; border:1px solid #dfe6ea; text-align:center; vertical-align:middle;
    background:#fff;
}
.conv-table td.col-num { font-variant-numeric:tabular-nums; text-align:right; padding-right:0.4rem; }
.conv-table select,
.conv-table input[type="number"],
.conv-table input[type="text"] {
    width:100%; font-size:0.72rem; padding:0.15rem 0.25rem; border:1px solid #ccc;
    border-radius:3px; text-align:center;
}
.conv-table input[type="text"] { text-align:left; }
.conv-table .conv-dim-cell { min-width:180px; }
.conv-dim-inputs { display:flex; flex-wrap:wrap; gap:2px; align-items:center; }
.conv-dim-inputs input { width:48px !important; }
.conv-dim-inputs span { font-size:0.65rem; color:#777; white-space:nowrap; }
.conv-table .btn-del-row { font-size:0.85rem; padding:0 4px; }
.conv-add-row { margin-top:0.35rem; }

/* Material summary */
.conv-mat-summary, .conv-shipping-summary, .conv-result-box {
    margin-top:0.4rem; padding:0.5rem 0.7rem; border-radius:6px;
    background:#eef5ff; border:1px solid #c8dcf0; font-size:0.8rem;
}
.conv-mat-summary .summary-row,
.conv-shipping-summary .summary-row {
    display:flex; justify-content:space-between; align-items:baseline;
    padding:0.1rem 0; gap:0.5rem;
}
.conv-mat-summary .summary-row .label,
.conv-shipping-summary .summary-row .label { font-weight:600; color:#444; }
.conv-mat-summary .summary-row .value,
.conv-shipping-summary .summary-row .value { font-weight:700; color:var(--primary-dark); font-variant-numeric:tabular-nums; }
.conv-mat-summary .summary-total {
    margin-top:0.25rem; padding-top:0.25rem; border-top:1.5px solid #88a;
    font-size:0.85rem;
}
.conv-mat-summary .summary-total .label,
.conv-mat-summary .summary-total .value { font-size:0.85rem; }

/* Shipping grid */
.conv-shipping-grid {
    display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:0.4rem;
}
.conv-field { display:flex; flex-direction:column; gap:0.15rem; }
.conv-field label { font-size:0.75rem; font-weight:600; color:#444; }
.conv-field input, .conv-field select, .conv-field button {
    font-size:0.8rem; padding:0.2rem 0.35rem; border:1px solid #ccc; border-radius:4px;
}

/* Summary section */
.conv-summary-section { background:#f0f7e8; border-color:#c3d9a8; }
.conv-summary-grid {
    display:grid; grid-template-columns:repeat(auto-fit,minmax(160px,1fr)); gap:0.4rem; margin-bottom:0.5rem;
}
.conv-result-box {
    background:#e8f5e9; border:1px solid #a5d6a7; font-size:0.85rem;
}
.conv-result-box .result-row {
    display:flex; justify-content:space-between; align-items:baseline;
    padding:0.15rem 0; border-bottom:1px dotted #cde;
}
.conv-result-box .result-row:last-child { border-bottom:none; }
.conv-result-box .result-row .label { font-weight:600; color:#333; }
.conv-result-box .result-row .value { font-weight:700; font-variant-numeric:tabular-nums; }
.conv-result-box .result-grand {
    margin-top:0.3rem; padding-top:0.3rem; border-top:2px solid #2e7d32;
    font-size:1rem; font-weight:800; color:#2e7d32;
}
.conv-result-box .result-grand .value { font-size:1.1rem; }

/* Actions */
.conv-actions { display:flex; flex-wrap:wrap; gap:0.5rem; margin-top:0.5rem; }

/* Unit note */
.conv-unit-note {
    margin-top:0.5rem; text-align:center; font-size:0.72rem; color:#888;
    border-top:1px dashed #ccc; padding-top:0.4rem;
}

@media (max-width:900px) {
    .converter-box { width:100vw; max-width:100vw; border-radius:0; }
    .conv-table { font-size:0.68rem; }
    .conv-table th { padding:0.2rem 0.15rem; }
    .conv-dim-inputs input { width:40px !important; }
}

/* ===== Tiered Pricing (阶梯报价) ===== */

/* Form: tier template picker in product section header */
.tier-template-picker {
    display:flex; align-items:center; gap:0.4rem; margin-right:auto;
    font-size:0.8rem;
}
.tier-template-label { color:#555; white-space:nowrap; }
.tier-template-select { width:auto; min-width:120px; padding:0.25rem 0.4rem; font-size:0.8rem; }

/* Form: tier toggle button in product row actions */
.product-table .row-actions { display:flex; gap:0.25rem; align-items:center; }
.btn-tier-toggle {
    border:1px solid var(--primary-dark); color:var(--primary-dark);
    background:#fff; border-radius:var(--radius-sm);
    padding:0.15rem 0.5rem; font-size:0.72rem; cursor:pointer; white-space:nowrap;
}
.btn-tier-toggle.active {
    background:var(--primary-dark); color:#fff;
}

/* Form: hidden tier input row */
.product-tier-row .tier-cell { padding:0.4rem 0.5rem 0.5rem; background:#f7f9fc; border:1px solid #e3e8ef; border-top:none; }
.tier-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:0.35rem; }
.tier-head .tier-title { font-size:0.78rem; font-weight:600; color:var(--primary-dark); }
.tier-input-table { width:100%; border-collapse:collapse; font-size:0.78rem; }
.tier-input-table th { text-align:left; font-size:0.72rem; color:#666; padding:0.2rem 0.3rem; border-bottom:1px solid #dde3ea; }
.tier-input-table td { padding:0.2rem 0.3rem; }
.tier-input-table input { width:100%; padding:0.2rem 0.35rem; font-size:0.78rem; border:1px solid #cfd8e3; border-radius:var(--radius-sm); }

/* Preview: inline tiers inside product row price cell */
.doc-table .tier-inline { margin-top:0.35rem; border-top:1px dashed #c9d2dd; padding-top:0.3rem; }
.doc-table .tier-line { display:flex; justify-content:space-between; gap:0.4rem; font-size:0.7rem; line-height:1.5; color:#444; }
.doc-table .tier-line .tier-r { color:#777; }
.doc-table .tier-line .tier-p { font-weight:600; color:var(--primary-dark); }

/* Preview: bottom tier discount appendix */
.doc-tier-appendix { margin-top:0.6rem; }
.doc-tier-table { font-size:0.76rem; }
.doc-tier-table th { font-size:0.72rem; }
.doc-tier-table td { padding:0.3rem 0.4rem; }
.doc-tier-note { margin-top:0.35rem; font-size:0.68rem; color:#888; font-style:italic; }

/* Anti-split for tier appendix rows (print + PDF) */
.doc-tier-table tr { break-inside:avoid; page-break-inside:avoid; }
.doc-tier-appendix, .doc-tier-note { break-inside:avoid; page-break-inside:avoid; }

@media print {
    .doc-tier-table thead { display:table-header-group; }
}

/* ===== Product Library Modal ===== */
.pl-card { max-width: 1060px; width: 94%; }

.pl-toolbar { display:flex; align-items:center; gap:0.5rem; flex-wrap:wrap; margin-bottom:0.75rem; }
.pl-search { flex:1; min-width:180px; padding:0.45rem 0.7rem; border:1px solid #cfd8e3; border-radius:var(--radius-sm); font-size:0.85rem; font-family:var(--font); }
.pl-cat-select { padding:0.45rem 0.5rem; border:1px solid #cfd8e3; border-radius:var(--radius-sm); font-size:0.85rem; font-family:var(--font); background:#fff; max-width:180px; }
.pl-toolbar-btns { display:flex; gap:0.4rem; flex-wrap:wrap; }

.pl-list-wrap { border:1px solid var(--border); border-radius:var(--radius-sm); overflow:hidden auto; max-height:340px; background:#fff; }
.pl-list { width:100%; }
.pl-table { width:100%; border-collapse:collapse; font-size:0.82rem; }
.pl-table th { position:sticky; top:0; background:#f5f7fa; color:#333; font-size:0.74rem; text-align:left; padding:0.45rem 0.5rem; border-bottom:1px solid var(--border); white-space:nowrap; z-index:1; }
.pl-table td { padding:0.4rem 0.5rem; border-bottom:1px solid var(--border-light); vertical-align:middle; }
.pl-table tr:hover td { background:#f8fafd; }
.pl-thumb { width:44px; height:44px; object-fit:cover; border-radius:6px; border:1px solid var(--border); display:block; }
.pl-thumb-empty { width:44px; height:44px; border-radius:6px; border:1px dashed #ccc; display:flex; align-items:center; justify-content:center; color:#aaa; font-size:1.1rem; background:#fafafa; }
.pl-name-cell { font-weight:600; color:var(--text); max-width:220px; }
.pl-name-cell .pl-cat-tag { display:inline-block; margin-left:0.35rem; font-size:0.68rem; font-weight:500; color:var(--primary-dark); background:var(--primary-light); border-radius:4px; padding:0 0.35rem; vertical-align:middle; }
.pl-spec-cell { max-width:260px; white-space:pre-line; color:#666; font-size:0.74rem; line-height:1.45; }
.pl-price-cell { font-weight:600; color:var(--primary-dark); white-space:nowrap; }
.pl-tiers-cell { font-size:0.72rem; color:#777; white-space:nowrap; }
.pl-ops { white-space:nowrap; }
.pl-ops button { border:1px solid var(--border); background:#fff; border-radius:6px; padding:0.15rem 0.5rem; font-size:0.74rem; cursor:pointer; color:var(--text); }
.pl-ops button:hover { background:#f0f4f9; }
.pl-ops .pl-op-del { color:var(--danger); }
.pl-empty { padding:2.2rem 1rem; text-align:center; color:var(--text-muted); font-size:0.85rem; }
.pl-count { padding:0.35rem 0.6rem; font-size:0.72rem; color:#888; border-top:1px solid var(--border-light); background:#fafbfc; }

/* Product library edit form */
.pl-edit-section { margin-top:0.9rem; border:1px solid var(--border); border-radius:var(--radius-sm); padding:0.75rem; background:#fcfdfe; }
.pl-edit-section h4 { font-size:0.9rem; color:var(--primary-dark); margin-bottom:0.6rem; }
.pl-edit-grid { display:grid; grid-template-columns:repeat(4, 1fr); gap:0.55rem 0.6rem; }
.pl-edit-grid .full { grid-column:1 / -1; }

/* Structured spec grid inside the product library edit form */
.pl-spec-block { margin-top:0.85rem; padding-top:0.7rem; border-top:1px dashed var(--border); }
.pl-block-title { font-size:0.85rem; font-weight:600; color:var(--primary-dark); margin-bottom:0.4rem; display:flex; align-items:baseline; gap:0.5rem; }
.pl-block-sub { font-size:0.7rem; color:var(--text-light); font-weight:400; }
.pl-spec-grid { display:grid; grid-template-columns:repeat(4, 1fr); gap:0.45rem 0.55rem; }
.pl-spec-grid .spec-field label { font-size:0.72rem; }
.pl-spec-grid .spec-field input { padding:0.28rem 0.38rem; }

/* Price input + currency dropdown + equivalent preview */
.pl-price-row { display:flex; gap:0.3rem; align-items:stretch; }
.pl-ccy-select { flex:0 0 86px; padding:0.25rem 0.3rem; font-weight:600; }
.pl-price-equiv { font-size:0.7rem; color:var(--text-light); margin-top:0.2rem; min-height:1em; font-weight:500; }
.pl-price-equiv.has-value { color:var(--primary-dark); }

/* FX status bar in product library toolbar */
.pl-fx-bar { display:flex; align-items:center; gap:0.6rem; padding:0.4rem 0.6rem; margin:0.6rem 0; background:linear-gradient(90deg,#f5f9ff,#e8f1ff); border:1px solid #cfd8e3; border-radius:var(--radius-sm); font-size:0.78rem; }
.pl-fx-label { font-weight:600; color:var(--primary-dark); white-space:nowrap; }
.pl-fx-info { flex:1; color:var(--text); font-family:'Consolas','Menlo',monospace; }
.pl-fx-info.is-stale { color:#c62828; font-style:italic; }
.pl-fx-info.is-loading { color:var(--text-light); font-style:italic; }
.pl-img-field { display:flex; flex-direction:column; gap:0.3rem; align-items:flex-start; }
.pl-img-field > label { font-size:0.72rem; color:var(--text-light); }
.pl-img-wrap { width:86px; height:86px; border:1px dashed #c5cdd8; border-radius:var(--radius-sm); display:flex; align-items:center; justify-content:center; overflow:hidden; background:#fff; cursor:pointer; }
.pl-img-wrap:hover { border-color:var(--primary); }
.pl-img-wrap img { width:100%; height:100%; object-fit:cover; }
.pl-img-empty { font-size:1.6rem; color:#bbb; }

.pl-tier-block { margin-top:0.65rem; }
.pl-tier-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:0.3rem; }
.pl-tier-head label { font-size:0.78rem; font-weight:600; color:var(--text-light); }
.pl-tier-table { width:100%; border-collapse:collapse; font-size:0.8rem; max-width:480px; }
.pl-tier-table th { text-align:left; font-size:0.72rem; color:#666; padding:0.2rem 0.35rem; border-bottom:1px solid #dde3ea; }
.pl-tier-table td { padding:0.25rem 0.35rem; }
.pl-tier-table input { width:90px; padding:0.25rem 0.4rem; font-size:0.8rem; border:1px solid #cfd8e3; border-radius:var(--radius-sm); font-family:var(--font); }
.pl-tier-table .pl-tier-del { border:1px solid var(--border); background:#fff; border-radius:6px; padding:0.1rem 0.45rem; cursor:pointer; color:var(--danger); font-size:0.74rem; }
.pl-edit-actions { display:flex; gap:0.5rem; margin-top:0.75rem; }

/* ===== Product picker dropdown (in quotation form) ===== */
.p-name-wrap { display:flex; align-items:center; gap:0.25rem; }
.p-name-wrap .p-name { flex:1; }
.p-lib-btn { flex:none; width:24px; height:24px; border:1px solid var(--border); background:#fff; border-radius:6px; cursor:pointer; font-size:0.78rem; line-height:1; color:#777; padding:0; }
.p-lib-btn:hover { background:var(--primary-light); border-color:var(--primary); }

.pl-picker { position:fixed; z-index:10001; width:320px; max-width:92vw; background:#fff; border:1px solid var(--border); border-radius:var(--radius-sm); box-shadow:var(--shadow-lg); overflow:hidden; }
.pl-picker-search { width:100%; padding:0.45rem 0.65rem; border:none; border-bottom:1px solid var(--border-light); font-size:0.84rem; font-family:var(--font); outline:none; }
.pl-picker-list { max-height:260px; overflow:auto; }
.pl-picker-item { display:flex; align-items:center; gap:0.5rem; padding:0.45rem 0.6rem; cursor:pointer; border-bottom:1px solid var(--border-light); }
.pl-picker-item:hover { background:#f4f8fd; }
.pl-picker-item:last-child { border-bottom:none; }
.pl-pi-icon { width:34px; height:34px; flex:none; border-radius:5px; border:1px solid var(--border); object-fit:cover; display:flex; align-items:center; justify-content:center; background:#fafafa; font-size:0.95rem; }
.pl-pi-main { flex:1; min-width:0; }
.pl-pi-name { font-size:0.8rem; font-weight:600; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.pl-pi-meta { font-size:0.7rem; color:#999; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.pl-pi-price { flex:none; font-size:0.78rem; font-weight:600; color:var(--primary-dark); }
.pl-picker-empty { padding:1rem; text-align:center; color:var(--text-muted); font-size:0.8rem; }
.pl-picker-manage { display:block; width:100%; padding:0.5rem; background:#f5f7fa; border:none; border-top:1px solid var(--border-light); color:var(--primary); font-size:0.8rem; cursor:pointer; font-family:var(--font); }
.pl-picker-manage:hover { background:#eef3f9; }

@media (max-width:800px) {
    .pl-edit-grid { grid-template-columns:repeat(2, 1fr); }
    .pl-spec-grid { grid-template-columns:repeat(2, 1fr); }
    .pl-card { width:98%; }
    .pl-spec-cell { display:none; }
    .pl-tiers-cell { display:none; }
    .pl-toolbar-btns { width:100%; }
}

/* ===== Quote memory: auto-filled values + candidate switcher ===== */

/* Brief highlight on every field the memory engine wrote into. */
.mem-flash {
    animation: memFlash 1.2s ease-out;
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px rgba(245, 124, 0, 0.18);
}

@keyframes memFlash {
    0%   { background: #fff3e0; }
    70%  { background: #fff8f0; }
    100% { background: transparent; box-shadow: none; }
}

.mem-pop {
    position: fixed;
    z-index: 10002;
    width: 330px;
    max-width: 92vw;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    font-family: var(--font);
}

.mem-pop-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
}

.mem-pop-title { font-size: 0.8rem; font-weight: 600; }
.mem-pop-count { font-size: 0.7rem; opacity: 0.85; white-space: nowrap; }

.mem-pop-list { max-height: 190px; overflow: auto; }

.mem-pop-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.45rem 0.7rem;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-light);
    font-family: var(--font);
    text-align: left;
    cursor: pointer;
}

.mem-pop-item:last-child { border-bottom: none; }
.mem-pop-item:hover { background: #f4f8fd; }
.mem-pop-item.is-active { background: var(--primary-light); }

.mem-pop-meta {
    flex: 1;
    min-width: 0;
    font-size: 0.75rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mem-pop-len {
    flex: none;
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    background: #eef2f7;
    color: var(--text-light);
    font-size: 0.7rem;
}

.mem-pop-price {
    flex: none;
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.mem-pop-foot {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    border-top: 1px solid var(--border-light);
    background: #fafbfc;
}

.mem-pop-undo {
    flex: 1;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text-light);
    font-size: 0.76rem;
    font-family: var(--font);
    cursor: pointer;
}

.mem-pop-undo:hover { border-color: var(--danger); color: var(--danger); }

.mem-pop-ok {
    flex: 1;
    padding: 0.35rem 0.5rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 0.76rem;
    font-family: var(--font);
    cursor: pointer;
}

.mem-pop-ok:hover { background: var(--primary-dark); }

/* ===== Backup & cloud sync ===== */

.sync-card { margin-top: 1rem; }

.sync-check {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0.25rem 0 0.5rem;
    font-size: 0.85rem;
    color: var(--text-light);
    cursor: pointer;
}

.sync-check input { width: 15px; height: 15px; accent-color: var(--primary); }

.sync-status {
    margin: 0.35rem 0 0.65rem;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    background: #f2f4f7;
    color: var(--text-light);
    font-size: 0.8rem;
}

.sync-status.is-ok { background: #e8f5e9; color: var(--success); }

.sync-help {
    margin-top: 0.75rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: #fafbfc;
    overflow: hidden;
}

.sync-help summary {
    padding: 0.45rem 0.7rem;
    font-size: 0.8rem;
    color: var(--primary);
    cursor: pointer;
    user-select: none;
}

.sync-help pre {
    margin: 0;
    padding: 0.7rem;
    border-top: 1px solid var(--border-light);
    background: #1f2430;
    color: #d7e0ee;
    font-size: 0.74rem;
    line-height: 1.55;
    overflow-x: auto;
}

