:root {
  --navy: #172549;
  --royal: #3956A3;
  --royal-hover: #2e4787;
  --sky: #81ABD9;
  --sky-mid: #C6D9EE;
  --sky-pale: #DDE7F2;
  --mist: #EBEBF3;
  --coral: #F79496;
  --coral-pale: #FEF5F5;
  --red: #D62F33;
  --green: #1F7A55;
  --ink: #2b2f36;
  --muted: #5f6672;
  --bg: #F6F8FC;
  --card: #ffffff;
  --border: #dbe2ee;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23,37,73,.05), 0 6px 24px rgba(23,37,73,.06);
  --font: 'League Spartan', 'Spartan', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 24px; }
.muted { color: var(--muted); }
button { font-family: inherit; }

.topbar { background: var(--navy); color: #fff; border-bottom: 4px solid var(--coral); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { color: var(--royal); display: inline-flex; }
.brand-mark svg rect { fill: #fff; }
.brand-mark svg path { stroke: var(--royal); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 20px; letter-spacing: .01em; }
.brand-sub { font-size: 13px; color: var(--sky-mid); letter-spacing: .02em; }
.local-pill { font-size: 13px; padding: 6px 12px; border-radius: 999px; background: rgba(129,171,217,.18); color: var(--sky-pale); border: 1px solid rgba(129,171,217,.4); white-space: nowrap; }

.intro { padding: 40px 0 20px; max-width: 760px; }
.intro h1 { font-size: clamp(26px, 3.2vw, 36px); line-height: 1.15; margin: 0 0 10px; color: var(--navy); font-weight: 700; letter-spacing: -.01em; }
.intro p { margin: 0; color: var(--muted); font-size: 17px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.upload-card { padding: 20px; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 36px 16px; border: 2px dashed var(--sky); border-radius: 12px; background: linear-gradient(180deg, #fafcff, var(--sky-pale)); cursor: pointer; transition: background .2s, border-color .2s, transform .1s; }
.dropzone:hover, .dropzone:focus-visible { border-color: var(--royal); outline: none; }
.dropzone.drag { background: var(--sky-mid); border-color: var(--royal); }
.dz-icon { color: var(--royal); }
.dz-title { font-size: 19px; font-weight: 600; color: var(--navy); }
.dz-title u { color: var(--royal); text-underline-offset: 3px; }
.dz-sub { font-size: 14px; color: var(--muted); }

.file-list { display: grid; gap: 8px; margin-top: 16px; }
.file-list:empty { display: none; }
.file-row { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.file-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--sky); }
.file-row.ok .file-dot { background: var(--green); }
.file-row.err .file-dot { background: var(--red); }
.file-row.warn .file-dot { background: #D9902B; }
.file-name { font-weight: 600; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 14px; color: var(--muted); }
.file-row.err .file-meta { color: var(--red); }
.file-amt { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--navy); white-space: nowrap; }
.file-remove { border: 0; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; padding: 4px 8px; cursor: pointer; border-radius: 6px; }
.file-remove:hover { background: var(--coral-pale); color: var(--red); }
.file-info { min-width: 0; }
.upload-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 15px; }

.btn { border: 1px solid transparent; border-radius: 999px; padding: 10px 20px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 6px 14px; font-size: 14px; }
.btn-primary { background: var(--royal); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--royal-hover); }
.btn-secondary { background: var(--sky-pale); color: var(--navy); border-color: var(--sky-mid); }
.btn-secondary:hover:not(:disabled) { background: var(--sky-mid); }
.btn-ghost { background: transparent; color: var(--royal); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--sky-pale); }

.results { margin-top: 24px; display: grid; gap: 20px; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; border-top: 4px solid var(--sky); }
.kpi-alert { border-top-color: var(--coral); }
.kpi-label { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 30px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-small { font-size: 22px; padding-top: 4px; }
.kpi-value.good { color: var(--green); }
.kpi-value.bad { color: var(--red); }
.kpi-foot { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

.table-card { overflow: hidden; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs { display: inline-flex; background: var(--mist); border-radius: 999px; padding: 4px; }
.tab { border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { background: #fff; color: var(--navy); box-shadow: 0 1px 3px rgba(23,37,73,.12); }
.toolbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.search { font-family: inherit; font-size: 15px; padding: 9px 14px; border: 1px solid var(--border); border-radius: 999px; width: 300px; max-width: 100%; }
.search:focus { outline: 2px solid var(--sky); border-color: var(--royal); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; color: var(--ink); cursor: pointer; white-space: nowrap; }
.check input { accent-color: var(--royal); width: 16px; height: 16px; }

.table-scroll { overflow: auto; max-height: 560px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
thead th { position: sticky; top: 0; background: var(--navy); color: #fff; text-align: left; font-weight: 600; padding: 10px 12px; white-space: nowrap; z-index: 1; font-size: 13px; letter-spacing: .02em; }
tbody td { padding: 8px 12px; border-bottom: 1px solid #edf1f7; white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:nth-child(even) td { background: #fafbfe; }
tbody tr:hover td { background: var(--sky-pale); }
tbody tr.flag td { background: var(--coral-pale); }
tbody tr.flag:hover td { background: #fde4e5; }
td.num { text-align: right; }
th.num { text-align: right; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: #e3f3eb; color: var(--green); }
.badge-bad { background: #fde4e5; color: var(--red); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 14px; flex-wrap: wrap; gap: 10px; }
.pager { display: flex; align-items: center; gap: 10px; }

.export-card { padding: 20px 24px; display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; }
.export-card h2 { margin: 0 0 2px; font-size: 20px; color: var(--navy); }
.export-card p { margin: 0; font-size: 15px; }
.export-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

.footer { display: flex; justify-content: space-between; padding-top: 36px; padding-bottom: 36px; font-size: 13px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

@media (max-width: 1024px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .local-pill { display: none; }
  .brand-sub { font-size: 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 24px; }
  .file-row { grid-template-columns: auto 1fr auto; }
  .file-amt { grid-column: 2; font-size: 14px; }
  .file-remove { grid-row: 1; grid-column: 3; }
  .toolbar-right, .search { width: 100%; }
  .export-buttons .btn { flex: 1 1 100%; }
  .footer { flex-direction: column; gap: 4px; }
}

/* Reconciliation */
.recon-card { padding: 22px 24px; margin-top: 20px; }
.recon-card h2 { margin: 0 0 4px; font-size: 21px; color: var(--navy); }
.recon-card p { margin: 0; }
.recon-grid { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: end; margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 500; }
.field input { font: inherit; font-size: 15px; color: var(--ink); padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; min-width: 0; }
.field input:focus { outline: 2px solid var(--sky); border-color: var(--royal); }
.recon-auth { display: flex; gap: 8px; }
.conn-status { margin: 12px 0 0 !important; font-size: 14px; padding: 8px 12px; border-radius: 8px; background: var(--sky-pale); color: var(--navy); }
.conn-status:empty { display: none; }
.conn-status.ok { background: #e3f3eb; color: var(--green); }
.conn-status.warn { background: var(--coral-pale); color: #8a3336; border: 1px solid #f7c9ca; }
.conn-status.err { background: #fde4e5; color: var(--red); }
.recon-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
body.modal-open { overflow: hidden; }
.rv-modal { position: fixed; inset: 0; background: rgba(23,37,73,.55); z-index: 50; display: flex; padding: 24px; }
.rv-modal[hidden], .cf-modal[hidden] { display: none; }
.rv-panel { background: var(--bg); border-radius: var(--radius); width: 100%; max-width: 1500px; margin: 0 auto; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.rv-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; background: var(--navy); color: #fff; padding: 16px 22px; border-bottom: 4px solid var(--coral); }
.rv-header h2 { margin: 0; font-size: 21px; }
.rv-sub { margin: 2px 0 0; color: var(--sky-mid); font-size: 14px; }
.rv-close { background: transparent; border: 0; color: #fff; font-size: 30px; line-height: 1; cursor: pointer; padding: 0 4px; }
.rv-summary { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; padding: 16px 22px 4px; }
.rv-kpi { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; }
.rv-kpi span { font-size: 13px; color: var(--muted); }
.rv-kpi strong { font-size: 22px; color: var(--navy); font-variant-numeric: tabular-nums; }
.rv-kpi em { font-style: normal; font-size: 13px; color: var(--muted); }
.rv-toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 22px 0; flex-wrap: wrap; }
.rv-tab .count { display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--sky-mid); color: var(--navy); font-size: 12px; text-align: center; }
.rv-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 22px; }
.rv-spacer { flex: 1; }
.rv-busy { font-size: 14px; color: var(--royal); font-weight: 600; }
.rv-scroll { flex: 1; max-height: none; margin: 0 22px; background: #fff; border: 1px solid var(--border); border-radius: 10px; }
.rv-table td.cb, .rv-table th.cb { width: 36px; text-align: center; }
.rv-table input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--royal); cursor: pointer; }
.rv-table td.reason { min-width: 220px; white-space: normal; color: #8a3336; }
.rv-table tr.done td { color: var(--muted); }
.rv-table td.empty { text-align: left; padding: 32px 16px; color: var(--muted); }
.rv-foot { padding: 10px 22px 16px; font-size: 14px; }
.badge-info { background: var(--sky-pale); color: var(--royal); }
.badge-warn { background: var(--coral-pale); color: #8a3336; border: 1px solid #f7c9ca; }
.cf-modal { position: fixed; inset: 0; background: rgba(23,37,73,.45); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.cf-panel { background: #fff; border-radius: var(--radius); max-width: 520px; width: 100%; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.cf-panel h3 { margin: 0 0 10px; color: var(--navy); font-size: 20px; }
.cf-panel p { margin: 0 0 10px; }
.cf-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
@media (max-width: 820px) {
  .recon-grid { grid-template-columns: 1fr; }
  .rv-modal { padding: 0; }
  .rv-panel { border-radius: 0; }
  .rv-summary { grid-template-columns: repeat(2, minmax(0,1fr)); padding: 12px 14px 0; }
  .rv-toolbar, .rv-actions { padding-left: 14px; padding-right: 14px; }
  .rv-toolbar .search { width: 100%; }
  .rv-scroll { margin: 0 14px; }
  .rv-spacer { display: none; }
}
