:root {
  --bg: #f4f6f2;
  --bg-soft: #e9efe8;
  --surface: #ffffff;
  --surface-soft: #f9faf7;
  --text: #17201b;
  --heading: #0f1713;
  --muted: #66736b;
  --muted-strong: #48564d;
  --line: #d9e1d9;
  --line-strong: #c7d2c7;
  --primary: #245c45;
  --primary-dark: #174131;
  --primary-soft: #e3f0e8;
  --accent: #2d6f9f;
  --accent-soft: #e2edf4;
  --warn: #9a641d;
  --warn-soft: #f5ead8;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --success: #176b45;
  --success-soft: #e4f3ea;
  --shadow: 0 18px 45px rgba(23, 32, 27, 0.08);
  --shadow-soft: 0 8px 24px rgba(23, 32, 27, 0.06);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(233, 239, 232, 0.72), rgba(244, 246, 242, 0) 260px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

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

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  align-items: center;
  backdrop-filter: blur(16px);
  background: rgba(244, 246, 242, 0.88);
  border-bottom: 1px solid rgba(217, 225, 217, 0.9);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 max(18px, calc((100vw - 1160px) / 2));
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  align-items: center;
  color: var(--heading);
  display: inline-flex;
  font-weight: 800;
  gap: 10px;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand::before {
  align-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 8px;
  color: #fff;
  content: "M";
  display: inline-flex;
  font-size: 14px;
  font-weight: 900;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.topbar-user {
  align-items: center;
  color: var(--muted-strong);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 14px;
  justify-content: flex-end;
}

.topbar-user a {
  border-radius: 999px;
  color: var(--muted-strong);
  font-weight: 650;
  padding: 7px 10px;
}

.topbar-user a:hover {
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--heading);
}

.user-chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--heading);
  font-weight: 800;
  padding: 7px 11px;
}

.topbar-user form {
  margin: 0;
}

.page {
  margin: 0 auto;
  max-width: 1160px;
  padding: 28px 18px 56px;
}

.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 52px auto 0;
  max-width: 440px;
  overflow: hidden;
  padding: 28px;
  position: relative;
  width: 100%;
}

.auth-panel::before {
  background: linear-gradient(90deg, var(--primary), var(--accent), var(--warn));
  content: "";
  display: block;
  height: 4px;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
}

.auth-panel.wide {
  max-width: 620px;
}

.auth-panel h1,
.section-header h1,
.empty-state h2,
.table-panel h2 {
  color: var(--heading);
  letter-spacing: 0;
}

.auth-panel h1 {
  font-size: 26px;
  line-height: 1.18;
  margin: 0 0 10px;
}

.muted {
  color: var(--muted);
  margin: 0 0 20px;
}

.form {
  display: grid;
  gap: 16px;
}

label {
  color: var(--muted-strong);
  display: grid;
  gap: 7px;
  font-size: 14px;
  font-weight: 650;
}

.checkbox-row {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  gap: 10px;
  padding: 11px 12px;
}

.checkbox-row input {
  width: auto;
}

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

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted-strong) 50%),
    linear-gradient(135deg, var(--muted-strong) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 19px,
    calc(100% - 12px) 19px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
  padding-right: 34px;
}

input::placeholder {
  color: #9aa49d;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(36, 92, 69, 0.13);
  outline: 0;
}

button,
.primary-button,
.secondary-button {
  align-items: center;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  font-weight: 750;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
  white-space: nowrap;
}

button:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  background: var(--primary);
  color: white;
  box-shadow: 0 10px 22px rgba(36, 92, 69, 0.18);
}

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

.primary-button.compact {
  min-height: 40px;
}

.secondary-button {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--heading);
  min-height: 40px;
}

.secondary-button:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.link-button {
  background: transparent;
  box-shadow: none;
  color: var(--primary);
  min-height: auto;
  padding: 0;
}

.link-button:hover {
  transform: none;
}

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

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

.inline-actions form {
  margin: 0;
}

.alert {
  border: 1px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  margin: 0 auto 16px;
  max-width: 620px;
  padding: 12px 14px;
}

.alert.error {
  background: var(--danger-soft);
  border-color: #ffd3cb;
  color: var(--danger);
}

.alert.success {
  background: var(--success-soft);
  border-color: #c7e8d2;
  color: var(--success);
}

.hero {
  align-items: stretch;
  background:
    linear-gradient(135deg, #173c30 0%, #235944 54%, #2d6f9f 100%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: white;
  display: flex;
  justify-content: space-between;
  min-height: 174px;
  overflow: hidden;
  padding: 28px;
  position: relative;
}

.hero::after {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 28px);
  bottom: 0;
  content: "";
  opacity: 0.45;
  position: absolute;
  right: 0;
  top: 0;
  width: 34%;
}

.hero > * {
  position: relative;
  z-index: 1;
}

.hero h1 {
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1;
  margin: 7px 0 0;
}

.eyebrow {
  color: rgba(255, 255, 255, 0.78);
  font-weight: 750;
  margin: 0;
}

.hero .primary-button {
  align-self: flex-end;
  background: #fff;
  box-shadow: none;
  color: var(--primary-dark);
}

.metric-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 16px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.metric strong {
  color: var(--heading);
  font-size: 22px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.metric:nth-child(2) {
  background: linear-gradient(180deg, #fff, var(--warn-soft));
}

.metric:nth-child(3) {
  background: linear-gradient(180deg, #fff, var(--success-soft));
}

.metric:nth-child(4) {
  background: linear-gradient(180deg, #fff, var(--accent-soft));
}

.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  margin-top: 16px;
  padding: 20px;
}

.empty-state h2 {
  font-size: 18px;
  margin: 0 0 6px;
}

.empty-state p {
  color: var(--muted);
  margin: 8px 0 0;
}

.settings-panel .actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.settings-panel .secondary-button {
  background: var(--surface-soft);
  justify-content: flex-start;
  min-height: 54px;
}

.backup-config p {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 6px;
  grid-template-columns: 140px minmax(0, 1fr);
  margin: 0;
  padding: 10px 0;
}

.backup-config p:last-child {
  border-bottom: 0;
}

.actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

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

.section-header h1 {
  font-size: 30px;
  line-height: 1.14;
  margin: 0 0 6px;
}

.section-header .muted {
  margin-bottom: 0;
}

.table-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow-x: auto;
}

.table-panel h2 {
  font-size: 17px;
  margin: 0;
  padding: 16px 16px 2px;
}

.filter-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  margin-bottom: 16px;
  padding: 16px;
}

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

.compact-filter {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.filter-actions {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.split-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 16px;
}

.block-panel {
  margin-top: 16px;
}

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

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

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tbody tr {
  transition: background 0.14s ease;
}

tbody tr:hover {
  background: #fbfcf9;
}

tr:last-child td {
  border-bottom: 0;
}

.group-row td {
  background: var(--bg-soft);
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 800;
}

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

.muted-inline {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  min-height: 26px;
  padding: 3px 9px;
  white-space: nowrap;
}

.badge-income,
.badge-success,
.badge-asset {
  background: var(--success-soft);
  color: var(--success);
}

.badge-expense,
.badge-danger,
.badge-liability {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-refund,
.badge-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-repayment,
.badge-adjustment,
.badge-neutral {
  background: var(--warn-soft);
  color: var(--warn);
}

.amount {
  color: var(--heading);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  white-space: nowrap;
}

.amount-positive {
  color: var(--success);
}

.amount-negative {
  color: var(--danger);
}

.amount-neutral {
  color: var(--accent);
}

.note-cell {
  color: var(--muted-strong);
  max-width: 260px;
  overflow-wrap: anywhere;
}

.hidden {
  display: none;
}

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

  .filter-grid,
  .compact-filter,
  .split-grid,
  .settings-panel .actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
  }

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

  .topbar-user a {
    padding: 6px 8px;
  }

  .user-chip {
    padding: 6px 9px;
  }

  .page {
    padding: 18px 12px 42px;
  }

  .auth-panel {
    margin-top: 24px;
    max-width: calc(100vw - 24px);
    padding: 22px;
    width: calc(100vw - 24px);
  }

  .hero {
    align-items: flex-start;
    flex-direction: column;
    gap: 24px;
    min-height: 190px;
    padding: 22px;
  }

  .hero::after {
    bottom: auto;
    height: 54%;
    left: 0;
    top: auto;
    width: 100%;
  }

  .hero .primary-button {
    align-self: stretch;
  }

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

  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .section-header h1 {
    font-size: 26px;
  }

  .filter-actions,
  .form-actions,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-actions > *,
  .form-actions > *,
  .actions > * {
    width: 100%;
  }

  .backup-config p {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 12px;
  }
}
