:root {
  --bg: #f4f7fb;
  --sidebar: #111827;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #059669;
  --danger: #dc2626;
  --positive: #047857;
  --negative: #b91c1c;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', Arial, sans-serif;
  background: linear-gradient(180deg, #eef3f9 0%, #f8fafc 100%);
  color: var(--text);
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, #0f172a 100%);
  color: #fff;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.brand-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  padding: 22px;
  margin-bottom: 22px;
}
.brand-card h1 { margin: 8px 0; font-size: 1.6rem; }
.brand-card p, .small-text { color: rgba(255,255,255,0.72); line-height: 1.5; }
.brand-eyebrow, .page-eyebrow, .small-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
}
.nav-menu { display: flex; flex-direction: column; gap: 10px; }
.nav-link {
  text-decoration: none;
  color: rgba(255,255,255,0.84);
  padding: 14px 16px;
  border-radius: 16px;
  transition: all .2s ease;
  font-weight: 600;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,0.12); color: #fff; }
.main-content { padding: 28px; }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.page-header h2 { margin: 6px 0 0; font-size: 2rem; }
.header-actions, .form-actions, .row-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.compact { justify-content: flex-end; }
.flash-wrapper { margin-bottom: 18px; }
.flash-message {
  padding: 14px 16px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 14px;
  color: #9a3412;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.cards-grid, .content-grid { display: grid; gap: 20px; align-items: start; }
.cards-grid { margin-bottom: 32px; }
.content-grid { margin-top: 8px; }
.cards-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cards-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two-columns-65-35 { grid-template-columns: 1.3fr 0.7fr; }
.two-columns-40-60 { grid-template-columns: 0.85fr 1.15fr; }
.two-columns-50-50 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-card, .panel, .action-card {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(255,255,255,0.75);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card { padding: 22px; }
.stat-label { color: var(--muted); font-weight: 600; }
.stat-value { margin-top: 12px; font-size: 2rem; font-weight: 800; }
.stat-note { color: var(--muted); margin-top: 8px; line-height: 1.5; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.panel { padding: 22px; overflow: hidden; }
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 18px;
}
.panel-header h3 { margin: 0 0 6px; }
.panel-header p { margin: 0; color: var(--muted); }
.quick-actions { display: grid; gap: 14px; }
.action-card {
  display: block;
  padding: 18px;
  text-decoration: none;
  color: inherit;
  transition: transform .15s ease, box-shadow .15s ease;
}
.action-card:hover { transform: translateY(-2px); }
.action-card strong { display: block; margin-bottom: 6px; }
.action-card span { color: var(--muted); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}
.form-field label { display: block; margin-bottom: 8px; font-weight: 700; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  font: inherit;
}
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 14px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-weight: 700;
  font: inherit;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e5e7eb; color: #111827; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-small { padding: 8px 12px; font-size: .92rem; }
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: .82rem;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.pill {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: .84rem;
  font-weight: 700;
}
.pill.income { background: #d1fae5; color: #065f46; }
.pill.expense { background: #fee2e2; color: #991b1b; }
.empty-cell { color: var(--muted); text-align: center; }
.chart-panel canvas { min-height: 320px; }
.narrow-panel { max-width: 900px; }
.mb-24 { margin-bottom: 24px; }

.mobile-topbar, .mobile-bottom-nav { display: none; }
@media (max-width: 1200px) {
  .cards-grid-4, .cards-grid-3, .two-columns-65-35, .two-columns-40-60, .two-columns-50-50 {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 980px) {
  html {
    scroll-padding-bottom: 96px;
  }

  body {
    display: block;
    min-height: 100dvh;
    padding-bottom: 92px;
  }

  .sidebar {
    display: none;
  }

  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 90;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    background: rgba(17, 24, 39, 0.96);
    color: #fff;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(14px);
  }

  .mobile-topbar strong {
    display: block;
    font-size: 1.05rem;
    line-height: 1.2;
  }

  .mobile-eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.66rem;
    font-weight: 800;
    color: rgba(255,255,255,0.72);
  }

  .mobile-add-btn {
    width: 44px;
    height: 44px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    font-size: 1.65rem;
    font-weight: 800;
    line-height: 1;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    padding: 8px max(8px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    background: rgba(255,255,255,0.96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 26px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(14px);
  }

  .mobile-bottom-nav a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 14px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 800;
  }

  .mobile-bottom-nav a.active {
    background: #e8efff;
    color: var(--primary);
  }

  .main-content {
    padding: 16px 14px 112px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 18px;
  }

  .page-header h2 {
    font-size: 1.72rem;
    line-height: 1.15;
  }

  .page-eyebrow {
    font-size: 0.66rem;
  }

  .header-actions,
  .form-actions,
  .row-actions {
    width: 100%;
  }

  .header-actions .btn,
  .form-actions .btn {
    width: 100%;
  }

  .cards-grid,
  .content-grid {
    gap: 14px;
  }

  .cards-grid {
    margin-bottom: 18px;
  }

  .stat-card,
  .panel,
  .action-card {
    border-radius: 18px;
  }

  .stat-card,
  .panel {
    padding: 18px;
  }

  .stat-value {
    font-size: 1.65rem;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .compact {
    justify-content: stretch;
  }

  .form-grid {
    gap: 12px;
  }

  .span-2, .span-3, .span-4, .span-6, .span-8, .span-12 {
    grid-column: span 12;
  }

  .form-field input,
  .form-field select,
  .form-field textarea {
    min-height: 46px;
    font-size: 16px;
  }

  .btn {
    min-height: 46px;
  }

  .table-wrapper {
    margin-left: -4px;
    margin-right: -4px;
    padding-bottom: 4px;
  }

  table {
    min-width: 720px;
  }

  th, td {
    padding: 12px 10px;
  }

  .quick-actions {
    gap: 12px;
  }

  .chart-panel canvas {
    min-height: 250px;
    max-height: 360px;
  }
}

@media (max-width: 480px) {
  .main-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .panel,
  .stat-card {
    padding: 16px;
  }

  .page-header h2 {
    font-size: 1.55rem;
  }

  .mobile-bottom-nav a {
    font-size: 0.72rem;
  }
}


/* Autenticacion */
.auth-body {
  display: block;
  min-height: 100vh;
  background: linear-gradient(135deg, #111827 0%, #1f2937 48%, #2563eb 100%);
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 28px;
  padding: 30px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.26);
}

.auth-brand {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--primary);
}

.auth-card h1 {
  margin: 10px 0 8px;
  font-size: 2rem;
}

.auth-copy,
.auth-hint {
  color: var(--muted);
  line-height: 1.5;
}

.auth-form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.auth-form .btn {
  width: 100%;
}

.auth-flashes {
  margin-top: 16px;
  margin-bottom: 0;
}

.auth-hint {
  margin: 18px 0 0;
  font-size: 0.88rem;
}

.nav-link-logout {
  margin-top: 14px;
  color: #fecaca;
}

/* Cuenta y usuarios */
.mt-24 {
  margin-top: 24px;
}

.account-summary {
  display: grid;
  gap: 16px;
}

.account-summary > div {
  padding: 16px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.account-summary strong {
  display: block;
  margin-top: 6px;
  font-size: 1.05rem;
}

.small-label-dark {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form select,
.inline-form input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  font: inherit;
}

.user-actions {
  display: grid;
  gap: 8px;
}

@media (max-width: 760px) {
  .inline-form {
    align-items: stretch;
  }

  .inline-form select,
  .inline-form input,
  .inline-form button,
  .user-actions .btn {
    width: 100%;
  }
}


/* Marca familiar en panel lateral */
.brand-card {
  overflow: hidden;
}

.brand-family {
  margin: 14px 0 12px;
  font-weight: 700;
  color: rgba(255,255,255,0.88);
}

.brand-icon {
  display: block;
  width: 96px;
  height: 96px;
  max-width: 52%;
  object-fit: contain;
  margin: 6px auto 0;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.22));
}

@media (max-width: 980px) {
  .brand-icon {
    width: 78px;
    height: 78px;
    max-width: 42%;
  }
}

/* Pagos programados */
:root {
  --panel-soft: #f8fafc;
  --warning: #d97706;
}

.upcoming-panel {
  border: 1px solid #bfdbfe;
}

.upcoming-list {
  display: grid;
  gap: 12px;
}

.upcoming-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}

.upcoming-item strong,
.upcoming-item span,
.upcoming-item small {
  display: block;
}

.upcoming-item span {
  margin-top: 4px;
  color: var(--muted);
}

.upcoming-item small,
.muted-text {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.5;
}

.upcoming-item.overdue {
  border-color: #fecaca;
  background: #fff7f7;
}

.upcoming-item.today {
  border-color: #fed7aa;
  background: #fff7ed;
}

.empty-state {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
  background: var(--panel-soft);
}

.filter-tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.checkbox-field {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.check-label {
  display: flex !important;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px !important;
}

.check-label input {
  width: auto;
  min-height: auto;
}

.payment-summary {
  display: grid;
  gap: 14px;
}

.payment-summary > div {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
}

.payment-summary strong {
  display: block;
  margin-top: 6px;
}

button:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 980px) {
  .mobile-bottom-nav {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .upcoming-item {
    flex-direction: column;
    align-items: stretch;
  }

  .upcoming-item .btn {
    width: 100%;
  }
}
