/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:     #2563eb;
  --primary-dk:  #1d4ed8;
  --success:     #16a34a;
  --success-lt:  #dcfce7;
  --warning:     #d97706;
  --warning-lt:  #fef3c7;
  --danger:      #dc2626;
  --danger-lt:   #fee2e2;
  --gray-50:     #f9fafb;
  --gray-100:    #f3f4f6;
  --gray-200:    #e5e7eb;
  --gray-300:    #d1d5db;
  --gray-400:    #9ca3af;
  --gray-500:    #6b7280;
  --gray-600:    #4b5563;
  --gray-700:    #374151;
  --gray-800:    #1f2937;
  --gray-900:    #111827;
  --white:       #ffffff;
  --radius:      8px;
  --shadow:      0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg:   0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
  --font:        'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 16px; }
body { font-family: var(--font); background: var(--gray-100); color: var(--gray-800); min-height: 100vh; }

/* ── Login ──────────────────────────────────────────────────────────────────── */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}
.login-card {
  background: var(--white); border-radius: 16px; padding: 2.5rem 2rem;
  width: 100%; max-width: 380px; box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .logo-icon { font-size: 2.5rem; }
.login-logo h1 { font-size: 1.75rem; font-weight: 700; color: var(--gray-900); margin-top: .25rem; }
.login-logo p { color: var(--gray-500); font-size: .875rem; margin-top: .25rem; }
.login-error {
  background: var(--danger-lt); color: var(--danger);
  border-radius: var(--radius); padding: .6rem .875rem;
  font-size: .875rem; margin-bottom: .75rem; border: 1px solid #fca5a5;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.app-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
  background: linear-gradient(90deg, #1e3a5f 0%, #2563eb 100%);
  color: var(--white); padding: 0 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-md);
}
.navbar-brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.125rem; }
.navbar-brand span { font-size: 1.25rem; }
.navbar-right { display: flex; align-items: center; gap: .5rem; }
.navbar-user { font-size: .875rem; opacity: .9; }

/* ── Tabs ───────────────────────────────────────────────────────────────────── */
.tabs-bar {
  background: var(--white); border-bottom: 2px solid var(--gray-200);
  display: flex; overflow-x: auto; gap: 0;
  position: sticky; top: 56px; z-index: 99;
}
.tabs-bar::-webkit-scrollbar { height: 3px; }
.tabs-bar::-webkit-scrollbar-thumb { background: var(--gray-300); }
.tab-btn {
  padding: .75rem 1.25rem; border: none; background: none; cursor: pointer;
  font-size: .9rem; color: var(--gray-500); font-weight: 500;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
  white-space: nowrap; transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Main content ───────────────────────────────────────────────────────────── */
.main-content { padding: 1.25rem; max-width: 960px; margin: 0 auto; width: 100%; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem;
}
.card-title {
  font-size: 1rem; font-weight: 600; color: var(--gray-700);
  margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between;
}

/* ── Summary grid ───────────────────────────────────────────────────────────── */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.summary-card {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1.25rem; border-left: 4px solid var(--primary);
}
.summary-card.green  { border-left-color: var(--success); }
.summary-card.red    { border-left-color: var(--danger); }
.summary-card.yellow { border-left-color: var(--warning); }
.summary-card.blue   { border-left-color: var(--primary); }
.summary-card .sc-label { font-size: .75rem; color: var(--gray-500); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.summary-card .sc-value { font-size: 1.375rem; font-weight: 700; color: var(--gray-900); margin-top: .25rem; }

/* ── Month nav ──────────────────────────────────────────────────────────────── */
.month-nav {
  display: flex; align-items: center; justify-content: center; gap: 1rem;
  margin-bottom: 1.25rem;
}
.month-nav h2 { font-size: 1.125rem; font-weight: 600; text-transform: capitalize; min-width: 160px; text-align: center; }
.month-nav button { background: var(--white); border: 1px solid var(--gray-300); border-radius: var(--radius); padding: .35rem .75rem; cursor: pointer; font-size: 1rem; transition: background .15s; }
.month-nav button:hover { background: var(--gray-100); }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { background: var(--gray-50); color: var(--gray-500); font-weight: 600; text-align: left; padding: .625rem .75rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--gray-200); }
td { padding: .625rem .75rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

/* ── Pago rows ──────────────────────────────────────────────────────────────── */
tr.pagado td { opacity: .65; }
tr.pagado .estado-chip { background: var(--success-lt); color: var(--success); }
tr.pendiente .estado-chip { background: var(--danger-lt); color: var(--danger); }
tr.proximo .estado-chip { background: var(--warning-lt); color: var(--warning); }
tr.parcial .estado-chip { background: #fef3c7; color: #92400e; }
tr.parcial td { background: #fffbeb; }
tr.parcial:hover td { background: #fef9e4; }
.estado-chip { font-size: .7rem; font-weight: 600; padding: .2rem .55rem; border-radius: 9999px; white-space: nowrap; }
.restante-hint { font-size: .72rem; color: var(--warning); font-weight: 500; display: block; margin-top: .1rem; }

/* ── Chips / badges ─────────────────────────────────────────────────────────── */
.badge { display: inline-block; font-size: .7rem; font-weight: 600; padding: .15rem .5rem; border-radius: 9999px; }
.badge-admin { background: #ede9fe; color: #7c3aed; }
.badge-miembro { background: var(--gray-100); color: var(--gray-600); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .875rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: var(--white); border-color: var(--primary); }
.btn-primary:hover:not(:disabled)  { background: var(--primary-dk); }
.btn-success  { background: var(--success); color: var(--white); }
.btn-success:hover:not(:disabled)  { background: #15803d; }
.btn-danger   { background: var(--danger);  color: var(--white); }
.btn-danger:hover:not(:disabled)   { background: #b91c1c; }
.btn-outline  { background: var(--white); border-color: var(--gray-300); color: var(--gray-700); }
.btn-outline:hover:not(:disabled)  { background: var(--gray-50); }
.btn-ghost    { background: transparent; color: var(--white); border-color: rgba(255,255,255,.4); }
.btn-ghost:hover:not(:disabled)    { background: rgba(255,255,255,.15); }
.btn-sm  { padding: .3rem .65rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: .35rem .5rem; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; color: var(--gray-700); margin-bottom: .35rem; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: .5rem .75rem;
  border: 1px solid var(--gray-300); border-radius: var(--radius);
  font-size: .875rem; color: var(--gray-800); background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  font-family: var(--font);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .75rem; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--white); border-radius: 12px; padding: 1.5rem;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.modal-close { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--gray-400); line-height: 1; padding: .2rem; }
.modal-close:hover { color: var(--gray-700); }

/* ── Pago tipo toggle ───────────────────────────────────────────────────────── */
.pago-tipo-toggle {
  display: flex; border: 1px solid var(--gray-200); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 1rem;
}
.pago-tipo-btn {
  flex: 1; padding: .5rem; border: none; background: var(--white);
  font-size: .875rem; font-weight: 500; color: var(--gray-500); cursor: pointer;
  transition: background .15s, color .15s;
}
.pago-tipo-btn:first-child { border-right: 1px solid var(--gray-200); }
.pago-tipo-btn.active { background: var(--primary); color: var(--white); }
.pago-tipo-btn:not(.active):hover { background: var(--gray-50); }

/* ── Parcial banner ─────────────────────────────────────────────────────────── */
.parcial-banner {
  background: #fffbeb; border: 1px solid #fcd34d; border-radius: var(--radius);
  padding: .5rem .75rem; font-size: .8rem; color: #92400e;
  margin-bottom: 1rem; text-align: center;
}

/* ── Progress bar ───────────────────────────────────────────────────────────── */
.progress-wrap { background: var(--gray-200); border-radius: 9999px; height: 10px; overflow: hidden; margin: .4rem 0; }
.progress-bar { height: 100%; border-radius: 9999px; background: var(--primary); transition: width .4s; }
.progress-bar.done { background: var(--success); }

/* ── Bolsillo card ──────────────────────────────────────────────────────────── */
.bolsillo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.bolsillo-card {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem; border-top: 4px solid var(--primary);
}
.bolsillo-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; }
.bolsillo-card .b-saldo { font-size: 1.5rem; font-weight: 700; color: var(--success); }
.bolsillo-card .b-meta { font-size: .8rem; color: var(--gray-500); margin-top: .2rem; }
.bolsillo-card .b-actions { display: flex; gap: .4rem; margin-top: .75rem; }

/* ── Meta card ──────────────────────────────────────────────────────────────── */
.meta-card {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem; margin-bottom: .75rem;
}
.meta-card .m-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: .75rem; }
.meta-card h3 { font-size: .975rem; font-weight: 600; }
.meta-card .m-info { font-size: .8rem; color: var(--gray-500); margin-top: .75rem; display: flex; gap: 1rem; flex-wrap: wrap; }

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 2.5rem 1rem; color: var(--gray-400);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.empty-state p { font-size: .9rem; }

/* ── Sin permisos ───────────────────────────────────────────────────────────── */
.no-permisos {
  text-align: center; padding: 3rem 1rem; color: var(--gray-500);
}
.no-permisos .np-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.no-permisos h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: .4rem; color: var(--gray-700); }
.no-permisos p { font-size: .875rem; }

/* ── Config sections ────────────────────────────────────────────────────────── */
.config-section { margin-bottom: 1.5rem; }
.config-section-title {
  font-size: .95rem; font-weight: 600; color: var(--gray-600);
  padding-bottom: .5rem; border-bottom: 1px solid var(--gray-200);
  margin-bottom: .875rem; display: flex; align-items: center; justify-content: space-between;
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 9999;
  background: var(--gray-900); color: var(--white);
  padding: .65rem 1.1rem; border-radius: var(--radius);
  font-size: .875rem; box-shadow: var(--shadow-lg);
  transform: translateY(calc(100% + 1.25rem));
  transition: transform .25s ease;
  max-width: 320px;
}
#toast.show { transform: translateY(0); }
#toast.toast-success { background: var(--success); }
#toast.toast-error   { background: var(--danger); }

/* ── Checkbox custom ────────────────────────────────────────────────────────── */
.check-paid { width: 18px; height: 18px; cursor: pointer; accent-color: var(--success); }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.text-right { text-align: right; }
.text-green { color: var(--success); }
.text-red   { color: var(--danger); }
.text-yellow { color: var(--warning); }
.text-gray  { color: var(--gray-500); }
.fw-600 { font-weight: 600; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap { display: flex; align-items: center; gap: .5rem; }
.w-full { width: 100%; }

/* ── Animations ─────────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(.93); }
  to   { opacity: 1; transform: scale(1); }
}

.tab-panel.active { animation: fadeSlideIn .18s ease both; }

.modal-backdrop:not(.hidden) { animation: fadeIn .18s ease both; }
.modal-backdrop:not(.hidden) .modal { animation: modalIn .2s ease both; }

.summary-card { animation: scaleIn .2s ease both; }
.summary-card:nth-child(2) { animation-delay: .04s; }
.summary-card:nth-child(3) { animation-delay: .08s; }
.summary-card:nth-child(4) { animation-delay: .12s; }

.bolsillo-card { animation: fadeSlideIn .2s ease both; }
.meta-card     { animation: fadeSlideIn .2s ease both; }

.btn { transition: background .15s, opacity .15s, transform .1s, box-shadow .15s; }
.btn:active:not(:disabled) { transform: scale(.96); }
.btn-primary:hover:not(:disabled)  { box-shadow: 0 4px 12px rgba(37,99,235,.35); }
.btn-success:hover:not(:disabled)  { box-shadow: 0 4px 12px rgba(22,163,74,.3); }
.tab-btn { transition: color .18s, border-color .18s, background .18s; }
.tab-btn:hover { background: var(--gray-50); }

/* ── Metodo / Notas chips ────────────────────────────────────────────────────── */
.metodo-chip {
  display: inline-block; font-size: .68rem; font-weight: 600;
  padding: .15rem .45rem; border-radius: 9999px; margin-top: .2rem;
  background: #dbeafe; color: #1d4ed8;
}
.notas-hint {
  font-size: .72rem; color: var(--gray-500); cursor: default;
  display: block; margin-top: .15rem;
}

/* ── Pago info box (notas from gasto) ───────────────────────────────────────── */
.pago-info-box {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius);
  padding: .5rem .75rem; font-size: .8rem; color: #1e40af;
  margin-bottom: 1rem; white-space: pre-wrap; line-height: 1.5;
}

/* ── Check-paid bigger touch target on mobile ───────────────────────────────── */
.check-paid { width: 20px; height: 20px; cursor: pointer; accent-color: var(--success); }

/* ── mes-table-wrap ──────────────────────────────────────────────────────────── */
.mes-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .main-content { padding: .875rem; }
  .navbar { padding: 0 .875rem; }
  .navbar-user { display: none; }
  .bolsillo-grid { grid-template-columns: 1fr; }
  .modal { padding: 1.25rem; }
  .tab-btn { padding: .65rem .875rem; font-size: .8rem; }

  /* Mobile card-rows for the monthly table */
  .mes-table-wrap table thead { display: none; }
  .mes-table-wrap table,
  .mes-table-wrap tbody,
  .mes-table-wrap tr,
  .mes-table-wrap td { display: block; width: 100%; }
  .mes-table-wrap tr {
    background: var(--white); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: .6rem;
    padding: .6rem .875rem; position: relative;
    border-left: 4px solid var(--gray-300);
    animation: fadeSlideIn .2s ease both;
  }
  .mes-table-wrap tr.pagado  { border-left-color: var(--success); }
  .mes-table-wrap tr.pendiente { border-left-color: var(--danger); }
  .mes-table-wrap tr.proximo { border-left-color: var(--warning); }
  .mes-table-wrap td { padding: .2rem 0; border: none; font-size: .875rem; }
  .mes-table-wrap td:first-child { position: absolute; top: .6rem; right: .875rem; width: auto; }
  .mes-table-wrap tr:hover td { background: none; }
}
@media (max-width: 380px) {
  .summary-grid { grid-template-columns: 1fr; }
  .btn { padding: .45rem .65rem; font-size: .8rem; }
}
