:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-muted: #eef6f4;
  --line: #d8dfdc;
  --text: #17211f;
  --muted: #61706c;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --amber: #f59e0b;
  --coral: #dc5f48;
  --blue: #2563eb;
  --shadow: 0 8px 24px rgba(15, 40, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 14px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.ledger-picker {
  min-width: 210px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.05;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

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

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

.metric {
  padding: 14px;
}

.metric span,
label span,
legend {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 7px;
}

.metric strong {
  display: block;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.content-grid {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.entry-panel,
.list-panel,
.settlement-panel {
  padding: 16px;
}

.settlement-panel {
  grid-column: 2;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.expense-form {
  display: grid;
  gap: 13px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

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

.check-grid,
.quick-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

.check-chip input {
  width: auto;
}

.quick-amounts button,
.ghost-button,
.text-button {
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--teal-dark);
  padding: 0 12px;
  font-weight: 700;
}

.text-button {
  background: #fff;
}

.primary-button {
  background: var(--teal);
  color: #fff;
  padding: 0 16px;
  font-weight: 800;
}

.danger-button {
  background: #fff1f2;
  color: #b42318;
  border: 1px solid #fecdd3;
  padding: 0 16px;
  font-weight: 800;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.expense-list,
.balance-list,
.transfer-list {
  display: grid;
  gap: 10px;
}

.expense-item,
.balance-item,
.transfer-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

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

.expense-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}

.expense-title strong {
  font-size: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  background: #e0f2fe;
  color: #075985;
  font-size: 12px;
  font-weight: 700;
}

.badge.category-food {
  background: #fef3c7;
  color: #92400e;
}

.badge.category-transport {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge.category-stay {
  background: #dcfce7;
  color: #166534;
}

.expense-meta,
.expense-note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.expense-amount {
  font-weight: 800;
  white-space: nowrap;
}

.item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.item-actions button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--teal-dark);
  font-weight: 700;
}

.balance-item,
.transfer-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.positive {
  color: var(--teal-dark);
}

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

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

dialog {
  width: min(460px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(10, 20, 18, 0.28);
}

.settings-form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 12px;
  }

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

  .settlement-panel {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 26px;
  }

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

  .topbar-actions {
    align-items: stretch;
  }

  .ledger-picker {
    flex: 1;
    min-width: 0;
  }

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

  .summary-grid .metric:last-child {
    grid-column: 1 / -1;
  }

  .form-row,
  .form-actions {
    grid-template-columns: 1fr;
  }

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

  .expense-amount {
    white-space: normal;
  }
}
