:root {
  color-scheme: light;
  --bg: #f8faf7;
  --surface: #ffffff;
  --surface-strong: #f0f4ef;
  --ink: #172019;
  --muted: #667069;
  --line: #dce4dd;
  --positive: #12784a;
  --positive-soft: #e6f5ed;
  --negative: #a23131;
  --negative-soft: #fae9e8;
  --focus: #c08a11;
  --shadow: 0 14px 42px rgba(23, 32, 25, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(240, 244, 239, 0.72), rgba(248, 250, 247, 0) 260px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

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

.eyebrow,
.panel-label,
.summary-label,
.field span {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 9vw, 2.35rem);
  line-height: 0.98;
}

h2 {
  font-size: 1.05rem;
  line-height: 1.2;
}

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

.balance-panel {
  padding: 18px;
}

.balance-row,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.balance-value {
  margin: 7px 0 0;
  font-size: clamp(2.35rem, 12vw, 3.45rem);
  font-weight: 800;
  line-height: 1;
  overflow-wrap: anywhere;
}

.balance-value.negative {
  color: var(--negative);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.summary-grid > div {
  min-height: 66px;
  padding: 12px;
  background: var(--surface-strong);
  border-radius: 8px;
}

.summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.entry-panel,
.history-panel {
  margin-top: 14px;
  padding: 16px;
}

form {
  margin: 0;
}

.type-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-height: 44px;
  margin: 14px 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.type-switch label {
  position: relative;
  min-width: 0;
}

.type-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.type-switch span {
  display: grid;
  min-height: 36px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 750;
}

.type-switch input:checked + span {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(23, 32, 25, 0.09);
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

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

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(192, 138, 17, 0.22);
  outline: none;
}

.split-fields {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 10px;
}

.primary-button,
.ghost-button,
.text-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  gap: 8px;
  margin-top: 16px;
  background: var(--ink);
  color: #fff;
}

.primary-button span {
  font-size: 1.25rem;
  line-height: 1;
}

.ghost-button,
.icon-button {
  min-height: 40px;
  padding: 0 12px;
  background: var(--surface-strong);
  border-color: var(--line);
  color: var(--ink);
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 0.72rem;
}

.text-button {
  min-height: 34px;
  padding: 0 4px;
  background: transparent;
  color: var(--negative);
}

.transaction-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.transaction-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.transaction-main {
  min-width: 0;
}

.transaction-title,
.transaction-amount {
  margin: 0;
  font-weight: 800;
}

.transaction-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.transaction-side {
  display: grid;
  justify-items: end;
  gap: 6px;
}

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

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

.delete-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

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

.empty-state[hidden] {
  display: none;
}

.opening-dialog {
  width: min(calc(100% - 28px), 420px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.opening-dialog::backdrop {
  background: rgba(23, 32, 25, 0.38);
}

.opening-dialog form {
  padding: 18px;
  background: var(--surface);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.dialog-actions .primary-button {
  margin-top: 0;
}

.dialog-actions .ghost-button {
  min-height: 48px;
}

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

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

  .ghost-button {
    width: 100%;
  }
}
