:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #687384;
  --line: #dce2ea;
  --primary: #146c5f;
  --primary-strong: #0e544a;
  --income: #167047;
  --expense: #b13b3b;
  --focus: #e2f3ee;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 18px;
  font-weight: 700;
}

.username {
  color: var(--muted);
  margin-right: 12px;
}

.page {
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto;
}

.login-panel {
  width: min(380px, 100%);
  margin: 80px auto;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

h1,
h2 {
  margin: 0 0 18px;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

.form-stack,
.entry-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

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

input:focus,
select:focus {
  outline: 2px solid var(--focus);
  border-color: var(--primary);
}

.primary-button,
.ghost-button,
.link-button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.primary-button {
  min-height: 38px;
  padding: 8px 16px;
  color: #fff;
  background: var(--primary);
}

.primary-button:hover {
  background: var(--primary-strong);
}

.ghost-button {
  min-height: 36px;
  padding: 7px 12px;
  color: var(--primary);
  background: #eef6f3;
}

.link-button {
  padding: 0;
  color: var(--expense);
  background: transparent;
}

.text-link {
  color: var(--primary);
  text-decoration: none;
}

.alert {
  margin-bottom: 16px;
  padding: 10px 12px;
  color: var(--expense);
  background: #fff0f0;
  border: 1px solid #ffd4d4;
  border-radius: 6px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.month-filter,
.metric,
.entry-form,
.table-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.month-filter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.income strong,
.amount-income {
  color: var(--income);
}

.expense strong,
.amount-expense {
  color: var(--expense);
}

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

.entry-form {
  align-self: start;
  padding: 18px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented label {
  display: block;
}

.segmented input {
  display: none;
}

.segmented span {
  display: block;
  min-height: 36px;
  padding: 8px 12px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
}

.segmented input:checked + span {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.table-panel {
  min-width: 0;
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.filters {
  display: grid;
  grid-template-columns: 120px 140px auto;
  gap: 8px;
}

.category-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.category-summary span {
  padding: 5px 9px;
  color: var(--muted);
  background: #f0f3f7;
  border-radius: 999px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-weight: 600;
}

.row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

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

@media (max-width: 860px) {
  .summary-grid,
  .layout {
    grid-template-columns: 1fr;
  }

  .panel-header {
    display: grid;
  }

  .filters {
    grid-template-columns: 1fr;
  }
}
