:root {
  --bg: #F5F4F8;
  --card: #FFFFFF;
  --ink: #17162B;
  --muted: #747187;
  --line: #E9E7EF;
  --accent: #6E59A9;
  --accent-soft: #EEE9FA;
  --positive: #2F7D5B;
  --negative: #A4495C;
  --shadow: 0 12px 32px rgba(38, 31, 66, .07);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
#app { max-width: 760px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(92px + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 30;
  padding: calc(18px + env(safe-area-inset-top)) 20px 14px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(245,244,248,.92); backdrop-filter: blur(18px);
}
.topbar h1, .top-section h2 { margin: 0; font-size: 27px; letter-spacing: -.8px; }
.eyebrow { margin: 0 0 3px; text-transform: uppercase; font-size: 10px; font-weight: 800; letter-spacing: 1.4px; color: var(--muted); }
.icon-button {
  width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow); color: var(--ink); font-size: 20px;
}

main { padding: 0 16px; }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .5; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.month-nav { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; margin: 5px 0 14px; }
.month-arrow, .month-title { border: 0; background: transparent; color: var(--ink); }
.month-arrow { font-size: 30px; }
.month-title { font-weight: 800; text-transform: capitalize; font-size: 17px; }

.hero-card {
  border-radius: 28px; padding: 24px; color: #fff;
  background: linear-gradient(140deg, #17162B, #3A315C);
  box-shadow: 0 18px 38px rgba(23,22,43,.18);
}
.hero-card span { opacity: .72; font-size: 13px; }
.hero-card strong { display: block; margin-top: 7px; font-size: 34px; letter-spacing: -1.2px; }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; margin-top: 24px; gap: 16px; }
.hero-grid div { border-top: 1px solid rgba(255,255,255,.16); padding-top: 14px; }
.hero-grid b { display: block; margin-top: 5px; font-size: 17px; }
.hero-card.compact { margin-top: 12px; }
.hero-card.compact strong { font-size: 29px; }

.section-header { display: flex; align-items: baseline; justify-content: space-between; margin: 25px 4px 11px; gap: 12px; }
.section-header h2, .section-header h3 { margin: 0; font-size: 18px; }
.section-header span { color: var(--muted); font-size: 13px; }
.section-header.top-section { margin-top: 12px; align-items: center; }
.section-header.no-margin { margin: 0 0 12px; }

.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.credit-card, .soft-card, .list-card, .form-card, .mini-stat, .projection-table-wrap {
  background: var(--card); border: 1px solid rgba(23,22,43,.04); box-shadow: var(--shadow);
}
.credit-card { padding: 15px; border-radius: 18px; }
.credit-card header { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.credit-card h3 { margin: 0; font-size: 14px; }
.credit-card .spent { display: block; margin-top: 14px; font-size: 19px; font-weight: 850; }
.credit-card .limit-line { display: flex; justify-content: space-between; margin-top: 5px; color: var(--muted); font-size: 11px; }
.progress { height: 6px; overflow: hidden; border-radius: 999px; background: #EEECEF; margin-top: 10px; }
.progress > div { height: 100%; background: var(--accent); border-radius: inherit; max-width: 100%; }

.soft-card { border-radius: 20px; padding: 18px; }
.commitment-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.commitment-card span { display: block; color: var(--muted); font-size: 12px; }
.commitment-card strong { display: block; margin-top: 5px; font-size: 20px; }
.text-button { border: 0; background: transparent; color: var(--accent); font-weight: 750; }

.list-card { border-radius: 20px; overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 11px; padding: 14px 15px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.row-main { min-width: 0; flex: 1; }
.row-main strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.row-value { text-align: right; font-size: 14px; font-weight: 780; }
.row-value.income { color: var(--positive); }
.row-value.expense { color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.empty { padding: 24px 16px; color: var(--muted); text-align: center; font-size: 13px; }

.month-picker { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.month-chip {
  border: 0; border-radius: 14px; padding: 11px 6px; background: var(--card); color: var(--muted);
  box-shadow: 0 5px 18px rgba(38,31,66,.04); font-weight: 750; text-transform: uppercase; font-size: 11px;
}
.month-chip.active { background: var(--ink); color: #fff; }

.projection-table-wrap { margin-top: 8px; border-radius: 18px; overflow-x: auto; }
.projection-table { width: 100%; border-collapse: collapse; min-width: 460px; }
.projection-table th, .projection-table td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: right; font-size: 12px; }
.projection-table th:first-child, .projection-table td:first-child { text-align: left; }
.projection-table th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .5px; }
.projection-table tbody tr:last-child td { border-bottom: 0; }

.form-card { border-radius: 22px; padding: 18px; margin-top: 12px; }
.form-card h3 { margin: 0 0 14px; font-size: 17px; }
label { display: block; color: var(--muted); font-size: 12px; font-weight: 650; margin: 14px 0; }
input, select {
  width: 100%; margin-top: 7px; border: 1px solid var(--line); background: #FAF9FC; color: var(--ink);
  border-radius: 13px; padding: 13px; outline: none; min-height: 46px;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.money-input { display: flex; align-items: center; margin-top: 7px; border: 1px solid var(--line); background: #FAF9FC; border-radius: 13px; overflow: hidden; }
.money-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.money-input span { padding-left: 13px; font-weight: 800; color: var(--ink); }
.money-input input { border: 0; box-shadow: none!important; margin: 0; padding-left: 6px; background: transparent; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: #F0EEF4; border-radius: 14px; padding: 4px; }
.segment { border: 0; background: transparent; padding: 10px; border-radius: 11px; color: var(--muted); font-weight: 800; }
.segment.active { background: var(--card); color: var(--ink); box-shadow: 0 3px 12px rgba(23,22,43,.08); }
.conditional { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 2px; }
.hidden { display: none!important; }
.helper { margin: 8px 0; font-size: 11px; line-height: 1.45; color: var(--muted); }

.primary-button, .secondary-button, .small-button {
  border: 0; border-radius: 14px; font-weight: 800;
}
.primary-button { width: 100%; padding: 14px; background: var(--ink); color: #fff; margin-top: 8px; }
.secondary-button { width: 100%; padding: 13px; background: var(--accent-soft); color: var(--accent); margin-top: 8px; text-align: center; }
.small-button { padding: 10px 12px; background: var(--ink); color: #fff; flex: 0 0 auto; }
.inline-select { width: auto; min-width: 100px; margin: 0; padding: 10px; min-height: auto; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.mini-stat { border-radius: 18px; padding: 16px; }
.mini-stat span { color: var(--muted); font-size: 11px; }
.mini-stat strong { display: block; margin-top: 6px; font-size: 17px; }

.limit-row { display: grid; grid-template-columns: 80px 1fr; align-items: center; gap: 10px; }
.limit-row label { margin: 6px 0; color: var(--ink); }
.limit-row input { margin: 5px 0; }
.inline-action { display: flex; gap: 8px; align-items: center; }
.inline-action input { margin-top: 0; }
.tag-list { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0 16px; }
.tag { display: inline-flex; gap: 7px; align-items: center; background: var(--accent-soft); color: var(--accent); padding: 7px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.tag button { border: 0; background: transparent; color: inherit; padding: 0; }
.filters { display: grid; grid-template-columns: 1fr 110px; gap: 8px; }
.filters input, .filters select { margin: 0; }
.entry-editor-list { margin-top: 10px; border-top: 1px solid var(--line); }
.editor-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--line); }
.editor-row strong { display: block; font-size: 13px; }
.editor-row small { display: block; color: var(--muted); margin-top: 3px; font-size: 10px; }
.editor-actions { display: flex; gap: 6px; }
.editor-actions button { border: 0; background: #F1EFF5; border-radius: 10px; padding: 8px 9px; }
.backup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.file-label { display: block; cursor: pointer; }
.category-manager label { margin-top: 8px; }

.bottom-nav {
  position: fixed; z-index: 50; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(760px, 100%); padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.94); backdrop-filter: blur(18px); border-top: 1px solid rgba(23,22,43,.06);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.nav-item { border: 0; background: transparent; color: #9995A6; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px; }
.nav-item span { font-size: 20px; line-height: 1; }
.nav-item small { font-size: 9px; font-weight: 750; }
.nav-item.active { color: var(--accent); }
.add-nav span { width: 39px; height: 31px; border-radius: 11px; display: grid; place-items: center; background: var(--ink); color: white; margin-top: -7px; box-shadow: 0 7px 18px rgba(23,22,43,.22); }

.toast {
  position: fixed; z-index: 100; left: 50%; bottom: 92px; transform: translate(-50%, 12px);
  background: var(--ink); color: white; border-radius: 999px; padding: 10px 16px;
  font-size: 12px; opacity: 0; pointer-events: none; transition: .2s;
  white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .two-columns { grid-template-columns: 1fr; gap: 0; }
  .card-grid { grid-template-columns: 1fr; }
}




.breakdown-row .row-main small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}


/* ===== V2.1: Meses + Cloudflare Sync ===== */
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
#app, main, .view, .form-card, .list-card, .hero-card,
.projection-table-wrap, .month-breakdown-grid {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
main {
  padding-left: 14px;
  padding-right: 14px;
  padding-bottom: calc(112px + env(safe-area-inset-bottom));
}
.view {
  overflow: visible;
}
#view-months {
  padding-bottom: 12px;
}
.month-picker {
  grid-template-columns: repeat(4, minmax(0,1fr));
  width: 100%;
}
.month-chip {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.month-section-title {
  align-items: flex-end;
}
.month-section-title > div span {
  display: block;
  margin-top: 3px;
}
.month-breakdown-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 9px;
}
.month-breakdown-card {
  background: var(--card);
  border: 1px solid rgba(23,22,43,.05);
  box-shadow: var(--shadow);
  border-radius: 17px;
  padding: 13px;
  min-width: 0;
}
.month-breakdown-card.is-zero {
  box-shadow: none;
  background: #F8F7FA;
}
.month-breakdown-card.is-zero strong,
.month-breakdown-card.is-zero b,
.month-breakdown-card.is-zero span {
  opacity: .55;
}
.month-breakdown-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.month-breakdown-head strong {
  min-width: 0;
  font-size: 12px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.month-breakdown-head span {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 800;
  color: var(--accent);
}
.month-breakdown-card > b {
  display: block;
  margin-top: 9px;
  font-size: 15px;
}
.analysis-progress {
  height: 5px;
  border-radius: 999px;
  background: #ECE9F0;
  overflow: hidden;
  margin-top: 9px;
}
.analysis-progress > div {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.projection-table-wrap {
  overflow: hidden;
}
.projection-table {
  min-width: 0 !important;
  width: 100%;
  table-layout: fixed;
}
.projection-table th,
.projection-table td {
  padding: 10px 4px;
  font-size: 10px;
  white-space: normal;
  overflow-wrap: anywhere;
  vertical-align: middle;
}
.projection-table th {
  font-size: 8px;
}
.projection-table th:first-child,
.projection-table td:first-child {
  width: 20%;
  padding-left: 8px;
}
.projection-table th:last-child,
.projection-table td:last-child {
  padding-right: 8px;
}
.hero-card strong,
.hero-grid b,
.row-value {
  overflow-wrap: anywhere;
}
.cloud-card .section-header {
  align-items: center;
}
.cloud-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #B8B5C0;
  flex: 0 0 auto;
}
.cloud-dot.ok { background: #2C9B69; }
.cloud-dot.busy { background: #D79A24; }
.cloud-dot.error { background: #C84F5A; }
.cloud-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cloud-actions .primary-button {
  grid-column: 1 / -1;
}
.cloud-actions .primary-button,
.cloud-actions .secondary-button {
  margin-top: 0;
}
.cloud-helper {
  margin-top: 12px;
  margin-bottom: 0;
}

@media (max-width: 360px) {
  main { padding-left: 10px; padding-right: 10px; }
  .month-picker { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .month-breakdown-grid { grid-template-columns: 1fr; }
  .projection-table th, .projection-table td { font-size: 9px; padding: 9px 2px; }
  .projection-table th { font-size: 7px; }
}
