:root {
  --bg: #fbfaf7;
  --ink: #23251f;
  --muted: #6f7168;
  --line: #dedbd1;
  --panel: #ffffff;
  --accent: #23745b;
  --accent-ink: #ffffff;
  --warn: #9d352c;
  --soft: #edf5ef;
  --shadow: 0 14px 38px rgba(35, 37, 31, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  overflow-x: hidden;
  width: 100%;
}

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

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

.app-shell {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  overflow-x: hidden;
}

.topbar,
.section-heading,
.month-row,
.form-actions,
.inline-field,
.header-actions {
  display: flex;
  align-items: center;
}

.topbar,
.section-heading {
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 16px;
}

.header-actions {
  gap: 8px;
}

.eyebrow,
h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h2 {
  font-size: 18px;
}

.icon-button,
.primary-button,
.secondary-button,
.text-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: 25px;
  line-height: 1;
}

label.icon-button {
  color: var(--ink);
  font-size: 25px;
  font-weight: 400;
  gap: 0;
  padding: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.summary-band,
.entry-form,
.quick-section,
.history-section,
.dialog-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-band {
  padding: 14px;
  margin-bottom: 14px;
}

.month-row {
  gap: 10px;
  margin-bottom: 12px;
}

.month-row input {
  min-width: 0;
  width: 100%;
}

.totals-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.totals-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fffdfa;
}

.totals-grid span,
label,
legend,
.meta,
.price-memory {
  color: var(--muted);
  font-size: 13px;
}

.totals-grid strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.entry-form,
.quick-section,
.history-section {
  padding: 14px;
  margin-bottom: 14px;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

.type-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.type-choice legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  font-weight: 700;
}

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

.type-choice span {
  display: grid;
  min-height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  color: var(--ink);
  font-weight: 800;
}

.type-choice input:checked + span {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent);
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  color: var(--ink);
  font-size: 16px;
  outline: 0;
  padding: 12px;
}

input[type="date"],
input[type="month"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}

select:disabled {
  color: var(--muted);
  opacity: 1;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35, 116, 91, 0.14);
}

.price-memory {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--soft);
  color: #385347;
  line-height: 1.45;
}

.form-actions {
  gap: 10px;
  margin-top: 14px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  flex: 1;
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary-button {
  background: #f1eee7;
  color: var(--ink);
}

.text-button {
  background: transparent;
  color: var(--accent);
  font-weight: 800;
  padding: 8px 0;
}

.text-button.danger {
  color: var(--warn);
}

.quick-list,
.editable-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.quick-chip,
.delete-chip {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 750;
}

.delete-chip {
  color: var(--warn);
}

.expense-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.expense-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.expense-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.item-title {
  font-weight: 850;
  line-height: 1.25;
}

.amount {
  font-weight: 900;
  text-align: right;
}

.meta {
  grid-column: 1 / -1;
  line-height: 1.45;
}

.empty-state {
  color: var(--muted);
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 12px;
}

dialog {
  width: min(calc(100% - 28px), 520px);
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(35, 37, 31, 0.38);
}

.dialog-panel {
  padding: 14px;
}

.inline-field {
  gap: 8px;
}

.field-with-action .inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
}

.small-icon {
  width: 44px;
  height: 44px;
  flex-basis: 44px;
  font-size: 22px;
  font-weight: 800;
}

.compact {
  flex: 0 0 auto;
}

.full-width {
  width: 100%;
  margin: 12px 0;
}

.suggestion-list,
.search-results {
  display: grid;
  gap: 8px;
}

.suggestion-list {
  margin-top: 8px;
}

.suggestion-option {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  color: var(--ink);
  padding: 9px 12px;
  text-align: left;
  font-weight: 800;
}

.suggestion-option small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.quick-list {
  margin-top: 12px;
}

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

  h1 {
    font-size: 27px;
  }
  .totals-grid {
    grid-template-columns: 1fr;
  }
}
