:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --danger: #dc2626;
    --border: #e5e7eb;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
.topbar { position: sticky; top: 0; z-index: 900; display: flex; align-items: center; gap: 18px; padding: 12px 20px; background: #111827; color: white; box-shadow: 0 4px 18px rgba(15, 23, 42, .18); }
.brand { font-weight: 700; white-space: nowrap; }
.nav { display: flex; flex-wrap: nowrap; gap: 10px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.nav a { flex: 0 0 auto; padding: 7px 9px; border-radius: 8px; color: #e5e7eb; }
.nav a:hover { background: #374151; color: white; }
.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
h1 { margin: 0 0 18px; }
h2 { margin-top: 0; }
.panel, .card, .login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: 0 2px 8px rgba(15,23,42,.04); }
.grid { display: grid; gap: 14px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 18px; }
.card .label { color: var(--muted); font-size: 14px; }
.card .value { font-size: 28px; font-weight: 700; margin-top: 8px; }
.login-card { max-width: 420px; margin: 80px auto; }
label { display: block; margin: 12px 0 6px; color: var(--muted); }
input, select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: white; }
.inline-form { display: flex; gap: 10px; align-items: end; margin-bottom: 16px; }
.inline-form input, .inline-form select { width: auto; min-width: 220px; }
.btn { border: 1px solid var(--border); background: white; padding: 10px 14px; border-radius: 10px; cursor: pointer; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-light { background: #374151; border-color: #4b5563; color: white; }
button:disabled, input:disabled, select:disabled { opacity: .6; cursor: not-allowed; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; border-bottom: 1px solid var(--border); padding: 10px 8px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.messages { margin-bottom: 16px; }
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 8px; background: #eff6ff; border: 1px solid #bfdbfe; }
.alert-danger { background: #fef2f2; border-color: #fecaca; }
.alert-warning { background: #fffbeb; border-color: #fde68a; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; }
.muted { color: var(--muted); }

.import-form { max-width: 520px; }
.small-value { font-size: 18px !important; }
.log-box { background: #111827; color: #e5e7eb; padding: 14px; border-radius: 10px; overflow: auto; max-height: 320px; white-space: pre-wrap; }

.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); background: #f9fafb; }
.badge-running, .badge-queued { background: #eff6ff; border-color: #bfdbfe; }
.badge-success { background: #ecfdf5; border-color: #a7f3d0; }
.badge-failed, .badge-cancelled { background: #fef2f2; border-color: #fecaca; }
.badge-partial { background: #fffbeb; border-color: #fde68a; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.run-log { background: #111827; color: #e5e7eb; padding: 12px; border-radius: 10px; white-space: pre-wrap; max-height: 300px; overflow: auto; }
.run-error { background: #7f1d1d; color: #fee2e2; padding: 12px; border-radius: 10px; white-space: pre-wrap; }

.actions-cell { min-width: 150px; }
.actions-cell form { display: inline-block; margin: 0 4px 6px 0; }
.badge-confirmed_manual { background: #ecfdf5; border-color: #a7f3d0; }
.badge-needs_review { background: #fffbeb; border-color: #fde68a; }
.badge-weak_candidate { background: #f9fafb; border-color: #d1d5db; }
.badge-rejected { background: #fef2f2; border-color: #fecaca; }
.badge-no_match { background: #f3f4f6; border-color: #d1d5db; }

.filters-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.filters-form label { margin-top: 0; }
.checkbox-line { display: flex; flex-direction: column; gap: 8px; }
.checkbox-line label { color: var(--text); margin: 0; display: flex; gap: 8px; align-items: center; }
.checkbox-line input { width: auto; }
.filter-actions { display: flex; gap: 8px; align-items: end; }
.report-cards .card { display: block; }
.table-header { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.table-scroll { overflow-x: auto; }
.report-table { min-width: 1500px; }
.report-table th { white-space: nowrap; }
.report-table td { min-width: 90px; }
.badge-report-our_more_expensive { background: #fef2f2; border-color: #fecaca; }
.badge-report-our_cheaper { background: #ecfdf5; border-color: #a7f3d0; }
.badge-report-same_price { background: #eff6ff; border-color: #bfdbfe; }
.badge-report-needs_review { background: #fffbeb; border-color: #fde68a; }
.badge-report-no_match,
.badge-report-no_our_product,
.badge-report-no_retailer_product,
.badge-report-no_price { background: #f3f4f6; border-color: #d1d5db; }
.badge-report-out_of_stock { background: #fef2f2; border-color: #fecaca; }

.badge-ok { background: #ecfdf5; border-color: #a7f3d0; }
.badge-warning { background: #fffbeb; border-color: #fde68a; }
.badge-error { background: #fef2f2; border-color: #fecaca; }

.progress-wrap { margin: 12px 0 18px; }
.progress-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; color: var(--muted); }
.progress-bar { width: 100%; height: 14px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .25s ease; }
.compact-cards { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); margin-bottom: 14px; }

.manual-match-form { margin-top: 14px; }
.form-grid { display: grid; gap: 14px; margin-bottom: 12px; }
.two-cols { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.manual-match-form select { min-height: 44px; }

/* Matching manual pairing UX */
.btn-sm {
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.2;
}
.actions-cell {
    min-width: 180px;
}
.action-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
}
.action-stack form {
    display: inline-block;
    margin: 0;
}
.action-stack .btn,
.match-pick-btn {
    white-space: nowrap;
}
.match-pick-btn {
    font-weight: 600;
}
.selected-product-card {
    margin: 12px 0 16px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f9fafb;
}
.selected-product-card .label {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 6px;
}
.manual-filter-form {
    margin: 12px 0 14px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fcfcfd;
}
.manual-match-form {
    margin-top: 14px;
}
.manual-match-form select[size] {
    min-height: 220px;
}
.manual-select-block {
    margin-bottom: 12px;
}
.small-note {
    font-size: 13px;
    margin-top: 6px;
}

/* Unified matching table */
.matching-summary-cards {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.matching-table td:nth-child(1) { min-width: 130px; }
.matching-table td:nth-child(4) { min-width: 100px; white-space: nowrap; }
.badge-matched { background: #ecfdf5; border-color: #a7f3d0; }
.matched-row { background: #fbfdfb; }
.matched-row td { opacity: .88; }
#our-matches .table-scroll { max-height: none; }

/* Final matching tab polish */
.panel {
    margin-bottom: 18px;
}
.matching-summary-cards {
    margin-top: 18px;
    margin-bottom: 18px;
}
#matching-run-panel,
#manual-pair,
#our-matches {
    scroll-margin-top: 18px;
}
.run-panel-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.run-panel-actions form {
    margin: 0;
}
#matching-run-log {
    margin-top: 12px;
}
#our-matches {
    margin-top: 18px;
}
.action-stack .btn-primary + .match-pick-btn,
.action-stack .match-pick-btn {
    margin-top: 0;
}

/* Our products page */
.products-filter-panel { margin-bottom: 18px; }
.products-table-panel { margin-top: 0; }
.products-table th, .products-table td { vertical-align: middle; }
.clickable-table .clickable-row {
    cursor: pointer;
    transition: background .18s ease, transform .18s ease, box-shadow .18s ease;
}
.clickable-table .clickable-row:hover {
    background: #f8fbff;
    box-shadow: inset 3px 0 0 var(--primary), 0 6px 18px rgba(37, 99, 235, .08);
    transform: translateY(-1px);
}
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}
.pagination-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

body.modal-open { overflow: hidden; }
.modal-backdrop[hidden] {
    display: none !important;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(15, 23, 42, .58);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 36px 20px;
    overflow-y: auto;
}
.product-modal {
    width: min(1120px, 100%);
    background: #fff;
    border-radius: 18px;
    border: 1px solid var(--border);
    box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
    padding: 24px;
    position: relative;
}
.modal-close {
    position: absolute;
    top: 14px;
    right: 16px;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}
.modal-close:hover { background: #f3f4f6; }
.modal-section {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}
.modal-section h3 { margin: 0 0 12px; }
.modal-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 12px;
}
.modal-info-grid.three { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.info-card {
    border: 1px solid var(--border);
    background: #f9fafb;
    border-radius: 12px;
    padding: 12px;
}
.info-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 5px;
}
.info-card strong { font-size: 18px; }
.price-chart {
    width: 100%;
    height: 220px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    margin: 8px 0 12px;
}
.mini-table-wrap {
    max-height: 260px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
}
.mini-table th, .mini-table td { padding: 8px 10px; }

/* Multi-source product price chart */
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 10px 0 12px;
}
.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f9fafb;
    cursor: pointer;
    user-select: none;
    font-size: 14px;
}
.chart-legend-item:hover {
    background: #f3f6ff;
}
.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    display: inline-block;
}
.competitor-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}
.competitor-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    padding: 14px;
}
.competitor-card-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 10px;
}
.competitor-card-header strong {
    font-size: 20px;
    white-space: nowrap;
}
.competitor-name {
    font-weight: 700;
    margin-bottom: 5px;
}
.compact-grid {
    margin-top: 10px;
}
.compact-grid .info-card {
    padding: 10px;
}
.compact-grid .info-card strong {
    font-size: 15px;
}

/* Report page polish */
.report-filter-panel {
    max-width: 1280px;
}
.field-help {
    color: var(--muted);
    font-size: 12px;
    margin-top: 5px;
    line-height: 1.25;
}
.report-wide-panel {
    width: min(1920px, calc(100vw - 48px));
    margin-left: 50%;
    transform: translateX(-50%);
}
.report-table-scroll {
    overflow: auto;
    max-height: calc(100vh - 260px);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.report-table {
    min-width: 1840px;
}
.report-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fff;
}
.report-table th,
.report-table td {
    padding: 12px 10px;
}
.report-table td:nth-child(2),
.report-table td:nth-child(4) {
    min-width: 300px;
}
.report-table td:nth-child(9) {
    min-width: 130px;
}
.sort-link {
    color: var(--muted);
    display: inline-flex;
    gap: 4px;
    align-items: center;
    white-space: nowrap;
}
.sort-link:hover {
    color: var(--primary);
}
.sort-indicator {
    color: var(--primary);
    font-weight: 700;
}
.disabled-btn {
    opacity: .45;
    cursor: not-allowed;
    pointer-events: none;
}

.report-ajax-panel {
    min-height: 220px;
}
.report-table-loading {
    padding: 24px;
    color: #6b7280;
}
#report-table-container.is-loading {
    opacity: 0.72;
}

/* Settings page */
.settings-section {
    margin-bottom: 24px;
}

.settings-section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.settings-section-header h2,
.settings-parser-header h3 {
    margin: 0;
}

.settings-summary-grid,
.readiness-mini-cards {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.settings-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    align-items: end;
}

.settings-form-grid-wide {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.settings-field-wide {
    grid-column: 1 / -1;
}

.settings-form-actions {
    display: flex;
    align-items: end;
    gap: 10px;
}

.checkbox-card,
.switch-line {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid #e1e7ef;
    border-radius: 12px;
    background: #fff;
    color: #233044;
    cursor: pointer;
}

.checkbox-card:hover,
.switch-line:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.checkbox-card input,
.switch-line input {
    width: auto;
}

.settings-readonly-card {
    padding: 14px 16px;
    border: 1px solid #e1e7ef;
    border-radius: 14px;
    background: #f8fafc;
}

.settings-code-line {
    margin: 6px 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    word-break: break-all;
}

.settings-table-scroll {
    width: 100%;
    overflow-x: auto;
}

.settings-table-scroll input,
.settings-table-scroll select {
    min-width: 130px;
}

.settings-parser-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 18px;
}

.settings-parser-card {
    border: 1px solid #e1e7ef;
    border-radius: 16px;
    padding: 18px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}

.settings-parser-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 14px;
}

.settings-parser-fields {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

@media (max-width: 760px) {
    .settings-section-header,
    .settings-parser-header {
        flex-direction: column;
    }

    .settings-parser-grid {
        grid-template-columns: 1fr;
    }
}

/* Settings page visual polish v2 */
.settings-overview-panel {
    padding: 20px 22px;
}

.settings-section {
    margin-bottom: 22px;
}

.settings-section-header {
    align-items: flex-start;
    margin-bottom: 18px;
}

.settings-section-header h2 {
    font-size: 24px;
    line-height: 1.2;
    margin-bottom: 6px;
}

.settings-section-header .muted {
    margin: 0;
}

.settings-summary-grid,
.readiness-mini-cards,
.settings-mini-cards {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 0;
}

.settings-summary-card {
    padding: 16px 18px;
    min-height: 104px;
}

.settings-summary-card .label {
    font-size: 14px;
    line-height: 1.25;
}

.settings-summary-card .value,
.settings-summary-card .value.small {
    font-size: 22px;
    line-height: 1.22;
    margin-top: 8px;
    word-break: break-word;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.settings-fields-grid {
    display: grid;
    gap: 16px;
    align-items: start;
}

.settings-fields-1 {
    grid-template-columns: 1fr;
}

.settings-fields-2 {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.settings-fields-4 {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.settings-fields-3 {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.settings-field-checkbox {
    min-height: 48px;
    align-self: end;
}

.settings-field label {
    margin-top: 0;
}

.settings-form-actions {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding-top: 2px;
}

.settings-checkbox-group {
    padding-top: 2px;
}

.settings-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
}

.checkbox-card,
.switch-line {
    min-height: 44px;
    margin: 0;
    padding: 10px 13px;
    font-size: 15px;
}

.checkbox-card input,
.switch-line input,
.settings-check-cell input {
    width: auto;
    min-width: auto;
}

.settings-readonly-card {
    margin-top: 2px;
}

.settings-table-scroll {
    margin-top: 4px;
}

.settings-table th,
.settings-table td {
    padding: 11px 10px;
}

.settings-table th {
    white-space: nowrap;
}

.settings-table input,
.settings-table select {
    min-width: 150px;
}

.settings-region-table-wrap input {
    min-width: 170px;
}

.settings-check-cell {
    width: 80px;
    text-align: center;
}

.settings-parser-grid {
    grid-template-columns: repeat(auto-fit, minmax(480px, 1fr));
    gap: 16px;
}

.settings-parser-card {
    padding: 16px;
}

.settings-parser-header h3 {
    font-size: 20px;
    line-height: 1.2;
}

.settings-parser-header {
    align-items: flex-start;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.settings-details-section summary {
    cursor: pointer;
}

@media (max-width: 760px) {
    .settings-summary-card .value,
    .settings-summary-card .value.small {
        font-size: 20px;
    }

    .settings-fields-4,
    .settings-fields-3,
    .settings-fields-2,
    .settings-parser-grid,
    .settings-checkbox-grid {
        grid-template-columns: 1fr;
    }
}

/* Settings: retailer/region architecture */
.settings-subpanel {
    margin-top: 18px;
    padding: 18px;
    border: 1px solid #dfe5ee;
    border-radius: 16px;
    background: #fbfcff;
}

.settings-subpanel h3,
.settings-card-title {
    margin: 0 0 12px;
    font-size: 18px;
    font-weight: 700;
    color: #1f2937;
}

.settings-retailer-region-add-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 14px;
    margin-top: 16px;
}

.settings-retailer-region-card {
    border: 1px solid #dfe5ee;
    border-radius: 14px;
    background: #fff;
    padding: 14px;
}

.settings-inline-checkbox {
    align-self: end;
    min-height: 48px;
}

.settings-region-settings-table th,
.settings-region-settings-table td {
    vertical-align: top;
}

.settings-retailer-region-cell {
    min-width: 540px;
}

.settings-retailer-region-fields {
    margin-top: 10px;
}

.settings-table-field label,
.settings-retailer-region-fields label {
    font-size: 12px;
    margin-bottom: 4px;
}

.settings-table-field input,
.settings-retailer-region-fields input {
    min-height: 40px;
}

.settings-compact-checkbox {
    padding: 10px 12px;
    min-height: 42px;
}

/* Competitor source links in matching */
.source-link {
    display: inline-block;
    margin-top: 6px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
}
.source-link:hover {
    text-decoration: underline;
}
.manual-source-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.settings-form-disabled input,
.settings-form-disabled select,
.settings-form-disabled button {
    opacity: .62;
}

.settings-region-list {
    display: grid;
    gap: 18px;
}

.settings-region-card {
    padding: 18px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 18px;
    background: #fff;
}

.settings-region-card-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.settings-store-card {
    margin-top: 16px;
}

.settings-store-list {
    display: grid;
    gap: 12px;
    margin-top: 14px;
}

.settings-store-row {
    display: grid;
    grid-template-columns: minmax(110px, auto) minmax(120px, auto) 1.1fr 0.8fr 0.7fr 1.5fr;
    gap: 12px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    background: #f8fafc;
}

.settings-new-store-row {
    margin-top: 14px;
    padding: 14px;
    border: 1px dashed var(--border-color, #d1d5db);
    border-radius: 14px;
    background: #fff;
}

.settings-new-store-row h5 {
    margin: 0 0 12px;
    font-size: 16px;
}

@media (max-width: 1200px) {
    .settings-store-row {
        grid-template-columns: 1fr 1fr;
    }
}

.product-modal-image {
    max-width: 160px;
    max-height: 160px;
    object-fit: contain;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    background: #fff;
    padding: 8px;
}

.products-cleanup-panel {
    margin-top: 16px;
    border-color: #fecaca;
    background: #fffafa;
}
.cleanup-form {
    align-items: center;
}

.matching-run-counters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 12px;
}
.matching-run-counters span {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f9fafb;
    color: var(--muted);
    font-size: 13px;
}
.matching-run-counters strong {
    color: var(--text);
}

.settings-collapsible[hidden] {
    display: none !important;
}
.settings-store-list-flat {
    gap: 16px;
}
.settings-store-row-wide {
    grid-template-columns: 0.9fr 0.9fr 0.9fr 1.15fr 0.8fr 0.7fr 1.35fr minmax(100px, auto) minmax(110px, auto);
}
.settings-field-wide {
    min-width: 220px;
}
.settings-regions-table input,
.settings-store-row-wide input,
.settings-store-row-wide select {
    width: 100%;
}
@media (max-width: 1500px) {
    .settings-store-row-wide {
        grid-template-columns: 1fr 1fr 1fr;
    }
}
@media (max-width: 900px) {
    .settings-store-row-wide {
        grid-template-columns: 1fr;
    }
}

/* Users and roles */
.topbar-user {
    color: #e5e7eb;
    font-size: 14px;
    white-space: nowrap;
    padding: 7px 10px;
    border: 1px solid #374151;
    border-radius: 999px;
    background: rgba(255, 255, 255, .06);
}
.user-modal {
    width: min(920px, 100%);
}
.settings-subpanel {
    border: 1px dashed #cbd5e1;
    border-radius: 16px;
    padding: 16px 18px;
    background: #fcfdff;
}
.settings-subpanel h3 {
    margin-top: 0;
}

/* Settings visual cleanup: compact regions, stores and users */
.settings-entity-list {
    display: grid;
    gap: 12px;
    margin-top: 12px;
}
.settings-entity-row,
.settings-store-row-card {
    padding: 14px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 16px;
    background: #f8fafc;
}
.settings-entity-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
}
.settings-row-form {
    display: grid;
    grid-template-columns: minmax(260px, 1.2fr) minmax(160px, .45fr) auto;
    gap: 14px;
    align-items: end;
}
.settings-row-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-start;
}
.settings-delete-form {
    display: flex;
    align-items: end;
    justify-content: flex-end;
}
.settings-region-add-grid {
    grid-template-columns: minmax(260px, 1fr) minmax(180px, 0.45fr);
}
.settings-users-add-grid {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.settings-code-field .settings-code-line {
    min-height: 46px;
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0 12px;
    border: 1px solid #e1e7ef;
    border-radius: 12px;
    background: #fff;
}
.settings-store-row-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
}
.settings-store-form {
    display: grid;
    gap: 14px;
}
.settings-store-main-grid {
    grid-template-columns: minmax(135px, .85fr) minmax(135px, .85fr) minmax(120px, .7fr) minmax(180px, 1.1fr) minmax(120px, .7fr) minmax(110px, .65fr) minmax(105px, auto) minmax(115px, auto);
    align-items: end;
    gap: 12px;
}
.settings-store-checkbox {
    min-height: 46px;
    align-self: end;
}
.settings-parser-card .settings-fields-grid {
    gap: 18px 20px;
    margin-top: 4px;
}
.settings-parser-card .settings-checkbox-grid {
    gap: 14px;
    margin-top: 4px;
}
.settings-parser-card .checkbox-card {
    min-height: 48px;
}
.settings-parser-card .settings-parser-header {
    margin-bottom: 20px;
}
@media (max-width: 1400px) {
    .settings-store-main-grid {
        grid-template-columns: repeat(4, minmax(150px, 1fr));
    }
}
@media (max-width: 900px) {
    .settings-entity-row,
    .settings-store-row-card,
    .settings-row-form,
    .settings-region-add-grid,
    .settings-store-main-grid {
        grid-template-columns: 1fr;
    }
    .settings-delete-form,
    .settings-row-actions {
        justify-content: flex-start;
    }
}

/* Settings quick polish: active regions, store card containment, users hint cleanup */
.settings-row-form {
    grid-template-columns: minmax(260px, 1.2fr) minmax(160px, .45fr) minmax(125px, auto) auto;
}
.settings-region-active-checkbox {
    min-height: 46px;
    align-self: end;
    white-space: nowrap;
}
.settings-store-row-card,
.settings-store-form,
.settings-store-main-grid,
.settings-store-list-flat,
.settings-section {
    min-width: 0;
    box-sizing: border-box;
}
.settings-store-row-card {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}
.settings-store-row-card .settings-delete-form {
    min-width: 0;
}
.settings-store-main-grid > *,
.settings-store-main-grid input,
.settings-store-main-grid select,
.settings-store-form input,
.settings-store-form select {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}
.settings-store-row-card .settings-delete-form .btn-danger {
    max-width: 140px;
    white-space: normal;
}
@media (max-width: 1500px) {
    .settings-store-row-card {
        grid-template-columns: 1fr;
    }
    .settings-store-row-card .settings-delete-form {
        justify-content: flex-start;
    }
}
@media (max-width: 900px) {
    .settings-row-form {
        grid-template-columns: 1fr;
    }
}

.product-modal-image {
    cursor: zoom-in;
}

.image-lightbox[hidden] {
    display: none !important;
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: rgba(15, 23, 42, .78);
}

.image-lightbox-img {
    width: min(96vw, 1280px);
    height: min(92vh, 1080px);
    max-width: 96vw;
    max-height: 92vh;
    object-fit: contain;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, .45);
    padding: 12px;
}

.image-lightbox-close {
    position: fixed;
    top: 22px;
    right: 28px;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .55);
    background: rgba(255, 255, 255, .96);
    color: #111827;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    z-index: 1201;
}

@media (max-width: 700px) {
    .image-lightbox {
        padding: 10px;
    }
    .image-lightbox-img {
        width: 96vw;
        height: 90vh;
        padding: 8px;
        border-radius: 14px;
    }
    .image-lightbox-close {
        top: 12px;
        right: 12px;
    }
}

/* Parser run store task details */
.nested-table {
    margin-top: 10px;
    margin-bottom: 14px;
    background: #fff;
    font-size: 0.92rem;
}
.nested-table th,
.nested-table td {
    padding: 8px 10px;
}

.settings-retailer-readiness-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(320px, 2fr);
    gap: 16px;
    align-items: center;
}

@media (max-width: 900px) {
    .settings-retailer-readiness-row {
        grid-template-columns: 1fr;
    }
}

/* Matching quality summary */
.matching-quality-panel .table-header {
    align-items: flex-start;
}
.readiness-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}
.quality-progress {
    margin: 10px 0 18px;
}
.matching-quality-cards .card {
    color: inherit;
}
.matching-quality-cards a.card {
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.matching-quality-cards a.card:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(15,23,42,.08);
    border-color: #bfdbfe;
}

/* Patch: Chart.js price history and compact store actions */
.price-chart-wrap {
    position: relative;
    width: 100%;
    height: 340px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    padding: 12px 14px 10px;
    margin: 8px 0 12px;
    box-sizing: border-box;
}
.price-chart-wrap .price-chart {
    width: 100% !important;
    height: 100% !important;
    border: 0;
    border-radius: 0;
    margin: 0;
    background: transparent;
}
.price-chart-empty {
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 15px;
    text-align: center;
}
.settings-store-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 2px;
}
.settings-store-actions .settings-delete-form {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    margin: 0;
}
.settings-store-actions .btn {
    white-space: nowrap;
}
.settings-store-actions .btn-danger {
    max-width: none;
}
.settings-store-row-card .settings-store-actions .settings-delete-form .btn-danger {
    max-width: none;
    white-space: nowrap;
}
@media (max-width: 1500px) {
    .settings-store-row-card .settings-store-actions .settings-delete-form {
        justify-content: flex-start;
    }
}

.alert-success { background: #ecfdf5; border-color: #a7f3d0; }
.matching-ajax-message { margin: 0 0 16px; }
.ajax-confirmed-row { transition: background-color .2s ease; }

/* Matching async table and finalization progress */
.progress-fill-finalizing {
    animation: matching-progress-pulse 1.05s ease-in-out infinite;
}
@keyframes matching-progress-pulse {
    0% { opacity: .45; }
    50% { opacity: 1; }
    100% { opacity: .45; }
}
.matching-table-tools {
    display: flex;
    gap: 8px;
    align-items: end;
    flex-wrap: wrap;
}
.matching-table-tools input[type="search"] {
    min-width: 280px;
}
.matching-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}
.matching-pagination[hidden] {
    display: none !important;
}
#matching-rows-state {
    margin: 4px 0 0;
}


/* Extended report columns */
.report-table { min-width: 2550px; }
.report-table td:nth-child(2),
.report-table td:nth-child(7) { min-width: 320px; }
.report-table td:nth-child(8) { min-width: 220px; }
.report-table td:nth-child(15) { min-width: 210px; }

/* Patch 3: informative dashboard, bounded history and scalable settings lists */
.badge-no_data { background: #f3f4f6; border-color: #d1d5db; }
.dashboard-metric-grid {
    grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
}
.dashboard-metric-card {
    display: block;
    min-height: 155px;
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.dashboard-metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(15, 23, 42, .10);
    border-color: #bfdbfe;
}
.dashboard-metric-card.dashboard-status-ok { border-left: 4px solid #16a34a; }
.dashboard-metric-card.dashboard-status-warning { border-left: 4px solid #d97706; }
.dashboard-metric-card.dashboard-status-failed { border-left: 4px solid #dc2626; }
.dashboard-metric-card.dashboard-status-no_data { border-left: 4px solid #94a3b8; }
.dashboard-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}
.dashboard-date-value {
    font-size: 20px !important;
    line-height: 1.25;
}
.dashboard-card-note {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
    margin-top: 12px;
}
.dashboard-progress {
    height: 8px;
    margin-top: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: #e5e7eb;
}
.dashboard-progress span {
    display: block;
    height: 100%;
    max-width: 100%;
    border-radius: inherit;
    background: var(--primary);
}
.dashboard-last-run-panel { margin-top: 18px; }
.page-heading-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
.page-heading-row h1 { margin-bottom: 6px; }

.modal-section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 8px;
}
.modal-section-heading h3 { margin-bottom: 6px; }
.history-period-control {
    flex: 0 0 190px;
    min-width: 190px;
}
.history-period-control label {
    margin: 0 0 6px;
    font-size: 13px;
    font-weight: 600;
}
.history-period-control select { padding: 8px 10px; }
.history-period-control .muted {
    display: block;
    min-height: 18px;
    margin-top: 4px;
    font-size: 12px;
}

.progressive-list-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
[data-progressive-item][hidden] { display: none !important; }

@media (max-width: 720px) {
    .modal-section-heading,
    .page-heading-row,
    .progressive-list-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .history-period-control {
        flex-basis: auto;
        min-width: 0;
        width: 100%;
    }
}

/* Retailer-aware store setup */
.settings-store-create-form {
    display: grid;
    gap: 18px;
}
.settings-store-step {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #fff;
}
.settings-store-step-heading {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.settings-store-step-heading p {
    margin: 4px 0 0;
}
.settings-store-step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    color: #fff;
    background: #2563eb;
    font-weight: 700;
}
.settings-store-selector-grid {
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) minmax(130px, auto);
    align-items: end;
}
.settings-store-details-grid {
    grid-template-columns: repeat(4, minmax(180px, 1fr));
}
.settings-store-guide {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 16px;
    border: 1px solid #bfdbfe;
    border-radius: 14px;
    background: #eff6ff;
}
.settings-store-guide[hidden],
.settings-store-step[hidden],
.settings-field[hidden] {
    display: none !important;
}
.settings-store-guide p {
    margin: 4px 0 0;
    color: #475569;
}
.settings-store-guide-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    color: #1d4ed8;
    background: #dbeafe;
    font-weight: 800;
    font-family: Georgia, serif;
}
.settings-field-help {
    display: block;
    margin-top: 6px;
    color: #64748b;
    font-size: 12px;
    line-height: 1.35;
}
.settings-retailer-store-card {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: stretch;
    overflow: visible;
}
.settings-store-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e2e8f0;
}
.settings-store-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}
.settings-store-card-title {
    display: block;
    margin-bottom: 4px;
    font-size: 18px;
}
.settings-retailer-badge {
    color: #1e3a8a;
    background: #dbeafe;
}
.badge-muted {
    color: #475569;
    background: #e2e8f0;
}
.badge-warning {
    color: #92400e;
    background: #fef3c7;
}
.settings-store-edit-grid {
    grid-template-columns: repeat(4, minmax(170px, 1fr));
    align-items: end;
}
.settings-readonly-field {
    min-width: 0;
}
.settings-readonly-value {
    min-height: 46px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    color: #334155;
    background: #f1f5f9;
    box-sizing: border-box;
}
.settings-store-api-note {
    padding: 12px 14px;
    border-left: 4px solid #2563eb;
    border-radius: 8px;
    color: #334155;
    background: #eff6ff;
    font-size: 13px;
    line-height: 1.45;
}
.settings-retailer-store-card .settings-store-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
.settings-retailer-store-card .settings-delete-form {
    justify-content: flex-start;
}
.settings-store-card-bristol {
    border-left: 4px solid #2563eb;
}
.settings-store-card-magnit {
    border-left: 4px solid #dc2626;
}
@media (max-width: 1200px) {
    .settings-store-details-grid,
    .settings-store-edit-grid {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }
}
@media (max-width: 760px) {
    .settings-store-selector-grid,
    .settings-store-details-grid,
    .settings-store-edit-grid {
        grid-template-columns: 1fr;
    }
    .settings-store-step {
        padding: 14px;
    }
}

/* Bristol bulk store locator */
.bristol-entry-list {
    display: grid;
    gap: 12px;
    margin: 16px 0;
}

.bristol-entry-row {
    display: grid;
    grid-template-columns: minmax(220px, 0.9fr) minmax(300px, 1.4fr) auto;
    gap: 12px;
    align-items: end;
    padding: 14px;
    border: 1px solid var(--border, #dfe3e8);
    border-radius: 12px;
    background: var(--surface, #fff);
}

.bristol-entry-remove {
    margin-bottom: 1px;
}

.bristol-results-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin: 18px 0 10px;
}

.bristol-result-card {
    border: 1px solid var(--border, #dfe3e8);
    border-radius: 12px;
    padding: 14px;
    margin: 10px 0;
    background: var(--surface, #fff);
}

.bristol-result-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.bristol-candidate-list {
    display: grid;
    gap: 8px;
}

.bristol-candidate-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--border, #dfe3e8);
    border-radius: 10px;
    cursor: pointer;
}

.bristol-candidate-row:hover {
    border-color: var(--primary, #1d6fdc);
}

.bristol-candidate-row.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.bristol-status-danger {
    border-color: #d9534f;
}

.bristol-status-success {
    border-color: #2f9e44;
}

.bristol-status-warning {
    border-color: #e0a800;
}

@media (max-width: 900px) {
    .bristol-entry-row {
        grid-template-columns: 1fr;
    }

    .bristol-entry-remove {
        justify-self: start;
    }

    .bristol-result-title,
    .bristol-results-header {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* Unified retailer store management */
.settings-store-filter-bar {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(150px, 1fr));
    gap: 14px;
    margin: 18px 0;
}

.settings-store-compact-list {
    display: grid;
    gap: 10px;
}

.settings-store-compact-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 16px 18px;
    border: 1px solid var(--border-color, #d9e1ec);
    border-radius: 14px;
    background: #fff;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.settings-store-compact-row:hover {
    border-color: #8aaef5;
    box-shadow: 0 8px 22px rgba(35, 64, 120, .08);
    transform: translateY(-1px);
}

.settings-store-compact-main {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.settings-store-compact-main strong {
    font-size: 1.05rem;
    overflow-wrap: anywhere;
}

.settings-store-compact-arrow {
    flex: 0 0 auto;
    font-size: 2rem;
    line-height: 1;
    color: #6b778c;
}

.settings-store-modal {
    width: min(920px, calc(100vw - 32px));
}

.settings-store-modal .settings-store-actions {
    margin-top: 18px;
}

@media (max-width: 900px) {
    .settings-store-filter-bar {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 620px) {
    .settings-store-filter-bar {
        grid-template-columns: 1fr;
    }
}

/* Compact store directory and parser run history */
.settings-store-directory {
    margin-top: 18px;
    border: 1px solid var(--border-color, #d9e1ec);
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
}

.settings-store-directory-summary {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    padding: 16px 18px;
    cursor: pointer;
    background: #f8fafc;
}

.settings-store-directory-body {
    padding: 0 18px 18px;
}

.settings-store-compact-row {
    padding: 11px 14px;
    min-height: 50px;
}

.settings-store-line {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    flex-wrap: nowrap;
}

.settings-store-line strong,
.settings-store-line-meta {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.settings-store-line strong {
    max-width: 36vw;
}

.settings-store-line-meta {
    max-width: 30vw;
}

.settings-store-api-result {
    margin-top: 14px;
    padding: 12px 14px;
    border-left: 4px solid #2d6cdf;
    border-radius: 10px;
    background: #eef5ff;
}

.parser-run-launch-form {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(220px, 1fr) auto;
    gap: 14px;
    align-items: end;
}

.parser-run-card-list {
    display: grid;
    gap: 10px;
}

.parser-run-card {
    border: 1px solid var(--border-color, #d9e1ec);
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
}

.parser-run-card-summary {
    display: grid;
    grid-template-columns: 58px minmax(150px, 1.4fr) auto repeat(4, minmax(74px, .55fr)) minmax(170px, 1fr) 24px;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    cursor: pointer;
    list-style: none;
}

.parser-run-card-summary::-webkit-details-marker { display: none; }
.parser-run-card[open] .parser-run-card-summary { background: #f8fafc; border-bottom: 1px solid var(--border-color, #d9e1ec); }
.parser-run-card-id { font-weight: 700; color: #5b6678; }
.parser-run-card-name { display: grid; gap: 2px; min-width: 0; }
.parser-run-card-name strong, .parser-run-card-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.parser-run-stat { display: grid; text-align: center; gap: 1px; }
.parser-run-stat b { font-size: 1.02rem; }
.parser-run-stat small, .parser-run-card-time small { color: #6d7788; }
.parser-run-stat-error b { color: #c92a2a; }
.parser-run-card-time { display: grid; gap: 2px; }
.parser-run-card-chevron { font-size: 1.4rem; transition: transform .15s ease; }
.parser-run-card[open] .parser-run-card-chevron { transform: rotate(180deg); }
.parser-run-card-body { padding: 16px; }
.parser-run-actions { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.parser-run-task-list { display: grid; gap: 8px; }
.parser-run-task-row {
    display: grid;
    grid-template-columns: minmax(220px, 1.8fr) auto repeat(4, minmax(82px, .6fr)) minmax(180px, 1fr);
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid #e5eaf1;
    border-radius: 10px;
}
.parser-run-task-name { font-weight: 600; }
.parser-run-log-details { margin-top: 14px; }
.parser-run-log-details > summary { cursor: pointer; font-weight: 600; margin-bottom: 10px; }

@media (max-width: 1100px) {
    .settings-store-line { flex-wrap: wrap; }
    .settings-store-line strong, .settings-store-line-meta { max-width: 100%; }
    .parser-run-card-summary { grid-template-columns: 50px minmax(150px, 1fr) auto repeat(2, minmax(70px, .5fr)); }
    .parser-run-card-summary .parser-run-stat:nth-of-type(n+3) { display: none; }
    .parser-run-card-time { display: none; }
    .parser-run-task-row { grid-template-columns: 1fr auto repeat(2, minmax(80px, .5fr)); }
    .parser-run-task-row > span:nth-child(n+5) { display: none; }
}

@media (max-width: 720px) {
    .parser-run-launch-form { grid-template-columns: 1fr; }
    .parser-run-card-summary { grid-template-columns: 46px minmax(120px, 1fr) auto 22px; }
    .parser-run-card-summary .parser-run-stat { display: none; }
    .settings-store-directory-summary { align-items: flex-start; flex-direction: column; }
}

/* Patch 16: compact store candidate selector. Global form styles set inputs
   to width:100%; radios inside a candidate row must keep their native size. */
.bristol-candidate-row {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    justify-content: start;
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
}
.bristol-candidate-row input[type="radio"] {
    width: 16px;
    min-width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    align-self: center;
}
.bristol-candidate-row > span {
    min-width: 0;
    text-align: left;
    line-height: 1.35;
}

/* Patch 17: wide, readable data screens */
.container {
    max-width: 1660px;
    padding-left: 22px;
    padding-right: 22px;
}

.data-table-scroll {
    width: 100%;
    max-height: calc(100vh - 210px);
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    scrollbar-gutter: stable;
}
.data-table {
    min-width: 1380px;
    table-layout: auto;
}
.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #f8fafc;
    box-shadow: 0 1px 0 var(--border);
    white-space: nowrap;
}
.data-table th,
.data-table td {
    vertical-align: middle;
    padding: 12px 11px;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:nth-child(even) { background: #fbfcfe; }
.data-table tbody tr:hover { background: #f3f7ff; }
.nowrap-cell,
.money-cell { white-space: nowrap; }
.money-cell { text-align: right; font-variant-numeric: tabular-nums; }
.text-center { text-align: center !important; }
.best-price-cell { font-weight: 800; color: #0f766e; }
.product-name-cell { min-width: 360px; max-width: 520px; }
.product-name-cell strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.25;
}
.store-name-cell { min-width: 240px; max-width: 360px; }
.store-name-cell > span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.competitor-products-table th:nth-child(1),
.competitor-products-table td:nth-child(1) { min-width: 380px; }
.competitor-products-table th:nth-child(3),
.competitor-products-table td:nth-child(3) { min-width: 270px; }
.our-products-table th:nth-child(1),
.our-products-table td:nth-child(1) { min-width: 420px; }

.count-dot {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
    border: 1px solid transparent;
    font-variant-numeric: tabular-nums;
}
.count-dot-success { color: #047857; background: #d1fae5; border-color: #6ee7b7; }
.count-dot-muted { color: #64748b; background: #f1f5f9; border-color: #cbd5e1; }

/* Product card: one regional line by default, store details separately */
.product-modal { width: min(1240px, 100%); }
.product-card-hero {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr) minmax(180px, 240px);
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
    padding-right: 44px;
}
.product-image-button,
.product-image-placeholder {
    width: 112px;
    height: 132px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    padding: 8px;
}
.product-image-button { cursor: zoom-in; }
.product-image-button img { width: 100%; height: 100%; object-fit: contain; }
.product-image-placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.product-card-title-block h2 { margin: 4px 0 8px; line-height: 1.18; font-size: clamp(24px, 2.4vw, 34px); }
.product-card-kicker { color: var(--primary); font-weight: 700; }
.product-meta-line {
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hero-price-card {
    border: 1px solid #bfdbfe;
    background: linear-gradient(145deg, #eff6ff, #ffffff);
    border-radius: 16px;
    padding: 16px;
    text-align: right;
}
.hero-price-card span,
.hero-price-card small { display: block; color: var(--muted); }
.hero-price-card strong { display: block; font-size: 28px; margin: 6px 0; color: #0f172a; }
.product-price-grid { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.modal-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.history-controls {
    display: grid;
    grid-template-columns: minmax(170px, 1fr) minmax(220px, 1.4fr) minmax(130px, .7fr) auto;
    gap: 12px;
    align-items: end;
    margin: 12px 0 14px;
}
.history-control label { margin-top: 0; font-size: 13px; }
.history-loading-status { align-self: center; }
.price-chart { height: 300px; }
.availability-summary { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.availability-dot {
    width: 10px;
    height: 10px;
    display: inline-block;
    border-radius: 999px;
    margin-right: 7px;
}
.availability-dot-success { background: #10b981; }
.availability-dot-danger { background: #ef4444; }
.availability-dot-muted { background: #94a3b8; }
.store-price-table-wrap { max-height: 310px; }
.store-price-table th { position: sticky; top: 0; z-index: 2; background: #f8fafc; }
.store-table-name { min-width: 360px; max-width: 600px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-values-details { margin-top: 12px; }
.history-values-details summary { cursor: pointer; color: var(--muted); font-weight: 600; }

/* Reports: use the viewport, keep headers visible, reduce multi-line cells */
.report-filter-panel { max-width: none; }
.report-wide-panel {
    width: calc(100vw - 28px);
    max-width: 1920px;
}
.report-table-scroll {
    max-height: calc(100vh - 190px);
    scrollbar-gutter: stable;
}
.report-table {
    min-width: 2050px;
}
.report-table th,
.report-table td { vertical-align: middle; }
.report-product-cell { min-width: 340px; max-width: 460px; }
.report-product-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-weight: 700;
    line-height: 1.25;
}
.report-store-cell { min-width: 260px; max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.report-availability-cell { text-align: center; min-width: 92px; }

@media (max-width: 900px) {
    .container { padding-left: 12px; padding-right: 12px; }
    .product-card-hero { grid-template-columns: 84px minmax(0, 1fr); }
    .product-image-button, .product-image-placeholder { width: 84px; height: 104px; }
    .hero-price-card { grid-column: 1 / -1; text-align: left; }
    .product-price-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
    .history-controls { grid-template-columns: 1fr; }
    .product-meta-line { white-space: normal; }
}
.matching-data-table-scroll { max-height: calc(100vh - 210px); }
.matching-table { min-width: 1180px; }
.matching-table td:nth-child(2),
.matching-table td:nth-child(3) { min-width: 360px; }
.matching-product-cell {
    display: flex;
    align-items: baseline;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.matching-product-cell strong,
.matching-product-meta {
    overflow: hidden;
    text-overflow: ellipsis;
}
.matching-product-cell strong { flex: 0 1 auto; }
.matching-product-meta { flex: 1 1 auto; color: var(--muted); }
.settings-table-scroll {
    max-height: calc(100vh - 220px);
    overflow: auto;
    scrollbar-gutter: stable;
}
.settings-table-scroll .settings-table th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f8fafc;
}


/* Patch 18: compact reports, matching rows, dashboard scope and collapsible settings */
.report-filter-footer {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}
.compact-checkbox-line { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.compact-checkbox-line label { display: inline-flex; align-items: center; gap: 8px; margin: 0; white-space: nowrap; }
.compact-checkbox-line input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }
.report-filter-actions { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
.report-export-button { white-space: nowrap; min-width: 174px; justify-content: center; }

.report-table { min-width: 1900px; table-layout: fixed; }
.report-table th:nth-child(1), .report-table td:nth-child(1) { width: 118px; }
.report-table th:nth-child(2), .report-table td:nth-child(2) { width: 310px; }
.report-table th:nth-child(3), .report-table td:nth-child(3) { width: 100px; }
.report-table th:nth-child(4), .report-table td:nth-child(4) { width: 132px; text-align: center; }
.report-table th:nth-child(5), .report-table td:nth-child(5) { width: 108px; text-align: center; }
.report-table th:nth-child(6), .report-table td:nth-child(6) { width: 92px; text-align: center; }
.report-table th:nth-child(7), .report-table td:nth-child(7) { width: 310px; }
.report-table th:nth-child(8), .report-table td:nth-child(8) { width: 260px; }
.report-table th:nth-child(9), .report-table td:nth-child(9),
.report-table th:nth-child(10), .report-table td:nth-child(10),
.report-table th:nth-child(11), .report-table td:nth-child(11),
.report-table th:nth-child(12), .report-table td:nth-child(12) { width: 105px; }
.report-table th:nth-child(13), .report-table td:nth-child(13) { width: 162px; }
.report-table th:nth-child(14), .report-table td:nth-child(14) { width: 155px; text-align: center; }
.report-table th:nth-child(15), .report-table td:nth-child(15) { width: 84px; text-align: center; }
.report-table th:nth-child(16), .report-table td:nth-child(16) { width: 88px; text-align: center; }
.report-table th:nth-child(17), .report-table td:nth-child(17) { width: 150px; }
.report-table th:nth-child(18), .report-table td:nth-child(18) { width: 82px; text-align: center; }
.report-our-price-cell, .report-competitor-markup-cell { text-align: center !important; }
.report-product-cell { min-width: 0; max-width: none; }

.matching-data-table-scroll { max-height: calc(100vh - 225px); }
.matching-table { min-width: 1180px; table-layout: fixed; width: 100%; }
.matching-table th:nth-child(1), .matching-table td:nth-child(1) { width: 135px; }
.matching-table th:nth-child(2), .matching-table td:nth-child(2) { width: 36%; min-width: 0; }
.matching-table th:nth-child(3), .matching-table td:nth-child(3) { width: 36%; min-width: 0; }
.matching-table th:nth-child(4), .matching-table td:nth-child(4) { width: 105px; text-align: center; }
.matching-table th:nth-child(5), .matching-table td:nth-child(5) { width: 160px; }
.matching-table td { height: 78px; }
.matching-product-cell { display: block; min-width: 0; white-space: normal; }
.matching-product-cell strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.25;
    max-height: 2.5em;
}
.matching-product-meta {
    display: block;
    margin-top: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

.dashboard-heading-row { align-items: end; gap: 24px; }
.dashboard-scope-form {
    display: grid;
    grid-template-columns: minmax(170px, 220px) minmax(170px, 220px) auto;
    gap: 10px;
    align-items: end;
    min-width: min(100%, 560px);
}
.dashboard-scope-form label { margin-top: 0; font-size: 13px; }
.dashboard-scope-note { margin: -4px 0 16px; color: var(--muted); }
.dashboard-metric-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.settings-collapse-panel { padding: 0; overflow: visible; }
.settings-collapse-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 20px 22px;
    border-radius: inherit;
}
.settings-collapse-summary::-webkit-details-marker { display: none; }
.settings-collapse-summary > span:first-child { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.settings-collapse-summary strong { font-size: 24px; }
.settings-collapse-summary small { color: var(--muted); font-size: 14px; }
.settings-collapse-arrow { font-size: 24px; transition: transform .2s ease; }
.settings-collapse-panel[open] .settings-collapse-arrow { transform: rotate(180deg); }
.settings-collapse-panel[open] .settings-collapse-summary { border-bottom: 1px solid var(--border); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.settings-collapse-body { padding: 20px 22px 24px; }
.settings-collapse-toolbar { display: flex; justify-content: flex-end; margin-bottom: 16px; }

@media (max-width: 800px) {
    .report-filter-footer { align-items: stretch; }
    .report-filter-actions { flex-wrap: wrap; }
    .dashboard-scope-form { grid-template-columns: 1fr; width: 100%; }
    .settings-collapse-summary > span:first-child { display: block; }
    .settings-collapse-summary small { display: block; margin-top: 4px; }
}

/* Patch 19: parallel runtime, live parser history and compact report controls */
.parser-run-history-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
}
.parser-run-live-indicator {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    padding-top: 6px;
}

/* The report footer is one horizontal action strip on desktop. */
.report-filter-footer {
    flex-wrap: nowrap;
    min-width: 0;
}
.compact-checkbox-line {
    flex-direction: row !important;
    flex-wrap: nowrap;
    min-width: 0;
}
.compact-checkbox-line label {
    white-space: nowrap;
}
.report-filter-actions {
    flex: 0 0 auto;
    flex-wrap: nowrap !important;
}
.report-filter-actions .btn,
.report-export-button {
    white-space: nowrap;
}

/* Report header labels remain fully visible and use a tidy two-line header. */
.report-table thead tr {
    height: 62px;
}
.report-table thead th {
    height: 62px;
    min-height: 62px;
    white-space: normal !important;
    vertical-align: middle;
    text-align: center;
    line-height: 1.15;
    padding-top: 8px;
    padding-bottom: 8px;
}
.report-table .sort-link {
    width: 100%;
    min-height: 2.3em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
    white-space: normal !important;
    line-height: 1.15;
}
.report-table .sort-label {
    display: block;
    max-width: 100%;
}
.report-table > thead > tr > th:last-child {
    white-space: normal !important;
}
.report-competitor-best-price-cell {
    color: var(--text) !important;
    font-weight: 700;
}

/* Matching actions: one primary row and two compact secondary buttons. */
.matching-table th:nth-child(5),
.matching-table td:nth-child(5) {
    width: 238px;
}
.matching-action-grid {
    display: grid;
    grid-template-rows: auto auto;
    gap: 6px;
    width: 100%;
}
.matching-action-primary:empty,
.matching-action-secondary:empty {
    display: none;
}
.matching-action-primary form,
.matching-action-primary .btn {
    width: 100%;
    margin: 0;
}
.matching-action-secondary {
    display: grid;
    grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
    gap: 6px;
}
.matching-action-secondary .btn {
    width: 100%;
    min-width: 0;
    padding-left: 7px;
    padding-right: 7px;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
}

@media (max-width: 1200px) {
    .report-filter-footer {
        flex-wrap: wrap;
    }
    .compact-checkbox-line {
        flex-wrap: wrap;
    }
}
