:root {
  --ink: #18231f;
  --muted: #66736d;
  --line: #dce3df;
  --surface: #ffffff;
  --canvas: #f2f5f1;
  --primary: #176b51;
  --primary-hover: #0f5842;
  --primary-soft: #e5f3ed;
  --danger: #a43835;
  --danger-soft: #f9e9e7;
  --shadow: 0 18px 50px rgba(20, 50, 38, 0.11);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(71, 152, 118, 0.20), transparent 30%),
    radial-gradient(circle at 85% 75%, rgba(196, 169, 92, 0.17), transparent 30%),
    #eef3ee;
}
.login-card {
  width: min(420px, 100%);
  padding: 44px;
  border: 1px solid rgba(23, 107, 81, 0.12);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 6px 0 8px; font-size: 30px; letter-spacing: -0.03em; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 24px;
  border-radius: 14px;
  color: white;
  background: var(--primary);
  font-size: 24px;
  font-weight: 800;
}
.brand-mark.small { width: 34px; height: 34px; margin: 0; border-radius: 10px; font-size: 17px; }
.eyebrow { margin: 0; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: 0.14em; }
.muted { margin: 0; color: var(--muted); }

.stack-form { display: grid; gap: 18px; margin-top: 30px; }
.login-code { font-size: 24px; font-weight: 750; letter-spacing: .22em; text-align: center; font-variant-numeric: tabular-nums; }
.login-hint { margin: -6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
label { display: grid; gap: 7px; color: #46524d; font-size: 13px; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cfd8d3;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 81, 0.12);
}
textarea { resize: vertical; }

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 15px;
  font-weight: 700;
  transition: background .15s, border-color .15s, transform .1s;
}
.button:active { transform: translateY(1px); }
.button:disabled { cursor: default; opacity: .45; }
.button.primary { color: white; background: var(--primary); }
.button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.button.secondary { color: var(--ink); border-color: var(--line); background: white; }
.button.secondary:hover:not(:disabled), .button.ghost:hover { background: #edf1ee; }
.button.ghost { color: #dceae5; border-color: rgba(255,255,255,.18); background: transparent; }
.button.danger { color: var(--danger); border-color: #edc7c4; background: var(--danger-soft); }
.button.full { width: 100%; }
.form-error { margin: 0; color: var(--danger); font-size: 13px; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1440px) / 2));
  color: white;
  background: #142b23;
}
.brand { display: flex; align-items: center; gap: 11px; color: white; text-decoration: none; font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.user-pill { color: #bcd3ca; font-size: 13px; }
.workspace-nav {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 10px max(24px, calc((100vw - 1440px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
}
.nav-button {
  flex: 0 0 auto;
  border: 0;
  border-radius: 9px;
  padding: 9px 13px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}
.nav-button:hover { color: var(--ink); background: #f0f4f1; }
.nav-button.active { color: var(--primary); background: var(--primary-soft); }
.owner-strip {
  padding: 8px max(24px, calc((100vw - 1440px) / 2));
  color: #49675b;
  background: #e7f1ec;
  font-size: 12px;
  font-weight: 650;
}
.page-shell { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 70px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 26px; }
.page-heading h1 { margin: 6px 0 6px; font-size: clamp(30px, 4vw, 42px); letter-spacing: -0.04em; }
.compact-heading { align-items: center; }
.summary-card { min-width: 128px; padding: 15px 18px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.summary-label { display: block; color: var(--muted); font-size: 12px; }
.summary-card strong { display: block; margin-top: 2px; font-size: 24px; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 5px 18px rgba(20, 50, 38, 0.04); }
.filters-panel { padding: 20px; margin-bottom: 18px; }
.content-panel { padding: 22px; }
.spaced-panel { margin-bottom: 18px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.02em; }
.metrics-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.metric-card span { display: block; color: var(--muted); font-size: 12px; }
.metric-card strong { display: block; margin-top: 6px; font-size: 28px; }
.dashboard-grid, .two-column-layout, .reports-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.section-link { margin-top: 18px; }
.card-list { display: grid; gap: 10px; }
.list-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px; border: 1px solid #e5eae7; border-radius: 12px; background: #fbfcfb; }
.list-card-main { min-width: 0; }
.list-card-title { margin: 0 0 5px; overflow: hidden; color: var(--ink); font-size: 14px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.list-card-meta { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.list-card-actions { display: flex; flex: 0 0 auto; gap: 8px; }
.inline-empty { padding: 28px 16px; border: 1px dashed #ccd7d1; border-radius: 12px; color: var(--muted); text-align: center; }
.inline-form { display: flex; align-items: end; gap: 10px; margin-top: 14px; }
.inline-form .grow { flex: 1; }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.no-top-margin { margin-top: 0; }
.report-output { min-height: 130px; margin: 0; padding: 16px; overflow: auto; border-radius: 12px; color: #21332c; background: #f3f6f4; font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
.compact-output { max-height: 290px; margin-bottom: 18px; }
.reports-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.duplicate-group { padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.duplicate-group h2 { margin: 0 0 12px; font-size: 17px; }
.duplicate-group .card-list { margin-bottom: 14px; }
.status-chip { display: inline-flex; border-radius: 999px; padding: 4px 8px; color: #49675b; background: #e7f1ec; font-size: 11px; font-weight: 800; }
.filter-grid { display: grid; grid-template-columns: 1.5fr 1.15fr repeat(2, minmax(140px, .7fr)); gap: 14px; }
.filter-grid .search-field { grid-column: span 2; }
.filter-actions { display: flex; gap: 10px; margin-top: 18px; }
.table-panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 1120px; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid #edf0ee; text-align: left; white-space: nowrap; }
th { color: var(--muted); background: #fafbf9; font-size: 11px; letter-spacing: .045em; text-transform: uppercase; }
td { font-size: 13px; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #f6faf7; }
tbody tr:last-child td { border-bottom: 0; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.counterparty-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.id-cell { max-width: 120px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.kind-badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 800; }
.kind-expense, .kind-fee { color: #8f3b37; background: #faecea; }
.kind-income { color: #176b51; background: var(--primary-soft); }
.kind-transfer { color: #65542e; background: #f6efd9; }
.row-button { min-height: 32px; padding: 5px 11px; }
.loading-state, .empty-state { padding: 70px 24px; text-align: center; color: var(--muted); }
.empty-state { display: grid; gap: 7px; }
.empty-state strong { color: var(--ink); font-size: 17px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 18px; padding: 15px; border-top: 1px solid var(--line); }
.pagination span { min-width: 110px; color: var(--muted); text-align: center; font-size: 13px; }

.transaction-dialog { width: min(820px, calc(100% - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 18px; box-shadow: var(--shadow); }
.transaction-dialog::backdrop { background: rgba(15, 31, 25, .55); backdrop-filter: blur(3px); }
.transaction-dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; }
.dialog-header { border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 4px 0 0; font-size: 24px; }
.dialog-body { padding: 24px; overflow-y: auto; }
.review-confirmation-hint {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 10px;
  color: #145540;
  background: var(--primary-soft);
  font-size: 13px;
  line-height: 1.5;
}
.dialog-footer { border-top: 1px solid var(--line); background: #fafbf9; }
.dialog-footer-right { display: flex; gap: 10px; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 50%; color: var(--muted); background: #eef2ef; font-size: 25px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .wide, .checkbox-field { grid-column: 1 / -1; }
.checkbox-field { display: flex; align-items: center; gap: 9px; }
.checkbox-field input { width: 18px; height: 18px; }
.source-details { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 17px; }
.source-details summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 700; }
.metadata { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 18px 0 0; font-size: 12px; }
.metadata dt { color: var(--muted); }
.metadata dd { margin: 0; overflow-wrap: anywhere; }
.source-details pre { max-height: 180px; overflow: auto; padding: 12px; border-radius: 10px; white-space: pre-wrap; background: #f3f5f3; font-size: 11px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: 380px; padding: 14px 18px; border-radius: 12px; color: white; background: #142b23; box-shadow: var(--shadow); font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 980px) {
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-grid .search-field { grid-column: span 1; }
  .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .login-card { padding: 32px 24px; }
  .topbar { padding: 0 16px; }
  .workspace-nav { padding-inline: 12px; }
  .owner-strip { padding-inline: 16px; }
  .user-pill { display: none; }
  .page-shell { width: min(100% - 24px, 1440px); padding-top: 26px; }
  .page-heading { align-items: stretch; }
  .summary-card { display: none; }
  .filter-grid, .form-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .two-column-layout, .reports-grid { grid-template-columns: 1fr; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form .button { width: 100%; }
  .list-card { align-items: flex-start; flex-direction: column; }
  .list-card-actions { width: 100%; }
  .list-card-actions .button { flex: 1; }
  .filter-grid .search-field, .form-grid .wide, .checkbox-field { grid-column: auto; }
  .filter-actions .button { flex: 1; }
  .dialog-header, .dialog-footer { padding: 16px; }
  .dialog-body { padding: 18px 16px; }
  .dialog-footer { align-items: stretch; gap: 12px; }
  .dialog-footer-right { margin-left: auto; }
}
