:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-strong: #f0f5f4;
  --ink: #17201d;
  --muted: #65726f;
  --line: #dbe2df;
  --line-strong: #c5cfca;
  --income: #20805f;
  --income-soft: #dff3eb;
  --expense: #b94242;
  --expense-soft: #f7e5e2;
  --balance: #2d62a8;
  --balance-soft: #e4eefb;
  --amber: #b27a1d;
  --amber-soft: #fff0cf;
  --shadow: 0 14px 36px rgba(20, 31, 28, 0.08);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #16231f;
  color: #eef6f2;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #e0f2ea;
  color: #173a2e;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 15px;
}

.brand span {
  color: #a8bbb4;
  font-size: 12px;
  margin-top: 3px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-button,
.button,
.segmented button,
.icon-button {
  border: 1px solid transparent;
  min-height: 38px;
}

.nav-button {
  width: 100%;
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 8px;
  align-items: center;
  border-radius: 8px;
  background: transparent;
  color: #d4dfda;
  padding: 9px 10px;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: #243630;
  color: #ffffff;
}

.icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  line-height: 1;
  flex: 0 0 20px;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
}

h2 {
  font-size: 16px;
}

.topbar-actions,
.filters,
.form-actions,
.panel-header,
.action-grid {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-actions {
  justify-content: flex-end;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

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

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  min-height: 116px;
  box-shadow: var(--shadow);
}

.kpi span,
.kpi small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.kpi strong {
  display: block;
  margin: 10px 0 8px;
  font-size: clamp(20px, 2vw, 28px);
  white-space: nowrap;
}

.kpi.accent {
  border-color: #b9d2f1;
  background: linear-gradient(180deg, #ffffff 0%, var(--balance-soft) 100%);
}

.dashboard-grid,
.accounts-layout,
.data-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.95fr);
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 12px;
}

.chart-panel {
  min-height: 430px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}

.legend-income {
  background: var(--income);
}

.legend-expense {
  background: var(--expense);
}

.legend-balance {
  background: var(--balance);
}

canvas {
  display: block;
  width: 100%;
  height: 360px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 8px;
  padding: 8px 12px;
  background: #eef3f1;
  color: var(--ink);
  border-color: var(--line-strong);
  font-weight: 700;
}

.button:hover {
  filter: brightness(0.98);
}

.button.primary {
  background: var(--income);
  color: #ffffff;
  border-color: var(--income);
}

.button.ghost {
  background: #ffffff;
}

.button.quiet {
  background: transparent;
  color: var(--balance);
  border-color: var(--line);
}

.button.danger {
  background: var(--expense-soft);
  color: var(--expense);
  border-color: #efbeb7;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  background: #eef3f1;
}

.segmented.small button {
  min-width: 78px;
}

.segmented button {
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  min-width: 92px;
}

.segmented button.active {
  background: #ffffff;
  color: var(--ink);
}

.field {
  display: grid;
  gap: 6px;
  min-width: 180px;
}

.field.compact {
  min-width: 112px;
}

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

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

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(45, 98, 168, 0.2);
  outline-offset: 1px;
}

.entry-form {
  display: grid;
  grid-template-columns: 150px minmax(210px, 1fr) minmax(190px, 0.85fr) 140px;
  gap: 12px;
  align-items: end;
}

.entry-form .wide {
  grid-column: span 3;
}

.account-form,
.payment-form {
  display: grid;
  grid-template-columns: 110px 1fr 1.2fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.payment-form {
  grid-template-columns: 1fr auto;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.tall {
  max-height: 520px;
}

.table-wrap.medium {
  max-height: 520px;
}

.cashflow-wrap {
  max-height: calc(100vh - 190px);
}

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

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

th {
  position: sticky;
  top: 0;
  background: #f1f6f3;
  color: #40504a;
  font-size: 12px;
  z-index: 1;
}

tbody tr:hover {
  background: #f8fbfa;
}

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

.action-col {
  width: 42px;
  text-align: center;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--expense);
  border-color: #efc7c2;
}

.amount-income {
  color: var(--income);
  font-weight: 700;
}

.amount-expense {
  color: var(--expense);
  font-weight: 700;
}

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

.category-row {
  display: grid;
  gap: 6px;
}

.category-row header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.meter {
  height: 9px;
  border-radius: 999px;
  background: #ebefed;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  background: var(--income);
}

.meter.expense span {
  background: var(--expense);
}

.cashflow-table {
  min-width: 1220px;
}

.cashflow-table .section-row td {
  background: #edf4f1;
  color: #2b433b;
  font-weight: 800;
}

.cashflow-table .total-row td {
  background: #f7faf9;
  font-weight: 800;
}

.cashflow-table .balance-row td {
  background: var(--balance-soft);
  color: #183c69;
  font-weight: 800;
}

.tag-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  border: 1px solid var(--line-strong);
  background: #f9fbfa;
  border-radius: 999px;
  padding: 5px 8px 5px 12px;
  font-size: 13px;
}

.tag button {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 999px;
  background: #ecefed;
  color: var(--muted);
}

.mapping-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.mapping-list div {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.mapping-list dt {
  font-weight: 800;
}

.mapping-list dd {
  margin: 0;
  color: var(--muted);
}

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

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  min-height: 44px;
  display: none;
  align-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  background: #16231f;
  color: #ffffff;
  box-shadow: var(--shadow);
}

.toast.show {
  display: flex;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .sidebar {
    padding-inline: 12px;
  }

  .brand {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .brand div:not(.brand-mark),
  .nav-button span:not(.icon) {
    display: none;
  }

  .nav-button {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .kpi-grid,
  .dashboard-grid,
  .accounts-layout,
  .data-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .entry-form,
  .account-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .entry-form .wide {
    grid-column: span 2;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .brand {
    grid-template-columns: 48px 1fr;
    justify-items: start;
    margin-bottom: 14px;
  }

  .brand div:not(.brand-mark) {
    display: block;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-button {
    min-width: 54px;
  }

  .workspace {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .kpi-grid,
  .dashboard-grid,
  .accounts-layout,
  .data-grid,
  .entry-form,
  .account-form,
  .payment-form {
    grid-template-columns: 1fr;
  }

  .entry-form .wide {
    grid-column: auto;
  }

  .form-actions {
    width: 100%;
  }

  .form-actions .button,
  .action-grid .button {
    flex: 1 1 140px;
  }
}
