:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --soft: #f1f5f9;
  --ink: #111827;
  --muted: #6b7280;
  --line: #d9dee7;
  --green: #15803d;
  --red: #b42318;
  --shadow: 0 14px 38px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(246, 247, 249, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand > span, .icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
}
.brand > span { color: #fff; background: var(--ink); font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.icon-button {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}
.app {
  display: grid;
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 16px 14px 32px;
  gap: 14px;
}
.hero, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.hero { padding: 18px; }
.hero-head, .panel-head, .list-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.kicker { margin: 0 0 6px; color: var(--muted); font-size: 12px; font-weight: 800; }
h1, h2 { margin: 0; line-height: 1.1; }
h1 { font-size: 32px; }
h2 { font-size: 18px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}
.metric {
  min-width: 0;
  padding: 11px 10px;
  background: var(--soft);
  border: 1px solid #e6ebf2;
  border-radius: 8px;
}
.metric span, .row span, .meta, .empty { color: var(--muted); font-size: 12px; }
.metric strong { display: block; overflow-wrap: anywhere; margin-top: 7px; font-size: 15px; }
.panel { padding: 15px; }
.form { display: grid; gap: 13px; }
.toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.toggle button, .primary, .ghost {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 850;
}
.toggle button { color: var(--muted); background: transparent; }
.toggle .active.income { color: var(--green); background: #e8f5ee; }
.toggle .active.expense { color: var(--red); background: #fbecea; }
.field { display: grid; gap: 7px; }
.field span { color: var(--muted); font-size: 12px; font-weight: 800; }
.field input, .field select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
textarea { min-height: 92px; padding: 12px; line-height: 1.5; resize: vertical; }
.amount input { height: 60px; font-size: 30px; font-weight: 900; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.span2 { grid-column: 1 / -1; }
.primary { width: 100%; color: #fff; background: var(--ink); border-color: var(--ink); }
.ghost { color: var(--ink); background: #fff; border-color: var(--line); }
.actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
.editing .actions { grid-template-columns: 1fr 1fr; }
.month-input { width: 132px; height: 38px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; }
.rows { display: grid; gap: 10px; margin-top: 14px; }
.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  border-bottom: 1px solid #edf0f5;
}
.row:last-child { border-bottom: 0; }
.row strong { text-align: right; overflow-wrap: anywhere; }
.history { padding: 0; overflow: hidden; }
.list-head { padding: 15px; border-bottom: 1px solid var(--line); }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 13px 15px;
  border-bottom: 1px solid #edf0f5;
}
.item:last-child { border-bottom: 0; }
.title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.item.income .dot { background: var(--green); }
.item.expense .dot { background: var(--red); }
.side { display: grid; justify-items: end; gap: 8px; }
.mini-actions { display: flex; gap: 6px; }
.mini-actions .icon-button { width: 32px; height: 32px; box-shadow: none; }
.empty { padding: 22px 15px; text-align: center; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 5;
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 13px;
  color: #fff;
  background: rgba(17, 24, 39, 0.92);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 760px) {
  .app { grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr); align-items: start; }
  .hero, .history { grid-column: 1 / -1; }
}
@media (max-width: 380px) {
  .summary, .grid2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}
