* { box-sizing: border-box; }
:root {
  --bg: #F4F1EA;
  --ink: #1C2321;
  --ink-soft: #5c5c58;
  --muted: #8a8a83;
  --card: #ffffff;
  --border: #EDE8DA;
  --green: #3f6659;
  --rust: #b5533c;
  --gold: #8a6d3b;
  --blue: #5c7a99;
}
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { padding-bottom: env(safe-area-inset-bottom); }

header.top {
  padding: calc(env(safe-area-inset-top) + 1.25rem) 1rem 0.5rem;
}
header.top h1 { font-size: 22px; font-weight: 700; margin: 0; }
header.top p { font-size: 13.5px; color: var(--muted); margin: 2px 0 0; }

nav.tabs {
  display: flex; gap: 6px; padding: 0.75rem 1rem; overflow-x: auto;
}
nav.tabs button {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--ink); font-size: 13.5px; font-weight: 500;
  white-space: nowrap; cursor: pointer;
}
nav.tabs button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

main { padding: 0.5rem 1rem 6rem; }
.view { display: none; }
.view.active { display: block; }

.hero {
  background: var(--ink); border-radius: 16px; padding: 1.25rem; margin-bottom: 12px;
}
.hero .label { color: #B8AE93; font-size: 12.5px; margin-bottom: 4px; }
.hero .value { color: var(--bg); font-size: 32px; font-weight: 700; }
.hero .sub { font-size: 13px; margin-top: 4px; }
.hero .sub.pos { color: #9DC7B0; }
.hero .sub.neg { color: #E29A85; }

.row-2 { display: flex; gap: 10px; margin-bottom: 12px; }
.metric {
  background: var(--card); border-radius: 14px; padding: 14px 16px; border: 1px solid var(--border);
  flex: 1; min-width: 0;
}
.metric .mlabel { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.metric .mvalue { font-size: 18px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card {
  background: var(--card); border-radius: 14px; border: 1px solid var(--border); padding: 1rem; margin-bottom: 14px;
}
.card h3 { font-size: 13.5px; font-weight: 600; margin: 0 0 10px; }
.cat-hint { font-size: 12px; color: var(--muted); margin: -6px 0 10px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.bar-row .bar-label { width: 78px; flex-shrink: 0; color: var(--ink-soft); }
.bar-track { flex: 1; height: 10px; background: var(--border); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; }
.bar-row .bar-value { width: 72px; text-align: right; flex-shrink: 0; font-weight: 600; }

.insight {
  font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; padding: 10px 12px;
  background: #FBF7EE; border-radius: 10px; border: 1px solid var(--border); margin-top: 6px;
}

.chart-legend { display: flex; gap: 16px; margin-bottom: 6px; }
.chart-legend span { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-soft); }
.chart-legend .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.month-table-head, .month-row {
  display: grid; grid-template-columns: 44px 1fr 1fr 1fr; gap: 4px; align-items: center;
}
.month-table-head { font-size: 11px; color: var(--muted); padding: 8px 0 4px; text-align: right; }
.month-table-head span:first-child { text-align: left; }
.month-row { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.month-row:last-child { border-bottom: none; }
.month-row.totals { border-top: 1px solid var(--ink); border-bottom: none; font-weight: 700; margin-top: 2px; padding-top: 8px; }
.month-name { color: var(--ink-soft); }
.month-val { text-align: right; font-weight: 600; }
.month-val.pos { color: var(--green); }
.month-val.neg { color: var(--rust); }

.tab-summary { display: flex; gap: 10px; margin-bottom: 14px; }
.tab-summary-item {
  flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 2px;
}
.ts-label { font-size: 11.5px; color: var(--muted); }
.ts-value { font-size: 16px; font-weight: 700; color: var(--ink); }

.btn-add {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%;
  padding: 12px; border-radius: 12px; border: none; color: #fff; font-size: 14.5px; font-weight: 600;
  cursor: pointer; margin-bottom: 14px;
}
.btn-add.income { background: var(--green); }
.btn-add.expense { background: var(--rust); }
.btn-add.asset { background: var(--ink); color: var(--bg); }

.list { background: var(--card); border-radius: 14px; border: 1px solid var(--border); padding: 0 1rem; }
.list .empty { color: var(--muted); font-size: 13.5px; padding: 1rem 0; text-align: center; }
.item-row {
  display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border);
  gap: 10px;
}
.item-row:last-child { border-bottom: none; }
.item-main { min-width: 0; }
.item-title { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 12.5px; color: var(--muted); }
.item-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.item-amount { font-size: 15px; font-weight: 600; }
.item-amount.pos { color: var(--green); }
.item-amount.neg { color: var(--rust); }
.del-btn { background: none; border: none; cursor: pointer; color: var(--rust); padding: 4px; font-size: 16px; }

.tag {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 999px; margin-left: 6px;
}
.tag.fijo { background: #E6EEF3; color: var(--blue); }
.tag.variable { background: #F3EDE0; color: var(--gold); }
.tag.hormiga { background: #F7E6E0; color: var(--rust); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(28,35,33,0.45); display: none;
  align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: var(--bg); width: 100%; max-width: 480px; border-radius: 20px 20px 0 0;
  padding: 1.5rem; max-height: 85vh; overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.1rem; }
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-head button { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--ink-soft); }

label.field-label { font-size: 13px; color: var(--ink-soft); display: block; margin-bottom: 4px; }
input, select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #DDD8CB;
  font-size: 15px; background: #fff; color: var(--ink); margin-bottom: 12px; font-family: inherit;
}
.type-choice { display: flex; gap: 8px; margin-bottom: 12px; }
.type-choice button {
  flex: 1; padding: 9px 6px; border-radius: 10px; border: 1px solid #DDD8CB; background: #fff;
  font-size: 12.5px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.type-choice button.selected { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.error-text { color: var(--rust); font-size: 13px; margin-top: -6px; margin-bottom: 10px; }
.save-btn {
  width: 100%; padding: 12px; border-radius: 10px; border: none; background: var(--ink);
  color: var(--bg); font-size: 15px; font-weight: 600; cursor: pointer;
}

.cat-list { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-chip {
  display: flex; align-items: center; gap: 6px; background: #FBF7EE; border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 6px 6px 12px; font-size: 13px; color: var(--ink);
}
.cat-chip button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px; }

.install-banner {
  position: fixed; left: 1rem; right: 1rem; bottom: 1rem; background: var(--ink); color: var(--bg);
  border-radius: 14px; padding: 12px 14px; display: none; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 13px; z-index: 40;
}
.install-banner.show { display: flex; }
.install-banner button {
  background: var(--bg); color: var(--ink); border: none; border-radius: 8px; padding: 8px 12px;
  font-size: 12.5px; font-weight: 600; cursor: pointer; flex-shrink: 0;
}
