:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #5f6c7b;
  --line: #d8e0e8;
  --line-strong: #b7c4d1;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --amber: #b7791f;
  --amber-bg: #fff7e6;
  --risk: #b42318;
  --risk-bg: #fff1f0;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --header: #243b53;
  --input-bg: #fffbea;
  --shadow: 0 12px 28px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 14px;
  margin-bottom: 10px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.header-actions > button:first-child {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.header-actions > button:first-child:hover,
.header-actions > button:first-child:focus-visible {
  background: var(--accent-dark);
}

.export-menu {
  position: relative;
}

.export-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 250px;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.export-menu-list[hidden] {
  display: none;
}

.export-menu-list button {
  width: 100%;
  justify-content: flex-start;
  border-color: transparent;
  text-align: left;
}

.export-menu-list button:hover,
.export-menu-list button:focus-visible {
  border-color: var(--accent);
  background: #eefaf8;
}

.app-shell {
  display: grid;
  gap: 14px;
  padding: 16px 24px 28px;
}

.control-band,
.import-band,
.workspace,
.disclaimer-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  padding: 14px;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.client-borrower-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
}

.control-band input,
.control-band select,
.rate-cell {
  background: var(--input-bg);
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.16);
}

.import-band {
  display: grid;
  grid-template-columns: minmax(260px, 380px) minmax(260px, 1fr);
  gap: 12px;
  padding: 14px;
}

.upload-panel,
.upload-actions {
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
}

.upload-file-field {
  display: grid;
  gap: 5px;
  min-width: 0;
  position: relative;
}

.field-label-with-help {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.field-label-with-help label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.info-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  height: 34px;
  border-radius: 50%;
  border-color: var(--line-strong);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
}

.info-button[aria-expanded="true"],
.info-button:hover,
.info-button:focus-visible {
  border-color: var(--accent);
  background: #e6fffb;
}

.info-panel {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: #f7fbfb;
  padding: 10px 12px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
}

.info-panel h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.info-panel p {
  margin: 0 0 6px;
}

.info-panel p:last-child {
  margin-bottom: 0;
}

input[type="file"] {
  background: #ffffff;
  padding: 7px;
}

.import-status {
  min-height: 38px;
  display: grid;
  gap: 6px;
}

.status-line {
  margin: 0;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.status-line.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.status-line.error {
  background: var(--risk-bg);
  color: var(--risk);
}

.status-line.warning {
  background: var(--amber-bg);
  color: var(--amber);
}

.import-summary-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 10px 12px;
}

.import-summary-panel.ok {
  border-left: 4px solid var(--ok);
}

.import-summary-panel.warning {
  border-left: 4px solid var(--amber);
}

.import-summary-panel h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.import-summary-panel dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0;
}

.import-summary-panel dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.import-summary-panel dd {
  margin: 2px 0 0;
  font-weight: 700;
}

.import-summary-panel details {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.import-summary-panel summary {
  cursor: pointer;
  font-weight: 700;
}

.import-summary-panel ul {
  margin: 6px 0 0 16px;
  padding: 0;
}

.import-preview {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.import-preview:empty {
  display: none;
}

.preview-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.preview-header strong {
  color: var(--ink);
  font-size: 13px;
}

.import-preview .table-scroll {
  max-height: 260px;
  box-shadow: none;
}

.import-preview table {
  min-width: 920px;
}

.advanced-tools {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.advanced-tools summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.metric-grid {
  display: block;
}

.dashboard-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.compliance-outcome-card,
.metric-group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.compliance-outcome-card {
  grid-column: 1 / -1;
  padding: 12px 14px;
}

.compliance-outcome-card span,
.compliance-outcome-card em {
  display: block;
}

.compliance-outcome-card span,
.metric-group h2 {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.compliance-outcome-card strong {
  display: block;
  margin-top: 4px;
  font-size: 21px;
  line-height: 1.15;
}

.compliance-outcome-card em,
.metric em {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}

.outcome-ok {
  border-left: 5px solid var(--ok);
}

.outcome-warning {
  border-left: 5px solid var(--amber);
}

.outcome-risk {
  border-left: 5px solid var(--risk);
}

.metric-group {
  padding: 10px;
}

.metric-group h2 {
  margin-bottom: 8px;
}

.metric-group-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  min-height: 84px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 20px;
  line-height: 1.2;
  overflow-wrap: normal;
  white-space: nowrap;
}

.metric-ok {
  border-top: 4px solid var(--ok);
}

.metric-risk {
  border-top: 4px solid var(--risk);
}

.metric-warning {
  border-top: 4px solid var(--amber);
}

.metric-neutral {
  border-top: 4px solid var(--header);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(0, 1fr);
  min-height: 520px;
  overflow: hidden;
}

.checks-panel {
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 16px;
}

.checks-panel ul,
.preview-checks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.checks-panel li,
.preview-checks li {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 9px;
}

.checks-panel li span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.checks-panel li strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  font-weight: 600;
}

.checks-panel li.information,
.preview-checks li.information,
.checks-panel li.ok,
.preview-checks li.ok {
  border-color: #a7f3d0;
  background: var(--ok-bg);
}

.checks-panel li.review,
.preview-checks li.review,
.checks-panel li.warning,
.preview-checks li.warning {
  border-color: #f8d998;
  background: var(--amber-bg);
}

.checks-panel li.action-required,
.preview-checks li.action-required,
.checks-panel li.error,
.preview-checks li.error {
  border-color: #fecaca;
  background: var(--risk-bg);
}

.check-level {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 4px;
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.checks-panel li.technical-checks-row {
  border-color: var(--line);
  background: transparent;
  padding: 0;
}

.technical-checks {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.technical-checks summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.technical-checks summary em {
  min-width: 24px;
  border-radius: 999px;
  background: #e6fffb;
  color: var(--accent-dark);
  font-style: normal;
  line-height: 1.8;
  text-align: center;
}

.technical-checks .summary-hide,
.technical-checks[open] .summary-show {
  display: none;
}

.technical-checks[open] .summary-hide {
  display: inline;
}

.technical-checks ul {
  padding: 0 9px 9px;
}

.main-panel {
  min-width: 0;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tabs button {
  min-width: max-content;
  min-height: 36px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tabs button.workflow-tab {
  border-color: rgba(15, 118, 110, 0.22);
  background: #eefcf8;
  color: var(--accent-dark);
}

.tabs button.is-active {
  border-color: var(--line);
  border-bottom-color: #ffffff;
  background: #ffffff;
  color: var(--ink);
}

.tabs button.workflow-tab.is-active {
  border-color: var(--accent-dark);
  border-bottom-color: #ffffff;
  box-shadow: inset 0 3px 0 var(--accent-dark);
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  margin-left: 6px;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 800;
}

.tab-badge-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.tab-badge-warning {
  background: var(--amber-bg);
  color: var(--amber);
}

.tab-panel {
  padding: 14px;
}

.table-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 620px;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  background: #ffffff;
}

.transaction-table {
  min-width: 2320px;
  table-layout: fixed;
}

.transaction-table .tx-col-date { width: 132px; }
.transaction-table .tx-col-source { width: 118px; }
.transaction-table .tx-col-description { width: 270px; }
.transaction-table .tx-col-reference { width: 150px; }
.transaction-table .tx-col-account { width: 230px; }
.transaction-table .tx-col-money { width: 132px; }
.transaction-table .tx-col-running { width: 158px; }
.transaction-table .tx-col-contact { width: 180px; }
.transaction-table .tx-col-client { width: 190px; }
.transaction-table .tx-col-borrower { width: 190px; }
.transaction-table .tx-col-type { width: 158px; }
.transaction-table .tx-col-checks { width: 280px; }

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--header);
  color: #ffffff;
  font-size: 12px;
}

.sort-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 38px;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 5px 3px;
  text-align: left;
}

.sort-header:hover,
.sort-header:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  outline: 2px solid rgba(255, 255, 255, 0.42);
}

.sort-header span {
  min-width: 0;
}

.sort-header em {
  flex: 0 0 auto;
  min-width: 16px;
  color: rgba(255, 255, 255, 0.72);
  font-style: normal;
  font-weight: 900;
  text-align: right;
}

.sort-header.is-active em {
  color: #ffffff;
}

td {
  font-size: 13px;
}

.transaction-table th,
.transaction-table td {
  padding: 7px 8px;
  vertical-align: middle;
}

.transaction-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.transaction-table .cell-input {
  min-height: 34px;
  width: 100%;
}

.transaction-table .wide-input {
  min-width: 0;
}

.transaction-table .money-input,
.transaction-table .small-input {
  width: 100%;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row-risk td {
  background: #fff9f8;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.status-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.status-risk {
  background: var(--risk-bg);
  color: var(--risk);
}

.status-warning {
  background: var(--amber-bg);
  color: var(--amber);
}

.rate-cell {
  width: 100px;
  min-height: 32px;
}

.inline-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-heading-row h3 {
  margin: 0;
  color: var(--header);
  font-size: 16px;
}

.section-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.excess-section {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.excess-section.allocation-action {
  border-color: #f59e0b;
  background: #fffbeb;
}

.excess-section.allocation-complete {
  border-color: rgba(15, 118, 110, 0.35);
  background: #f0fdfa;
}

.excess-reconciliation {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  margin-bottom: 12px;
}

.cell-input {
  min-height: 30px;
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 12px;
}

.small-input {
  width: 82px;
}

.money-input {
  width: 96px;
  text-align: right;
}

.wide-input {
  min-width: 220px;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.workpaper-shell {
  display: grid;
  gap: 14px;
  max-width: 1040px;
}

.workpaper-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.workpaper-heading span,
.fine-print {
  color: var(--muted);
  font-size: 12px;
}

.workpaper-heading strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
}

.workpaper-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 10px;
}

.compliance-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.fine-print {
  margin: 0;
}

.disclaimer-section {
  padding: 14px;
}

.disclaimer-section p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.disclaimer-section p:first-of-type {
  color: var(--ink);
}

.app-footer {
  position: sticky;
  bottom: 0;
  z-index: 9;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  color: var(--muted);
  padding: 7px 24px;
  font-size: 12px;
  text-align: center;
}

a {
  color: var(--accent-dark);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .control-band,
  .import-band {
    grid-template-columns: 1fr;
  }

  .dashboard-summary {
    grid-template-columns: 1fr;
  }

  .metric-group-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-header {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .header-actions {
    justify-content: stretch;
  }

  .header-actions button {
    flex: 1 1 170px;
  }

  .export-menu {
    flex: 1 1 170px;
  }

  .export-menu > button {
    width: 100%;
  }

  .export-menu-list {
    left: 0;
    right: 0;
  }

  .app-shell {
    padding: 12px;
  }

  .control-band,
  .import-band,
  .advanced-grid,
  .import-summary-panel dl,
  .workspace,
  .workpaper-heading,
  .workpaper-metrics,
  .compliance-panel {
    grid-template-columns: 1fr;
  }

  .metric-group-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .excess-reconciliation {
    grid-template-columns: 1fr;
  }

  .workspace {
    min-height: auto;
  }

  .checks-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 20px;
  }

  .metric-group-grid {
    grid-template-columns: 1fr;
  }

  .metric strong {
    white-space: normal;
  }

  .tabs {
    padding-left: 8px;
  }

  .tab-panel {
    padding: 10px;
  }

  th,
  td {
    padding: 8px;
  }
}
