@import url('https://fonts.googleapis.com/css2?family=Syne:wght@600;700;800&family=DM+Mono:wght@400;500&family=DM+Sans:wght@400;500;600&display=swap');

:root {
  --bg:         #080c10;
  --bg-card:    #0f1520;
  --bg-card2:   #161d2a;
  --border:     rgba(255,255,255,0.06);
  --border2:    rgba(255,255,255,0.1);
  --text:       #e8ecf2;
  --text-2:     #8899aa;
  --text-3:     #556677;
  --green:      #00e676;
  --green-dim:  rgba(0,230,118,0.12);
  --red:        #ff4060;
  --red-dim:    rgba(255,64,96,0.12);
  --yellow:     #ffb700;
  --yellow-dim: rgba(255,183,0,0.1);
  --blue:       #4d9fff;
  --accent:     #00e676;
  --radius:     16px;
  --radius-sm:  10px;
  --tab-h:      72px;
  --header-h:   56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }

#app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: var(--tab-h);
}

#loader {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--green), var(--blue), var(--green));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
  z-index: 9999;
}
#loader.hidden { display: none; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.tab-page { display: none; padding-bottom: 1rem; }
.tab-page.active { display: block; }

.section-month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}
.month-title {
  font-family: 'Syne', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  text-transform: capitalize;
}
.btn-month {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border2);
  color: var(--text);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.btn-month:active { background: var(--bg-card2); }

.balance-card {
  margin: 8px 16px 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px 24px 20px;
  position: relative;
  overflow: hidden;
}
.balance-card::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 150px; height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0,230,118,0.06) 0%, transparent 70%);
  pointer-events: none;
}
.balance-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 6px;
}
.balance-amount {
  font-family: 'DM Mono', monospace;
  font-size: 2.8rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
}
.balance-amount.positive { color: var(--green); }
.balance-amount.negative { color: var(--red); }
.balance-sublabel {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-top: 4px;
}
.balance-row {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.balance-item { text-align: center; flex: 1; }
.balance-item-val {
  font-family: 'DM Mono', monospace;
  font-size: 1rem;
  font-weight: 500;
}
.balance-item-val.green { color: var(--green); }
.balance-item-val.red   { color: var(--red); }
.balance-item-val.yellow { color: var(--yellow); }
.balance-item-label {
  font-size: 0.65rem;
  color: var(--text-3);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.alert-banner {
  margin: 10px 16px 0;
  background: var(--red-dim);
  border: 1px solid rgba(255,64,96,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-icon { font-size: 1rem; flex-shrink: 0; }
.alert-text { font-size: 0.82rem; color: var(--red); font-weight: 500; line-height: 1.3; }

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 14px 16px;
}
.btn-action {
  background: var(--bg-card);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-action:active { transform: scale(0.96); background: var(--bg-card2); }
.btn-action-icon { font-size: 1.4rem; }
.btn-action-label { font-size: 0.7rem; font-weight: 600; color: var(--text-2); letter-spacing: 0.04em; }

.section { padding: 16px 16px 0; }
.section-title {
  font-family: 'Syne', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 10px;
}

.cuota-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  gap: 12px;
}
.cuota-item.paid { opacity: 0.45; }
.cuota-info { flex: 1; min-width: 0; }
.cuota-desc {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cuota-meta { font-size: 0.72rem; color: var(--text-3); display: block; margin-top: 2px; }
.cuota-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.cuota-amount { font-family: 'DM Mono', monospace; font-size: 0.9rem; font-weight: 500; }
.btn-check {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  color: var(--text-3);
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-check.checked { background: var(--green); border-color: var(--green); color: #000; }

.cat-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.cat-icon { font-size: 1.1rem; flex-shrink: 0; width: 24px; text-align: center; }
.cat-bar-wrap { flex: 1; }
.cat-name-row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.cat-name { font-size: 0.82rem; color: var(--text); }
.cat-total { font-family: 'DM Mono', monospace; font-size: 0.82rem; color: var(--text-2); }
.cat-bar-bg { height: 4px; background: var(--border2); border-radius: 999px; overflow: hidden; }
.cat-bar-fill { height: 100%; background: linear-gradient(90deg, var(--blue), var(--green)); border-radius: 999px; transition: width 0.5s ease; }

.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon { font-size: 1.1rem; width: 24px; text-align: center; flex-shrink: 0; }
.activity-info { flex: 1; min-width: 0; }
.activity-desc { font-size: 0.85rem; font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-date { font-size: 0.72rem; color: var(--text-3); display: block; margin-top: 1px; }
.activity-amount { font-family: 'DM Mono', monospace; font-size: 0.9rem; font-weight: 500; flex-shrink: 0; }
.activity-amount.positive { color: var(--green); }
.activity-amount.negative { color: var(--red); }

.hist-section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.hist-section-title { font-family: 'Syne', sans-serif; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3); }
.hist-total { font-family: 'DM Mono', monospace; font-size: 0.9rem; font-weight: 500; }
.hist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  gap: 8px;
}
.hist-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.hist-icon { font-size: 1.1rem; flex-shrink: 0; }
.hist-info { flex: 1; min-width: 0; }
.hist-desc { font-size: 0.85rem; font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-meta { font-size: 0.7rem; color: var(--text-3); display: block; margin-top: 2px; }
.hist-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.hist-amount { font-family: 'DM Mono', monospace; font-size: 0.9rem; font-weight: 500; }
.hist-amount.positive { color: var(--green); }
.hist-amount.negative { color: var(--red); }
.btn-delete {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--red-dim);
  color: var(--red);
  font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.btn-delete:active { background: var(--red); color: #fff; }

.cuotas-header { padding: 16px 16px 0; display: flex; justify-content: space-between; align-items: center; }
.cuotas-header-title { font-family: 'Syne', sans-serif; font-size: 1rem; font-weight: 700; }
.comprometido-badge { background: var(--red-dim); border: 1px solid rgba(255,64,96,0.25); border-radius: 999px; padding: 4px 12px; }
.comprometido-label { font-size: 0.65rem; color: var(--text-3); display: block; text-align: right; }
.comprometido-val { font-family: 'DM Mono', monospace; font-size: 0.9rem; color: var(--red); font-weight: 500; }

.cuota-card { margin: 10px 16px 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cuota-card.completed { opacity: 0.5; }
.cuota-card-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 16px 10px; }
.cuota-card-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 3px; }
.cuota-card-meta { font-size: 0.72rem; color: var(--text-3); }
.btn-delete-sm { width: 26px; height: 26px; border-radius: 50%; background: var(--red-dim); color: var(--red); font-size: 0.65rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

.cuota-progress-row { display: flex; align-items: center; gap: 12px; padding: 0 16px 12px; }
.cuota-progress-bar { flex: 1; height: 6px; background: var(--border2); border-radius: 999px; overflow: hidden; }
.cuota-progress-fill { height: 100%; background: linear-gradient(90deg, var(--blue), var(--green)); border-radius: 999px; transition: width 0.5s; }
.cuota-progress-text { font-size: 0.72rem; color: var(--text-3); flex-shrink: 0; }

.cuota-card-footer { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cuota-next { font-size: 0.78rem; color: var(--yellow); }
.cuota-done { font-size: 0.78rem; color: var(--green); }
.cuota-remaining { font-family: 'DM Mono', monospace; font-size: 0.85rem; }
.cuota-remaining.negative { color: var(--red); }

.cuota-payments-list { padding: 6px 0; }
.payment-row { display: flex; align-items: center; gap: 8px; padding: 8px 16px; }
.payment-row.paid { opacity: 0.4; }
.payment-num { font-size: 0.78rem; color: var(--text-3); width: 56px; flex-shrink: 0; }
.payment-date { font-size: 0.78rem; color: var(--text-2); flex: 1; }
.payment-amount { font-family: 'DM Mono', monospace; font-size: 0.82rem; flex-shrink: 0; }
.btn-check-sm { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border2); color: var(--text-3); font-size: 0.75rem; display: flex; align-items: center; justify-content: center; transition: all 0.15s; flex-shrink: 0; }
.btn-check-sm.checked { background: var(--green); border-color: var(--green); color: #000; }

.tab-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(8,12,16,0.92);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  height: var(--tab-h);
  align-items: flex-start;
  padding-top: 10px;
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 430px;
  margin: 0 auto;
  z-index: 100;
}
.tab-btn { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 20px; border-radius: 12px; transition: all 0.15s; -webkit-tap-highlight-color: transparent; }
.tab-icon { font-size: 1.4rem; }
.tab-label { font-size: 0.62rem; font-weight: 600; letter-spacing: 0.06em; color: var(--text-3); text-transform: uppercase; }
.tab-btn.active .tab-label { color: var(--green); }
.tab-btn.active .tab-icon { transform: translateY(-1px); }

.modal { position: fixed; inset: 0; z-index: 200; display: none; align-items: flex-end; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 430px;
  background: var(--bg-card);
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--border2);
  border-bottom: none;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 92dvh;
  overflow-y: auto;
}
.modal.open .modal-sheet { transform: translateY(0); }
.modal-handle { width: 36px; height: 4px; background: var(--border2); border-radius: 999px; margin: 0 auto 20px; }
.modal-title { font-family: 'Syne', sans-serif; font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); margin-bottom: 6px; }
.form-input, .form-select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input.amount-input { font-family: 'DM Mono', monospace; font-size: 1.4rem; font-weight: 500; }
.form-hint { font-family: 'DM Mono', monospace; font-size: 0.82rem; color: var(--green); margin-top: 4px; min-height: 18px; }
.form-select option { background: #1a2030; }

.amount-preview {
  font-family: 'DM Mono', monospace;
  font-size: 1.6rem;
  font-weight: 500;
  color: var(--green);
  margin-top: 8px;
  display: none;
  letter-spacing: -0.02em;
}

.btn-submit { width: 100%; background: var(--accent); color: #000; border-radius: var(--radius-sm); padding: 16px; font-size: 1rem; font-weight: 700; margin-top: 6px; transition: all 0.15s; letter-spacing: 0.02em; }
.btn-submit:active { transform: scale(0.98); opacity: 0.9; }
.btn-submit:disabled { opacity: 0.5; pointer-events: none; }

.toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-20px); background: var(--bg-card2); border: 1px solid var(--border2); border-radius: 999px; padding: 10px 18px; display: flex; align-items: center; gap: 8px; font-size: 0.88rem; font-weight: 500; box-shadow: 0 4px 24px rgba(0,0,0,0.5); opacity: 0; transition: all 0.25s cubic-bezier(0.32, 0.72, 0, 1); z-index: 9999; white-space: nowrap; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success .toast-icon { color: var(--green); }
.toast-error .toast-icon { color: var(--red); }
.toast-error { border-color: rgba(255,64,96,0.3); }

.empty-msg { font-size: 0.82rem; color: var(--text-3); padding: 10px 0; text-align: center; }
::-webkit-scrollbar { width: 0; height: 0; }
.tab-page { padding-top: env(safe-area-inset-top, 0); }
