@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #24301F;
  --muted: #6B6250;
  --muted-2: #8B8368;
  --paper: #FBF8EF;
  --line: #EFE9D6;
  --border: #D8D0B4;
  --green: #2F6F4E;
  --red: #AE4B3C;
  --gold: #C99A3B;
  --desk: #26362B;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  color: var(--ink);
  background: var(--desk);
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
input:focus, button:focus-visible, select:focus { outline: 2px solid var(--green); outline-offset: 1px; }
::placeholder { color: #B0A98A; }
a { color: var(--green); }

.spin { animation: spin 1s linear infinite; display: inline-block; }
.spin-slow { animation: spin 1.4s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- layout ---------- */
.desk {
  min-height: 100vh;
  background: var(--desk);
  background-image: radial-gradient(circle at 20% 10%, rgba(255,255,255,0.03), transparent 40%);
  display: flex;
  justify-content: center;
  padding: 20px 12px 80px;
}
.frame { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- header ---------- */
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; gap: 8px; }
.brand { display: flex; align-items: center; gap: 6px; }
.brand-text { font-family: 'Fraunces', serif; font-weight: 600; font-size: 15px; color: #F5F0E1; }
.month-nav { display: flex; align-items: center; gap: 6px; background: var(--paper); border-radius: 999px; padding: 4px 6px; }
.nav-btn { background: none; border: none; padding: 4px; display: flex; align-items: center; border-radius: 999px; }
.month-label { font-family: 'Fraunces', serif; font-weight: 600; font-size: 13px; min-width: 96px; text-align: center; }
.header-right { display: flex; align-items: center; gap: 8px; }
.year-btn { background: none; border: none; padding: 4px; color: #F5F0E1; opacity: .75; display: flex; }
.logout-btn { background: none; border: none; padding: 4px; color: #F5F0E1; opacity: .75; display: flex; }
.save-indicator { width: 14px; display: flex; justify-content: center; }

/* ---------- banners (copiar presupuesto / cerca del limite) ---------- */
.banner { background: #FBF0DA; border: 1px solid #EBD9AC; border-radius: 12px; padding: 12px 14px; font-size: 12.5px; color: #5C4A1E; display: flex; align-items: center; gap: 10px; margin: 0 0 2px; }
.banner.banner-danger { background: #FBEAE7; border-color: #EFC9C1; color: #7A2E23; }
.banner-text { flex: 1; line-height: 1.45; }
.banner-text b { display: block; font-family: 'Fraunces', serif; font-size: 13.5px; margin-bottom: 2px; }
.banner-action { background: var(--green); color: #fff; border: none; border-radius: 8px; padding: 7px 12px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.banner-dismiss { background: none; border: none; color: inherit; opacity: .6; display: flex; padding: 2px; }

/* ---------- ticket ---------- */
.ticket { background: var(--paper); border-radius: 10px 10px 0 0; padding: 20px 20px 30px; box-shadow: 0 10px 24px rgba(0,0,0,.25); }
.ticket-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.ticket-label { font-size: 13px; color: var(--muted); }
.ticket-amount { font-family: 'IBM Plex Mono', monospace; font-size: 16px; font-weight: 600; }
.link-amount { font-family: 'IBM Plex Mono', monospace; font-size: 16px; font-weight: 600; color: var(--ink); background: none; border: none; padding: 0; text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.ticket-big { font-family: 'Fraunces', serif; font-size: 30px; font-weight: 700; }
.dashed-line { border-top: 1.5px dashed var(--border); margin: 10px 0; }

/* ---------- cards ---------- */
.card { background: var(--paper); border-radius: 14px; padding: 16px; box-shadow: 0 4px 14px rgba(0,0,0,.14); }
.card-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; }
.card-title { font-family: 'Fraunces', serif; font-weight: 600; font-size: 15px; margin-bottom: 8px; }
.small-link { background: none; border: none; color: var(--green); font-size: 12.5px; font-weight: 600; padding: 0; white-space: nowrap; }
.empty-hint { font-size: 13px; color: var(--muted-2); line-height: 1.5; padding: 6px 0; }

/* ---------- charts ---------- */
.chart-flex { display: flex; align-items: center; gap: 12px; }
.chart-canvas-wrap { width: 128px; height: 128px; flex-shrink: 0; position: relative; }
.legend { flex: 1; min-width: 0; }
.legend-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.legend-name { font-size: 12.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { font-size: 12px; font-family: 'IBM Plex Mono', monospace; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; display: inline-block; }
.months-chart-wrap { height: 130px; }

/* ---------- templates (gastos frecuentes) ---------- */
.template-row { display: flex; flex-wrap: wrap; gap: 8px; }
.template-chip { display: flex; align-items: center; gap: 6px; border: 1.5px solid var(--border); border-radius: 999px; padding: 7px 12px; background: #fff; font-size: 12.5px; font-weight: 600; }
.template-chip .dot { width: 7px; height: 7px; }
.template-add-btn { border: 1.5px dashed #B0A98A; border-radius: 999px; padding: 7px 12px; font-size: 12.5px; font-weight: 600; color: var(--muted); background: transparent; }
.template-del { background: none; border: none; color: var(--muted-2); padding: 0 0 0 2px; display: flex; }

/* ---------- search ---------- */
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-input { flex: 1; border: 1.5px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 13px; background: #fff; }
.filter-select { border: 1.5px solid var(--border); border-radius: 10px; padding: 8px 8px; font-size: 12.5px; background: #fff; max-width: 120px; }
.export-btn { border: 1.5px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; background: #fff; color: var(--muted); display: flex; align-items: center; gap: 4px; white-space: nowrap; }

/* ---------- budgets ---------- */
.budget-row { padding: 8px 0; border-top: 1px solid var(--line); }
.budget-top { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.budget-name { font-size: 13.5px; font-weight: 600; flex: 1; background: none; border: none; text-align: left; padding: 0; color: var(--ink); }
.budget-set-link { background: none; border: none; font-size: 11.5px; color: var(--muted-2); padding: 0; }
.budget-input { width: 90px; font-family: 'IBM Plex Mono', monospace; font-size: 12.5px; border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; }
.budget-bar-track { height: 7px; border-radius: 999px; background: var(--line); overflow: hidden; }
.budget-bar-fill { height: 100%; border-radius: 999px; transition: width .3s ease; }
.budget-foot { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted-2); margin-top: 4px; }
.budget-actions { display: flex; gap: 6px; }
.icon-mini-btn { background: none; border: none; padding: 2px; color: var(--muted-2); display: flex; }

/* ---------- expenses ---------- */
.date-header { font-size: 11px; font-weight: 700; color: var(--muted-2); letter-spacing: .5px; text-transform: uppercase; padding: 10px 0 4px; }
.expense-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; background: none; border-left: none; border-right: none; border-bottom: none; width: 100%; text-align: left; }
.expense-desc { font-size: 13.5px; font-weight: 500; }
.expense-cat { font-size: 11.5px; color: var(--muted-2); }
.expense-amount { font-family: 'IBM Plex Mono', monospace; font-size: 13.5px; font-weight: 600; color: var(--red); flex-shrink: 0; }

/* ---------- FAB ---------- */
.fab-row { position: sticky; bottom: 14px; display: flex; justify-content: flex-end; pointer-events: none; }
.fab { pointer-events: auto; width: 54px; height: 54px; border-radius: 50%; background: var(--green); border: none; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(0,0,0,.35); }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,26,18,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { width: 100%; max-width: 460px; background: var(--paper); border-radius: 18px 18px 0 0; padding: 18px 18px 26px; max-height: 88vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-title { font-family: 'Fraunces', serif; font-weight: 600; font-size: 17px; }
.icon-btn { background: #F0EAD9; border: none; border-radius: 999px; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; }

.field { margin-bottom: 14px; }
.label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.amount-input-wrap { display: flex; align-items: center; border: 1.5px solid var(--border); border-radius: 10px; padding: 8px 12px; background: #fff; }
.amount-prefix { font-family: 'IBM Plex Mono', monospace; font-size: 20px; color: var(--muted-2); margin-right: 4px; }
.amount-input { border: none; outline: none; font-family: 'IBM Plex Mono', monospace; font-size: 20px; font-weight: 600; flex: 1; background: transparent; color: var(--ink); }
.text-input { width: 100%; border: 1.5px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px; color: var(--ink); background: #fff; }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid; border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; background: transparent; color: var(--ink); }
.chip-add { border: 1.5px dashed #B0A98A; border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; color: var(--muted); background: transparent; }
.color-swatch { width: 28px; height: 28px; border-radius: 50%; border: none; padding: 0; }
.primary-btn { width: 100%; background: var(--green); color: var(--paper); border: none; border-radius: 12px; padding: 13px; font-size: 14.5px; font-weight: 700; margin-top: 4px; }
.secondary-btn { width: 100%; background: transparent; color: var(--green); border: 1.5px solid var(--green); border-radius: 12px; padding: 12px; font-size: 14px; font-weight: 700; margin-top: 10px; }
.danger-link { width: 100%; background: none; border: none; color: var(--red); font-size: 12.5px; font-weight: 600; padding: 10px 0 0; text-align: center; }
.category-manage-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.category-manage-name { flex: 1; font-size: 13.5px; font-weight: 500; }

/* ---------- toast (deshacer) ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1D2B1F; color: #F5F0E1; padding: 10px 14px; border-radius: 10px; font-size: 13px; display: flex; align-items: center; gap: 12px; box-shadow: 0 8px 20px rgba(0,0,0,.4); z-index: 60; }
.toast button { background: none; border: none; color: #8FD9A8; font-weight: 700; font-size: 13px; }

/* ---------- auth ---------- */
.auth-body { min-height: 100vh; background: var(--desk); display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--paper); border-radius: 16px; padding: 28px 24px; box-shadow: 0 14px 30px rgba(0,0,0,.3); }
.auth-title { font-family: 'Fraunces', serif; font-weight: 700; font-size: 24px; margin-bottom: 4px; text-align: center; }
.auth-subtitle { font-size: 13px; color: var(--muted-2); text-align: center; margin-bottom: 22px; }
.auth-error { font-size: 12.5px; color: var(--red); background: #FBEAE7; border: 1px solid #EFC9C1; border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.auth-switch a { font-weight: 700; text-decoration: none; }
.remember-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin: -2px 0 14px; cursor: pointer; }
.remember-row input { width: 15px; height: 15px; accent-color: var(--green); }

.loading-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--desk); }

@media (max-width: 380px) {
  .month-label { min-width: 76px; font-size: 12px; }
  .export-btn span { display: none; }
}
