:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --border: #e2e2e6;
  --text: #1a1a1e;
  --muted: #6b6b75;
  --accent: #2f5ce0;
  --missing: #c0392b;
  --partial: #b8790a;
  --matched: #1e8e4d;
  --excluded: #8a8a92;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text); }

.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border); }
.topbar .brand { display: flex; align-items: center; text-decoration: none; color: var(--text); justify-self: start; }
.brand-logo { height: 28px; width: auto; display: block; }
.topbar .site-title { justify-self: center; display: flex; align-items: center; text-decoration: none; color: var(--text); }
.topbar .site-title svg { display: block; height: 30px; width: auto; }
.menu-wrap { position: relative; justify-self: end; }
.menu-toggle { background: none; border: 1px solid transparent; padding: 8px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; justify-content: center; align-items: center; width: 36px; height: 36px; }
.menu-toggle:hover { background: #f3f3f5; }
.menu-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 1px; }

.menu-dropdown { position: absolute; top: calc(100% + 8px); right: 0; background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.08); padding: 6px; min-width: 200px; display: flex; flex-direction: column; opacity: 0; visibility: hidden; transform: translateY(-4px); transition: opacity 0.12s ease, transform 0.12s ease; z-index: 20; }
.menu-dropdown.open { opacity: 1; visibility: visible; transform: translateY(0); }
.menu-dropdown a { text-decoration: none; color: var(--text); font-size: 14px; padding: 8px 10px; border-radius: 6px; }
.menu-dropdown a:hover { background: #f3f3f5; }
.menu-divider { border-top: 1px solid var(--border); margin: 6px 2px; }
.menu-user { font-size: 13px; color: var(--muted); padding: 6px 10px; }
.menu-logout { background: none; border: none; color: var(--text); font-size: 14px; padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: left; width: 100%; }
.menu-logout:hover { background: #f3f3f5; }
.menu-dropdown form { display: block; }

.login-wrap { max-width: 360px; margin: 60px auto; }
.login-form { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.login-form input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.login-form button { margin-top: 8px; }
.login-error { color: var(--missing); background: #fdecea; border: 1px solid #f3c3bd; border-radius: 8px; padding: 10px 14px; font-size: 13px; }

.inline-form { display: flex; gap: 6px; align-items: center; margin: 0; }

.progress-good { color: var(--matched); font-weight: 600; }
.progress-bad { color: var(--missing); font-weight: 600; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(20,20,24,0.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-panel { background: var(--card); border-radius: 12px; padding: 24px 28px; width: 100%; max-width: 480px; max-height: 85vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,0.2); }
.modal-panel h2 { margin: 0 0 4px; font-size: 18px; }
.modal-panel > p.muted { margin: 0 0 16px; font-size: 13px; }
.modal-panel form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.format-list { overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; flex: 1; min-height: 0; margin-bottom: 16px; }
.format-option { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 14px; }
.format-option:last-child { border-bottom: none; }
.format-option:hover { background: #f7f7f9; }
.format-country { flex: 1; }
.format-example { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }
.btn-secondary { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: #f3f3f5; }

@media (max-width: 720px) {
  .topbar { grid-template-columns: auto auto; row-gap: 8px; }
  .topbar .site-title { grid-column: 1 / -1; justify-self: center; order: -1; }
  .menu-wrap { grid-column: 2; justify-self: end; }
}

.container { max-width: 1500px; margin: 24px auto; padding: 0 16px; }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-card { flex: 1; min-width: 140px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; text-decoration: none; color: var(--text); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.stat-missing .stat-value { color: var(--missing); }
.stat-partial .stat-value { color: var(--partial); }
.stat-matched .stat-value { color: var(--matched); }
.stat-excluded .stat-value { color: var(--excluded); }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input[type=text], .filters input[type=date] { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.filters input[name=q] { flex: 1; min-width: 200px; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.checkbox-label input[type=checkbox] { margin: 0; cursor: pointer; }
.date-range { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; flex-shrink: 0; white-space: nowrap; }
.date-range input[type=date] { width: 140px; flex-shrink: 0; }
.date-range-sep { color: var(--muted); font-size: 13px; flex-shrink: 0; }

.filter-banner { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; background: #fff7e0; border: 1px solid #f0d888; border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; }
.filter-banner-main { font-size: 14px; color: #7a5b00; }
.filter-banner-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-chip { background: #fff; border: 1px solid #f0d888; color: #7a5b00; font-size: 12px; padding: 3px 9px; border-radius: 999px; }
.clear-filters { font-size: 13px; color: var(--accent); text-decoration: underline; margin-left: 4px; }

table.tx-table { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
table.tx-table thead th:first-child { border-top-left-radius: 10px; }
table.tx-table thead th:last-child { border-top-right-radius: 10px; }
table.tx-table tbody tr:last-child td:first-child { border-bottom-left-radius: 10px; }
table.tx-table tbody tr:last-child td:last-child { border-bottom-right-radius: 10px; }
table.tx-table tbody tr:last-child td { border-bottom: none; }
table.tx-table th, table.tx-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.tx-table th { background: #fafafc; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; position: sticky; top: 16px; z-index: 1; }

.tx-table-sticky-mask { position: sticky; top: 0; height: 16px; background: var(--bg); z-index: 2; }

table.tx-table td.desc { color: var(--muted); }

#tx-table table.tx-table th:nth-child(1) { width: 13%; }
#tx-table table.tx-table th:nth-child(2) { width: 14%; }
#tx-table table.tx-table th:nth-child(3) { width: 15%; }
#tx-table table.tx-table th:nth-child(4) { width: 10%; }
#tx-table table.tx-table th:nth-child(5) { width: 20%; }
#tx-table table.tx-table th:nth-child(6) { width: 28%; }

.review-transactions table.tx-table th:nth-child(1) { width: 12%; }
.review-transactions table.tx-table th:nth-child(2) { width: 13%; }
.review-transactions table.tx-table th:nth-child(3) { width: 14%; }
.review-transactions table.tx-table th:nth-child(4) { width: 9%; }
.review-transactions table.tx-table th:nth-child(5) { width: 17%; }
.review-transactions table.tx-table th:nth-child(6) { width: 23%; }
.review-transactions table.tx-table th:nth-child(7) { width: 12%; }

/* date/amount must never truncate - better to wrap than to hide real numbers */
table.tx-table td.date-cell, table.tx-table td.amount { white-space: normal; overflow: visible; text-overflow: clip; word-break: keep-all; }
table.tx-table .empty { text-align: center; color: var(--muted); padding: 24px; }
table.tx-table tr.clickable-row { cursor: pointer; }
table.tx-table tr.clickable-row:hover { background: #f3f5fb; }

table.tx-table tr.row-missing { background: #fdecea; }
table.tx-table tr.row-missing:hover { background: #fbdcd8; }
table.tx-table tr.row-matched { background: #e9f7ef; }
table.tx-table tr.row-matched:hover { background: #dbf1e5; }
table.tx-table tr.row-partial { background: #fff3da; }
table.tx-table tr.row-partial:hover { background: #ffe9bf; }
table.tx-table tr.row-excluded { background: #f2f2f3; }
table.tx-table tr.row-excluded:hover { background: #e8e8ea; }

.legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,0.08); }
.legend-swatch.legend-matched { background: #e9f7ef; border-color: #b9e3c9; }
.legend-swatch.legend-partial { background: #fff3da; border-color: #f0cf85; }
.legend-swatch.legend-missing { background: #fdecea; border-color: #f3c3bd; }
.legend-swatch.legend-excluded { background: #f2f2f3; border-color: #d6d6d8; }

/* split view */
.split { display: flex; gap: 20px; align-items: flex-start; }
.split-left { flex: 1 1 55%; min-width: 0; }
.split-right { flex: 1 1 45%; min-width: 380px; position: sticky; top: 16px; }

.detail-panel { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; min-height: 300px; }
.detail-panel .placeholder { text-align: center; padding: 60px 20px; }

.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 12px; }
.panel-header h2 { margin: 0; font-size: 18px; }
.panel-sub { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.panel-header-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.amount.big { font-size: 18px; }

.tx-meta { display: grid; grid-template-columns: 140px 1fr; row-gap: 6px; margin: 0 0 16px 0; font-size: 13px; }
.tx-meta dt { color: var(--muted); }
.tx-meta dd { margin: 0; }

.receipt-area { margin-bottom: 12px; }
.receipt-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.receipt-tab { background: #eef1f6; color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font-size: 12px; cursor: pointer; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt-tab:hover { background: #e2e7f2; }

.receipt-viewer-inner { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.receipt-viewer-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: #fafafc; border-bottom: 1px solid var(--border); font-size: 12px; }
.receipt-viewer-toolbar a { color: var(--accent); text-decoration: none; }
.receipt-viewer-actions { display: flex; align-items: center; gap: 12px; }
.pdf-frame { width: 100%; height: 65vh; border: none; display: block; background: #525659; }
.receipt-img-frame { width: 100%; height: 65vh; display: block; background: #525659; object-fit: contain; }

.no-receipt { padding: 30px 0; text-align: center; }

.actions { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.actions summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.actions h4 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
.actions form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions select, .actions input[type=text] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; flex: 1; min-width: 160px; }

@media (max-width: 900px) {
  .split { flex-direction: column; }
  .split-left { width: 100%; }
  .split-right { position: static; width: 100%; }
  .review-split { grid-template-columns: 1fr; }
  .review-receipts, .review-viewer { position: static; max-height: none; }
}

@media (max-width: 720px) {
  /* a fixed 6-column layout has no room to breathe on a phone screen - scroll the
     table horizontally at a readable width instead of truncating every column to a
     couple of illegible characters */
  #tx-table, .review-transactions { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #tx-table table.tx-table, .review-transactions table.tx-table { table-layout: auto; min-width: 680px; }
  #tx-table table.tx-table th, .review-transactions table.tx-table th,
  #tx-table table.tx-table td, .review-transactions table.tx-table td { width: auto; white-space: nowrap; }
  #tx-table table.tx-table td.desc, .review-transactions table.tx-table td.desc { white-space: normal; min-width: 160px; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters select, .filters input[type=text] { width: 100%; }
  .date-range { width: 100%; }
  .date-range input[type=date] { flex: 1; width: auto; }

  .stats { gap: 8px; }
  .stat-card { min-width: calc(50% - 4px); flex: 1 1 calc(50% - 4px); }
}

/* manual review - 3 column split */
.review-split { display: grid; grid-template-columns: 240px minmax(320px, 1fr) minmax(420px, 1.3fr); gap: 16px; align-items: start; }
.review-split h3 { font-size: 13px; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }

.review-receipts { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.receipt-pick-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.receipt-pick { display: block; padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--text); cursor: pointer; border: 1px solid transparent; }
.receipt-pick:hover { background: #f3f5fb; }
.receipt-pick.active { background: #eaf0ff; border-color: var(--accent); }
.receipt-pick-name { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt-pick-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.receipt-pick-list .empty { padding: 20px 10px; text-align: center; color: var(--muted); font-size: 13px; }

.review-viewer { position: sticky; top: 16px; }
.review-viewer .placeholder { background: var(--card); border: 1px solid var(--border); border-radius: 10px; text-align: center; padding: 60px 20px; }

.review-transactions .tx-table td form { margin: 0; }
.review-transactions { min-width: 0; }

.bank-logo { height: 0.8em; width: auto; vertical-align: -0.05em; display: inline-block; }
.bank-logo-finom { height: 1.3em; vertical-align: -0.3em; }
.account-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; white-space: nowrap; min-width: 0; max-width: 100%; }
.account-cell.inline { flex-direction: row; align-items: center; gap: 4px; white-space: normal; }
.account-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.amount { white-space: nowrap; }
.amount.credit { color: var(--matched); font-weight: 600; }
.amount.debit { color: var(--text); font-weight: 600; }
td.amount { min-width: 110px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-missing { background: #fdecea; color: var(--missing); }
.badge-partial { background: #fff3da; color: var(--partial); }
.badge-matched { background: #e8f6ee; color: var(--matched); }
.badge-excluded { background: #eeeeef; color: var(--excluded); }

.pager { display: flex; gap: 6px; margin-top: 12px; }
.pager .page { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; text-decoration: none; color: var(--text); font-size: 13px; }
.pager .page.current { background: var(--accent); color: white; border-color: var(--accent); }

.tx-detail.standalone { max-width: 640px; }

.receipt-list { list-style: none; padding: 0; margin: 10px 0 0; }
.receipt-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.receipt-list li .muted { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.receipt-amount-form { display: flex; gap: 4px; align-items: center; margin: 0; }
.receipt-amount-form input { padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; width: 70px; }

.coverage-summary { font-size: 13px; margin-bottom: 10px; padding: 8px 10px; border-radius: 6px; background: #e8f6ee; color: var(--matched); }
.coverage-summary.coverage-short { background: #fff3da; color: var(--partial); }
.coverage-summary.muted { background: transparent; padding: 0 0 8px; }
.coverage-remaining { font-weight: 600; }

.muted { color: var(--muted); font-size: 13px; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 0; font-size: 13px; }
.link-btn.danger { color: var(--missing); }

.import-section { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; margin-bottom: 16px; }
.import-section form { display: flex; flex-direction: column; gap: 8px; max-width: 480px; }
.import-section label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.import-section input, form.tx-detail-form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.result-box { background: #eef4ff; border: 1px solid #c9d9fb; border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; }

button { background: var(--accent); color: white; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 14px; }
button:hover { opacity: 0.9; }
