:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #18202a;
  --muted: #677383;
  --line: #dfe4ea;
  --brand: #2a3d8a;
  --accent: #4f8f8b;
  --good: #0f7b53;
  --bad: #b42318;
  --warn: #a15c07;
  --shadow: 0 16px 40px rgba(24, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(16px, 4vw, 44px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.topbar h1,
.page-head h2 {
  margin: 0;
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.tabs a,
.segmented a {
  padding: 10px 13px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.tabs a.active,
.segmented a.active {
  background: var(--brand);
  color: #fff;
}

.shell {
  width: min(1240px, calc(100% - 28px));
  margin: 24px auto 48px;
}

.auth-wrap {
  display: grid;
  min-height: 60vh;
  place-items: center;
}

.auth-panel {
  display: grid;
  width: min(420px, 100%);
  gap: 14px;
}

.auth-panel h2 {
  margin: 0;
}

.small-note {
  font-size: 12px;
}

.alerts {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.alert.success {
  border-color: rgba(15, 123, 83, 0.22);
  color: var(--good);
}

.alert.error {
  border-color: rgba(180, 35, 24, 0.28);
  color: var(--bad);
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-head.compact-head {
  justify-content: flex-end;
  margin-top: -8px;
}

.page-head.detail-head {
  width: min(820px, 100%);
  margin-right: auto;
  margin-left: auto;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.45fr);
  gap: 18px;
}

.workspace-grid.movements-grid {
  grid-template-columns: minmax(300px, 0.72fr) minmax(760px, 1.7fr);
  align-items: start;
}

.workspace-grid.narrow {
  grid-template-columns: minmax(320px, 0.8fr) minmax(0, 1fr);
}

.panel,
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel h3 {
  margin: 0 0 14px;
}

.lower-panel {
  margin-top: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

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

.span-2 {
  grid-column: span 2;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--ink);
  font: inherit;
  background: #fff;
}

textarea {
  resize: vertical;
}

.primary-btn,
.ghost-btn,
.icon-btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 13px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.primary-btn {
  width: 100%;
  margin-top: 14px;
  color: #fff;
  background: var(--brand);
}

.ghost-btn {
  border: 1px solid var(--line);
  color: var(--brand);
  background: #fff;
}

.ghost-btn.compact {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 10px;
}

.row-actions,
.detail-actions,
.inline-payment-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inline-payment-form {
  justify-content: flex-end;
}

.stack-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 260px;
}

.inline-payment-form input[type="date"] {
  width: 150px;
  min-height: 36px;
  padding: 7px 9px;
}

.inline-payment-form .amount-mini {
  width: 118px;
  min-height: 36px;
  padding: 7px 9px;
}

.row-actions {
  justify-content: flex-end;
  min-width: 260px;
  white-space: nowrap;
}

.icon-btn {
  color: var(--bad);
  background: #fff0ee;
}

.kpi-strip,
.report-kpis {
  display: grid;
  gap: 10px;
}

.kpi-strip {
  grid-template-columns: repeat(3, minmax(110px, 1fr));
}

.kpi,
.kpi-card {
  padding: 12px 14px;
}

.kpi span,
.kpi-card span,
.muted,
small {
  color: var(--muted);
}

.kpi strong,
.kpi-card strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
}

.movement-concept {
  display: block;
  min-width: 210px;
  max-width: 330px;
  line-height: 1.25;
  white-space: normal;
}

.movement-category {
  min-width: 150px;
  max-width: 220px;
  white-space: normal;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.pill.a_favor {
  color: var(--good);
  background: #e9f7f0;
}

.pill.en_contra {
  color: var(--bad);
  background: #fff0ee;
}

.pill.neutral {
  color: var(--warn);
  background: #fff7e8;
}

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.segmented {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.category-list {
  display: grid;
  gap: 10px;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px 120px auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.category-meta {
  display: grid;
  gap: 6px;
  padding-left: calc(var(--indent) * 18px);
}

.report-kpis {
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  margin-bottom: 18px;
}

.toggle-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.toggle-filter input {
  width: 18px;
  min-height: 18px;
}

.detail-panel {
  width: min(820px, 100%);
  margin-right: auto;
  margin-left: auto;
}

.locked-id {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.locked-id span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.locked-id strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
}

.detail-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.detail-grid dt {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 0;
  font-weight: 700;
}

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

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

.mini-finance-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.mini-finance-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-finance-card strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

.chart-panel canvas {
  width: 100%;
  height: auto;
}

.month-filter {
  width: min(220px, 100%);
}

.month-switcher {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.narrative {
  display: grid;
  gap: 10px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .topbar,
  .page-head {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace-grid,
  .workspace-grid.narrow,
  .report-grid,
  .financial-grid {
    grid-template-columns: 1fr;
  }

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

  .category-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .field-grid,
  .kpi-strip,
  .report-kpis {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .panel {
    padding: 14px;
  }
}
