:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --ink: #1d2733;
  --muted: #68717d;
  --line: #dbe3ec;
  --blue: #2764d8;
  --blue-soft: #eaf1ff;
  --green: #16805d;
  --green-soft: #e6f5ef;
  --red: #b64242;
  --red-soft: #fbe9e7;
  --gold: #b87514;
  --gold-soft: #fff2d8;
  --shadow: 0 18px 45px rgba(33, 40, 48, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
}

.brand h1,
.brand p,
.dashboard-header h2,
.dashboard-header p,
.panel-heading h2,
.panel-heading h3 {
  margin: 0;
}

.brand h1 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
}

.brand p,
.dashboard-header p,
.panel-heading span,
.storage-note,
.metric-tile small,
.metric-label {
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.budget-control,
.month-picker,
label {
  display: grid;
  gap: 6px;
}

.budget-control {
  min-width: 170px;
}

.budget-control span,
.month-picker span,
label span,
legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(39, 100, 216, 0.14);
}

.icon-button,
.tab,
.text-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}

.icon-button {
  padding: 0 14px;
}

.icon-button span,
.tab span {
  display: inline-grid;
  width: 18px;
  height: 18px;
  place-items: center;
  flex: 0 0 18px;
}

.primary {
  background: var(--blue);
  color: #fff;
}

.secondary {
  background: var(--surface-strong);
  color: var(--ink);
  border-color: var(--line);
}

.danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: transparent;
}

.file-action {
  position: relative;
  overflow: hidden;
}

.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

.tab {
  background: var(--surface);
  border-color: var(--line);
  color: var(--muted);
  padding: 0 12px;
}

.tab.active {
  color: var(--ink);
  background: var(--blue-soft);
  border-color: #b8cdfc;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.dashboard-header,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.dashboard-header {
  margin: 6px 0 16px;
}

.dashboard-header h2,
.panel-heading h2 {
  font-size: 24px;
}

.panel-heading h3 {
  font-size: 18px;
}

.month-picker {
  width: min(210px, 100%);
}

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

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

.metric-tile {
  min-height: 128px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  gap: 8px;
}

.metric-tile strong {
  font-size: clamp(24px, 3.2vw, 36px);
  line-height: 1.05;
}

.accent-green {
  background: var(--green-soft);
  border-color: #b9dfcf;
}

.accent-red {
  background: var(--red-soft);
  border-color: #edc3be;
}

.dashboard-grid,
.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.split-layout {
  align-items: start;
}

.split-layout.narrow {
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
}

.tool-panel {
  padding: 16px;
}

.category-list,
.balance-list,
.expense-list,
.people-list,
.data-actions {
  display: grid;
  gap: 10px;
}

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

.category-meta,
.balance-row,
.expense-row,
.person-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.category-meta span:first-child,
.expense-title,
.person-row strong,
.balance-row strong {
  font-weight: 800;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf4;
}

.bar-fill {
  height: 100%;
  min-width: 6px;
  border-radius: inherit;
  background: var(--blue);
}

.balance-row,
.expense-row,
.person-row {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 10px;
}

.balance-row.positive {
  border-color: #bbe0d0;
}

.balance-row.negative {
  border-color: #edc3be;
}

.expense-row {
  align-items: flex-start;
}

.expense-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.expense-title,
.expense-meta,
.expense-note {
  overflow-wrap: anywhere;
}

.expense-meta,
.expense-note,
.person-row span,
.balance-row span {
  color: var(--muted);
  font-size: 13px;
}

.expense-amount {
  display: grid;
  justify-items: end;
  gap: 8px;
  flex: 0 0 auto;
}

.delete-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 18px;
  font-weight: 900;
}

.text-button {
  background: transparent;
  color: var(--blue);
  padding: 0 4px;
}

.expense-form,
.friend-form {
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

fieldset {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.people-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.check-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 8px 10px;
}

.check-option input {
  width: 16px;
  min-height: 16px;
  padding: 0;
}

.storage-note {
  margin: 14px 0 0;
  line-height: 1.5;
}

.empty-state {
  min-height: 88px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 10;
  transform: translateX(-50%) translateY(120px);
  min-width: min(420px, calc(100% - 28px));
  border: 1px solid #b8cdfc;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  text-align: center;
  transition: transform 180ms ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 920px) {
  .topbar,
  .dashboard-header,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > * {
    flex: 1 1 150px;
  }

  .summary-grid,
  .dashboard-grid,
  .split-layout,
  .split-layout.narrow {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 12px;
  }

  .brand {
    min-width: 0;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

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

  .summary-grid,
  .form-row,
  .people-options {
    grid-template-columns: 1fr;
  }

  .expense-row {
    display: grid;
  }

  .expense-amount {
    justify-items: stretch;
  }
}
