/* ─── Design System ──────────────────────────────────────── */
:root {
    /* Status colors */
    --s-matched-fg: #16a34a;     --s-matched-bg: #dcfce7;
    --s-ambiguous-fg: #d97706;   --s-ambiguous-bg: #fef9c3;
    --s-lowconf-fg: #ea580c;     --s-lowconf-bg: #ffedd5;
    --s-notfound-fg: #dc2626;    --s-notfound-bg: #fee2e2;

    /* Score bar colors */
    --score-high: #16a34a;
    --score-med: #a3b236;
    --score-low: #ea580c;
    --score-vlow: #dc2626;

    /* Neutrals */
    --bg: #f9fafb;
    --bg-card: #ffffff;
    --bg-detail: #f8fafc;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --text: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    --radius: 6px;
    --radius-sm: 4px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --transition: 150ms ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* ─── Layout ─────────────────────────────────────────────── */
.container { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
}

header .container { display: flex; align-items: baseline; gap: 12px; }
header h1 { font-size: 1.15rem; font-weight: 700; color: var(--text); }
header p { font-size: .8rem; color: var(--text-secondary); }

main { padding: 20px 0 96px; }

@media (max-width: 768px) {
    main { padding-bottom: 128px; }
}

/* ─── Tabs ───────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.tab {
    padding: 10px 18px;
    cursor: pointer;
    border: none;
    background: none;
    font-size: .875rem;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-weight: 500;
    transition: color var(--transition), border-color var(--transition);
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Form ───────────────────────────────────────────────── */
.form-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-group { margin-bottom: 12px; }

.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

textarea, input[type="text"], select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .875rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

textarea:focus, input[type="text"]:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

textarea {
    min-height: 100px;
    max-height: 200px;
    resize: vertical;
}

.form-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .8rem;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: 12px;
}

.form-toggle input { accent-color: var(--accent); }

/* Advanced options collapsible */
.advanced-toggle {
    font-size: .8rem;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.advanced-toggle:hover { color: var(--text-secondary); }

.advanced-panel {
    display: none;
    padding: 12px 0;
}

.advanced-panel.open { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

.advanced-panel .form-group { margin-bottom: 0; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .875rem;
    font-weight: 500;
    color: #fff;
    background: var(--accent);
    transition: background var(--transition);
    white-space: nowrap;
    min-height: 36px;
}

.btn:hover { background: var(--accent-hover); }
.btn:disabled { background: #9ca3af; cursor: not-allowed; opacity: .7; }
.btn-sm { padding: 4px 12px; font-size: .8rem; min-height: 28px; }
.btn-outline {
    background: #fff;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); border-color: #d1d5db; color: var(--text); }
.btn-success { background: var(--s-matched-fg); }
.btn-success:hover { background: #15803d; }

/* ─── Upload Area ────────────────────────────────────────── */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--accent);
    background: rgba(37, 99, 235, .03);
}

.upload-area input[type="file"] { display: none; }
.upload-area p { color: var(--text-secondary); font-size: .85rem; }
.upload-area p strong { color: var(--text); }

/* ─── Summary Bar ────────────────────────────────────────── */
.summary-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: .8rem;
}

.summary-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.summary-item .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot-matched { background: var(--s-matched-fg); }
.dot-ambiguous { background: var(--s-ambiguous-fg); }
.dot-lowconf { background: var(--s-lowconf-fg); }
.dot-notfound { background: var(--s-notfound-fg); }

.summary-bar .summary-right {
    margin-left: auto;
    display: flex;
    gap: 8px;
    align-items: center;
}

.summary-bar .time-label { color: var(--text-muted); }

/* ─── Results Header (single mode) ──────────────────────── */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f3f4f6;
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: .8rem;
    color: var(--text-secondary);
}

/* ─── Filter Bar ─────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-bar select, .filter-bar input[type="text"] {
    width: auto;
    padding: 5px 10px;
    font-size: .8rem;
    min-height: 30px;
}

.filter-bar input[type="text"] { min-width: 180px; }

/* ─── Results Table ──────────────────────────────────────── */
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.results-table th {
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-secondary);
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 2;
}

.results-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.results-table tbody tr { transition: background var(--transition); }
.results-table tbody tr:hover { background: #f9fafb; }
.results-table tbody tr:last-child td { border-bottom: none; }

/* Status left border */
.results-table tbody tr[data-status] { border-left: 3px solid transparent; }
.results-table tbody tr[data-status="matched"] { border-left-color: var(--s-matched-fg); }
.results-table tbody tr[data-status="ambiguous"] { border-left-color: var(--s-ambiguous-fg); }
.results-table tbody tr[data-status="low_confidence"] { border-left-color: var(--s-lowconf-fg); }
.results-table tbody tr[data-status="not_found"] { border-left-color: var(--s-notfound-fg); }

.results-table tbody tr.clickable { cursor: pointer; }

/* Column widths */
.col-address { width: 35%; }
.col-city { width: 18%; }
.col-gmina { width: 13%; }
.col-woj { width: 10%; }
.col-postal { width: 8%; font-family: "SF Mono", "Cascadia Code", "Fira Code", Menlo, monospace; }
.col-meta { width: 16%; text-align: right; }

/* Address cell */
.cell-street { font-weight: 500; color: var(--text); }
.cell-number { font-weight: 700; margin-left: 4px; }
.cell-nostreet { font-style: italic; color: var(--text-muted); font-weight: 400; }
.cell-gmina { color: var(--text-secondary); font-size: .8rem; }
.cell-woj { color: var(--text-muted); font-size: .8rem; }

/* Meta cell: badges + score */
.meta-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.meta-badges {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* ─── Status Badge ───────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: .7rem;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.6;
}

.badge-matched { background: var(--s-matched-bg); color: var(--s-matched-fg); }
.badge-ambiguous { background: var(--s-ambiguous-bg); color: var(--s-ambiguous-fg); }
.badge-low_confidence { background: var(--s-lowconf-bg); color: var(--s-lowconf-fg); }
.badge-not_found { background: var(--s-notfound-bg); color: var(--s-notfound-fg); }
.badge-invalid { background: #4b0082; color: #fff; }
.dot-invalid { background: #4b0082; }

.btn-invalid { background: transparent; color: var(--danger, #dc2626); border: 1px solid var(--danger, #dc2626); font-size: .72rem; padding: 2px 6px; min-width: auto; }
.btn-invalid:hover { background: var(--danger, #dc2626); color: #fff; }

.btn-ai { background: transparent; color: #7c3aed; border: 1px solid #7c3aed; font-size: .72rem; padding: 2px 6px; min-width: auto; font-weight: 600; }
.btn-ai:hover:not(:disabled) { background: #7c3aed; color: #fff; }
.btn-ai:disabled { opacity: 0.6; cursor: wait; }

/* File preview with always-visible horizontal slider */
.preview-scroll-wrap { position: relative; }
.preview-scroll { overflow-x: auto; overflow-y: hidden; border: 1px solid var(--border, #e5e7eb); border-radius: 6px; }
.preview-slider { width: 100%; margin: 6px 0 0 0; height: 18px; cursor: pointer; accent-color: var(--accent, #2563eb); display: block; }
.preview-slider::-webkit-slider-runnable-track { height: 8px; background: var(--border, #e5e7eb); border-radius: 4px; }
.preview-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; height: 16px; width: 28px; border-radius: 4px; background: var(--accent, #2563eb); margin-top: -4px; cursor: grab; }
.preview-slider::-moz-range-track { height: 8px; background: var(--border, #e5e7eb); border-radius: 4px; }
.preview-slider::-moz-range-thumb { height: 16px; width: 28px; border-radius: 4px; background: var(--accent, #2563eb); cursor: grab; border: none; }
.btn-invalid-inline { color: var(--danger, #dc2626); border-color: var(--danger, #dc2626); }
.btn-invalid-inline:hover { background: var(--danger, #dc2626); color: #fff; }

/* ─── Layer Badge ────────────────────────────────────────── */
.layer-badge {
    display: inline-flex;
    padding: 0 5px;
    border-radius: 3px;
    font-size: .65rem;
    font-weight: 500;
    line-height: 1.7;
}

.layer-default { background: #f3f4f6; color: #6b7280; }
.layer-fuzzy { background: #dbeafe; color: #1d4ed8; }
.layer-teryt { background: #ede9fe; color: #7c3aed; }
.layer-geo { background: #cffafe; color: #0e7490; }
.layer-nostreet { background: #fef3c7; color: #92400e; }
.layer-extended { background: #e5e7eb; color: #374151; }

/* ─── Score Bar ──────────────────────────────────────────── */
.score-inline {
    display: flex;
    align-items: center;
    gap: 5px;
}

.score-bar-wrap {
    width: 40px;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width .3s ease;
}

.score-label {
    font-size: .75rem;
    color: var(--text-muted);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* ─── Multi-row group (compact/list mode) ────────────────── */
.result-group-row td {
    padding: 10px 12px;
    cursor: pointer;
}

.group-input {
    font-size: .8rem;
    color: var(--text-muted);
}

.group-match {
    font-weight: 500;
}

.group-match-sub {
    font-size: .8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.group-ambig-hint {
    font-size: .75rem;
    color: var(--s-ambiguous-fg);
    font-style: italic;
}

.group-notfound {
    color: var(--s-notfound-fg);
    font-size: .85rem;
}

.expand-icon {
    display: inline-block;
    width: 16px;
    font-size: .7rem;
    color: var(--text-muted);
    transition: transform var(--transition);
    flex-shrink: 0;
}

.expand-icon.open { transform: rotate(90deg); }

/* ─── Equal / Sub-row ────────────────────────────────────── */
.equal-row { background: #fefce8; }
.equal-row:hover { background: #fef9c3 !important; }

.equal-badge {
    display: inline-block;
    padding: 0 6px;
    border-radius: 3px;
    font-size: .65rem;
    font-weight: 600;
    background: #fef3c7;
    color: #92400e;
}

/* ─── Detail Accordion ───────────────────────────────────── */
.detail-panel {
    display: none;
    background: var(--bg-detail);
    border-bottom: 1px solid var(--border);
}

.detail-panel.open { display: table-row; }

.detail-panel td {
    padding: 0 !important;
    border-bottom: 1px solid var(--border) !important;
}

.detail-inner {
    max-height: 0;
    overflow: hidden;
    transition: max-height 200ms ease, padding 200ms ease;
    padding: 0 16px;
}

.detail-panel.open .detail-inner {
    max-height: 800px;
    padding: 16px;
}

.detail-columns {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
}

.detail-section h3 {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.detail-field {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 3px 0;
    font-size: .82rem;
}

.detail-field-label {
    color: var(--text-secondary);
    font-size: .78rem;
}

.detail-field-value {
    font-weight: 500;
    text-align: right;
    word-break: break-all;
}

/* Copy button */
.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 3px;
    font-size: .7rem;
    transition: color var(--transition), background var(--transition);
    margin-left: 4px;
    vertical-align: middle;
    flex-shrink: 0;
}

.copy-btn:hover { color: var(--accent); background: rgba(37,99,235,.08); }
.copy-btn.copied { color: var(--s-matched-fg); }

/* ─── Map Links ──────────────────────────────────────────── */
.map-links {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.map-links a {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: .75rem;
    font-weight: 500;
    text-decoration: none;
    color: #fff;
    transition: opacity var(--transition);
}

.map-links a:hover { opacity: .85; }
.map-link-google { background: #4285f4; }
.map-link-osm { background: #7ebc6f; }
.map-link-geoportal { background: #e67e22; }
.map-links-disabled a {
    background: #d1d5db;
    pointer-events: none;
    cursor: default;
}

/* ─── Score Detail Bars ──────────────────────────────────── */
.score-detail-list { margin-top: 8px; }

.score-detail-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    font-size: .78rem;
}

.score-detail-name {
    width: 50px;
    color: var(--text-muted);
    text-align: right;
    flex-shrink: 0;
}

.score-detail-bar {
    flex: 1;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    overflow: hidden;
}

.score-detail-fill {
    height: 100%;
    border-radius: 3px;
}

.score-detail-val {
    width: 32px;
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-size: .75rem;
}

/* ─── Flag Chips ─────────────────────────────────────────── */
.flags-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

.flag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: .72rem;
    background: #f3f4f6;
    color: #4b5563;
}

.flag-chip-warn { background: #fef3c7; color: #92400e; }
.flag-chip-error { background: #fef2f2; color: #991b1b; font-weight: 600; }

.log-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; font-size: .72rem; font-weight: 600;
    color: var(--text-muted, #6b7280); background: var(--bg-secondary, #f3f4f6);
    border: 1px solid var(--border, #e5e7eb); border-radius: 4px;
    cursor: pointer; transition: all .15s;
}
.log-btn:hover { background: #e5e7eb; color: #374151; }
.flag-chip-info { background: #eff6ff; color: #1e40af; }

/* Cross-validation warning */
.cross-val-box {
    margin-top: 10px;
    padding: 8px 12px;
    background: #fefce8;
    border: 1px solid #fde68a;
    border-radius: var(--radius-sm);
    font-size: .8rem;
    color: #854d0e;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

/* Did you mean / available numbers */
.suggestion-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.suggestion-chip {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: .78rem;
    background: #eff6ff;
    color: var(--accent);
    cursor: pointer;
    border: 1px solid #bfdbfe;
    transition: background var(--transition);
}

.suggestion-chip:hover { background: #dbeafe; }

/* ─── Weak Results Separator ─────────────────────────────── */
.weak-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0 8px;
    font-size: .8rem;
    color: var(--text-muted);
    cursor: pointer;
}

.weak-separator::before, .weak-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.weak-separator:hover { color: var(--text-secondary); }

.weak-results { display: none; }
.weak-results.open { display: block; }
.weak-results .results-table tbody tr { opacity: .75; }
.weak-results .results-table tbody tr:hover { opacity: 1; }

/* ─── Empty State ────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: .4;
}

.empty-state h3 { color: var(--text-secondary); font-size: 1rem; margin-bottom: 8px; }

.empty-state p { font-size: .85rem; max-width: 400px; margin: 0 auto 16px; }

.example-links {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.example-link {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: .8rem;
    background: #eff6ff;
    color: var(--accent);
    cursor: pointer;
    border: none;
    transition: background var(--transition);
}

.example-link:hover { background: #dbeafe; }

/* ─── Error Banner ───────────────────────────────────────── */
.error-banner {
    padding: 10px 16px;
    background: var(--s-notfound-bg);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--s-notfound-fg);
    font-size: .85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.error-banner button {
    margin-left: auto;
    border: none;
    background: none;
    color: var(--s-notfound-fg);
    font-weight: 600;
    cursor: pointer;
    font-size: .8rem;
    text-decoration: underline;
}

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 8px 16px;
    background: #1f2937;
    color: #fff;
    border-radius: var(--radius);
    font-size: .8rem;
    z-index: 1000;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .2s, transform .2s;
    pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }

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

.spinner-dark {
    border-color: rgba(0,0,0,.1);
    border-top-color: var(--accent);
}

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

/* Skeleton loader */
.skeleton {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-row {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

.skeleton-row .skeleton { flex: 1; }

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Autocomplete dropdown ──────────────────────────────── */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: var(--shadow);
}

.autocomplete-dropdown div {
    padding: 6px 10px;
    cursor: pointer;
    font-size: .85rem;
}

.autocomplete-dropdown div:hover,
.autocomplete-dropdown .ac-item.ac-active { background: #eff6ff; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 1200px) {
    .col-woj, .col-gmina { display: none; }
    .detail-columns { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .container { padding: 0 12px; }

    .results-table thead { display: none; }
    .results-table, .results-table tbody, .results-table tr, .results-table td {
        display: block;
        width: 100%;
    }

    .results-table tbody tr {
        padding: 12px;
        margin-bottom: 8px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        border-left-width: 3px;
    }

    .results-table tbody tr[data-status] { border-left-width: 3px; }

    .results-table td {
        padding: 2px 0;
        border-bottom: none;
        text-align: left;
    }

    .results-table td:empty { display: none; }

    .col-address { width: 100%; }
    .col-city, .col-gmina, .col-woj, .col-postal, .col-meta { width: 100%; text-align: left; }

    .meta-cell { flex-direction: row; align-items: center; justify-content: flex-start; }

    .detail-columns { grid-template-columns: 1fr; }

    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar select, .filter-bar input[type="text"] { width: 100%; }

    .form-row { flex-direction: column; }

    .summary-bar { flex-direction: column; align-items: flex-start; gap: 6px; }
    .summary-bar .summary-right { margin-left: 0; }
}

/* ─── API Tab ────────────────────────────────────────────── */
.api-section h4 {
    font-size: .9rem;
    margin: 16px 0 6px;
    font-weight: 600;
}

.api-section p {
    font-size: .85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.api-section pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 14px 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: .8rem;
    line-height: 1.6;
    margin: 8px 0 16px;
}

/* ─── Tools tab ──────────────────────────────────────────── */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}
.tool-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.tool-card h3 {
    font-size: 1rem;
    margin: 0 0 4px;
    color: var(--text);
}
.tool-desc {
    font-size: .82rem;
    color: var(--text-muted);
    margin: 0 0 12px;
}
.tool-form {
    margin-bottom: 8px;
}
.tool-form input[type="text"],
.tool-form input[type="number"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .88rem;
    background: var(--bg);
    color: var(--text);
}
.tool-form input:focus {
    border-color: var(--accent);
    outline: none;
}
.tool-results {
    margin-top: 8px;
    max-height: 500px;
    overflow-y: auto;
}
.tool-result-card {
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 8px;
}
.tool-result-header {
    font-size: .9rem;
    margin-bottom: 6px;
}
.tool-result-meta {
    font-size: .8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.tool-result-sub {
    font-size: .82rem;
    color: var(--text-secondary);
    margin-top: 6px;
}
.tool-code {
    font-family: monospace;
    font-size: .8rem;
    background: var(--accent-light, #e0f2fe);
    color: var(--accent, #2563eb);
    padding: 1px 6px;
    border-radius: 4px;
}
.tool-code-sm {
    font-family: monospace;
    font-size: .72rem;
    color: var(--text-muted);
}
.tool-code-highlight {
    background: var(--accent-light, #e0f2fe);
    color: var(--accent, #2563eb);
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
}
.tool-mono { font-family: monospace; font-size: .85rem; }
.tool-chip {
    display: inline-block;
    font-size: .8rem;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 2px 8px;
    margin: 2px;
}
.tool-more {
    font-size: .78rem;
    color: var(--text-muted);
    font-style: italic;
}
.tool-list-preview {
    margin-top: 6px;
}
.tool-kv {
    font-size: .85rem;
    padding: 2px 0;
}
.tool-kv-label {
    color: var(--text-muted);
    display: inline-block;
    min-width: 110px;
}
.tool-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
    margin-top: 6px;
}
.tool-table th {
    text-align: left;
    padding: 6px 8px;
    background: var(--surface);
    border-bottom: 2px solid var(--border);
    font-size: .78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.tool-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border-light);
}
.tool-table tbody tr:hover {
    background: var(--hover-bg, rgba(0,0,0,.02));
}
.tool-empty {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: .88rem;
}
.tool-error {
    color: var(--status-not-found, #dc2626);
    padding: 8px;
    font-size: .85rem;
}
.loading-text {
    text-align: center;
    padding: 12px;
    color: var(--text-muted);
    font-size: .85rem;
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.btn-outline:hover {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--accent);
}
/* Map links within tool tables */
.tool-table .map-links { gap: 4px; }
.tool-table .map-links a { font-size: .72rem; padding: 2px 6px; }
.tool-card-wide { grid-column: 1 / -1; }
.tool-map-row:hover { background: var(--accent-light, #eff6ff) !important; }

/* ── File results top bar ── */
#file-results-topbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 12px 0;
    flex-wrap: wrap;
}

/* ── Mini map link in result rows ── */
.mini-map-link {
    font-size: .85rem;
    text-decoration: none;
    opacity: 0.6;
    transition: opacity .15s;
}
.mini-map-link:hover { opacity: 1; }

/* ── Rematch button ── */
.btn-rematch {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .7rem;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
}
.btn-rematch:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light, #eff6ff);
}

/* ── Inline rematch panel ── */
.inline-rematch {
    background: var(--surface, #f8fafc);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}
.inline-rematch-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.inline-rematch-input {
    flex: 1;
    min-width: 200px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .85rem;
}
.inline-rematch-input:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.inline-rematch-candidates {
    margin-top: 10px;
}

/* ── Inline candidate cards ── */
.inline-candidate {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all .15s;
    background: white;
}
.inline-candidate:hover {
    border-color: var(--accent);
    background: var(--accent-light, #eff6ff);
}
.inline-candidate-best {
    border-color: var(--status-matched, #16a34a);
    background: #f0fdf4;
}
.inline-candidate-addr {
    font-weight: 600;
    font-size: .85rem;
    min-width: 180px;
}
.inline-candidate-sub {
    font-size: .78rem;
    color: var(--text-muted);
    flex: 1;
}
.inline-candidate-score {
    min-width: 100px;
}

/* ── Highlighted row ── */
.file-row-highlight {
    background: var(--accent-light, #eff6ff) !important;
    box-shadow: inset 3px 0 0 var(--accent);
}

/* ── File results map ── */
#file-results-map-wrap {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 12px;
}

/* Wybory sub-tabs */
.wybory-stab { background: var(--bg-card, #fff); border: 1px solid var(--border); }
.wybory-stab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.wybory-obwod-row:hover { background: #eff6ff; }

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    .inline-candidate { background: var(--surface, #1e293b); }
    .inline-candidate-best { background: #052e16; border-color: #16a34a; }
    .inline-rematch { background: var(--surface, #1e293b); }
    .wybory-stab { background: var(--surface, #1e293b); }
    .wybory-stab.active { background: var(--accent); color: #fff; }
    .wybory-obwod-row:hover { background: #1e293b; }
}
