:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3f8;
  --line: #d6dee9;
  --line-strong: #b9c7d8;
  --text: #172033;
  --muted: #647083;
  --brand: #24579a;
  --brand-dark: #173f73;
  --green: #167348;
  --red: #b4233a;
  --amber: #9a6100;
  --blue-soft: #dce9fb;
  --green-soft: #dff4e8;
  --red-soft: #fde5e9;
  --amber-soft: #fff0cf;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 22px;
}

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

.summary-card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}

.summary-card strong {
  font-size: 28px;
  line-height: 1;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  margin-bottom: 16px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-field span {
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.search-field input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

select,
input,
textarea {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.table-shell {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(28, 43, 70, 0.08);
}

.table-head,
.income-row {
  display: grid;
  grid-template-columns: 42px minmax(240px, 1.6fr) 130px 130px 130px 130px 236px;
  align-items: center;
}

.table-head {
  min-height: 48px;
  padding: 0 16px;
  background: var(--brand);
  color: white;
  font-weight: 700;
}

.table-head span:first-child {
  grid-column: 2;
}

.income-list {
  min-height: 180px;
}

.income-row {
  position: relative;
  grid-template-rows: auto 0;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  transition: background 160ms ease;
}

.income-row.open {
  grid-template-rows: auto auto;
  background: #fbfdff;
}

.income-main {
  display: grid;
  gap: 4px;
}

.income-main small {
  min-height: 18px;
  color: var(--muted);
}

.expand-button,
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.expand-button span {
  transition: transform 160ms ease;
}

.income-row.open .expand-button span {
  transform: rotate(180deg);
}

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

.primary-action,
.secondary-action {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-action {
  background: var(--brand);
  color: white;
}

.primary-action:hover {
  background: var(--brand-dark);
}

.secondary-action {
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--line);
}

.compact {
  min-height: 34px;
  padding-inline: 10px;
  font-size: 13px;
}

.expense-panel {
  display: none;
  grid-column: 1 / -1;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.income-row.open .expense-panel {
  display: block;
}

.expense-head,
.expense-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) minmax(150px, 1fr) 112px 112px 96px 124px 76px;
  gap: 10px;
  align-items: center;
}

.expense-head {
  min-height: 40px;
  padding: 0 12px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.expense-row {
  padding: 12px;
  border-top: 1px solid var(--line);
}

.expense-row p {
  grid-column: 1 / -1;
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.item-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.status-select {
  width: 100%;
  min-height: 34px;
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font-size: 12px;
  font-weight: 800;
  transition: opacity 160ms ease, border-color 160ms ease;
}

.status-paid {
  background: var(--green-soft);
  color: var(--green);
  border-color: #b9e4c9;
}

.status-waiting {
  background: var(--red-soft);
  color: var(--red);
  border-color: #f2bcc7;
}

.status-planned {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: #efd59d;
}

.is-saving {
  opacity: 0.62;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

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

dialog {
  width: min(560px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(23, 32, 51, 0.3);
}

dialog::backdrop {
  background: rgba(11, 21, 38, 0.45);
}

.modal-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.modal-form header,
.modal-form footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.danger {
  color: var(--red);
}

@media (max-width: 980px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-head {
    display: none;
  }

  .income-row {
    grid-template-columns: 36px minmax(0, 1.2fr) minmax(120px, 0.8fr) auto;
    grid-template-rows: auto auto auto 0;
    gap: 12px 14px;
    align-items: start;
  }

  .income-row.open {
    grid-template-rows: auto auto auto auto;
  }

  .income-row > .expand-button {
    grid-column: 1;
    grid-row: 1;
  }

  .income-main {
    grid-column: 2 / 4;
    grid-row: 1;
  }

  .income-row > [data-field="receivedAt"] {
    grid-column: 2;
    grid-row: 2;
  }

  .income-row > [data-field="amount"] {
    grid-column: 3;
    grid-row: 2;
  }

  .income-row > [data-field="totalExpenses"] {
    grid-column: 2;
    grid-row: 3;
  }

  .income-row > [data-field="balance"] {
    grid-column: 3;
    grid-row: 3;
  }

  .income-row > [data-field] {
    display: grid;
    gap: 4px;
    min-width: 0;
  }

  .income-row > [data-field]::before {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .income-row > [data-field="receivedAt"]::before {
    content: "Дата";
  }

  .income-row > [data-field="amount"]::before {
    content: "Сумма";
  }

  .income-row > [data-field="totalExpenses"]::before {
    content: "Расходы";
  }

  .income-row > [data-field="balance"]::before {
    content: "Остаток";
  }

  .row-actions {
    grid-column: 4;
    grid-row: 1;
    justify-content: flex-end;
  }

  .expense-head {
    display: none;
  }

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

@media (max-width: 680px) {
  .shell {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

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

  .summary-grid,
  .toolbar,
  .two-columns {
    grid-template-columns: 1fr;
  }

  .income-row {
    grid-template-columns: 32px 1fr;
    grid-template-rows: auto auto auto auto auto auto 0;
  }

  .income-row.open {
    grid-template-rows: auto auto auto auto auto auto auto;
  }

  .income-row > time,
  .income-row > strong,
  .row-actions {
    grid-column: 2;
  }

  .income-main {
    grid-column: 2;
    grid-row: 1;
  }

  .row-actions {
    grid-row: 2;
    justify-content: flex-start;
  }

  .income-row > [data-field="receivedAt"] {
    grid-row: 3;
  }

  .income-row > [data-field="amount"] {
    grid-row: 4;
  }

  .income-row > [data-field="totalExpenses"] {
    grid-row: 5;
  }

  .income-row > [data-field="balance"] {
    grid-row: 6;
  }

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