* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 var(--space-2); }
h2 { font-size: 1.1rem; margin: 0 0 var(--space-3); }
h3 { font-size: .95rem; margin: var(--space-4) 0 var(--space-2); }
.muted { color: var(--text-muted); }
.money { font-variant-numeric: tabular-nums; }
.positive { color: var(--ok); }
.negative { color: var(--danger); }
.stack > * + * { margin-top: var(--space-3); }
.inline-form { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.app-shell { min-height: 100vh; padding-bottom: 88px; }
.sidebar { display: none; }
.content { width: 100%; max-width: 1180px; margin: 0 auto; padding: var(--space-4); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); box-shadow: var(--shadow); margin-bottom: var(--space-4); }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.stat { margin: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.stat-label { color: var(--text-muted); font-size: .85rem; }
.stat-value { font-size: 1.35rem; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: var(--space-3); }

.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-around; background: var(--surface); border-top: 1px solid var(--border); padding: var(--space-2) var(--space-1) calc(var(--space-2) + env(safe-area-inset-bottom)); z-index: 20; }
.bottom-nav a { color: var(--text-muted); font-size: .7rem; display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; min-width: 0; min-height: 44px; justify-content: center; }
.bottom-nav a span { font-size: 1.1rem; }
.bottom-nav a.active { color: var(--primary); }
.fab { position: fixed; right: var(--space-4); bottom: calc(76px + env(safe-area-inset-bottom)); width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: var(--primary-contrast); font-size: 2rem; display: grid; place-items: center; box-shadow: var(--shadow); z-index: 21; }

.btn, button { min-height: 44px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); padding: var(--space-2) var(--space-4); font: inherit; cursor: pointer; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); border-color: transparent; font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn.sending { opacity: .6; cursor: wait; }
.pending { opacity: .55; }
.field { display: flex; flex-direction: column; gap: var(--space-1); font-size: .9rem; }
.field > span { color: var(--text-muted); }
input, select, textarea { min-height: 44px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); font: inherit; width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.segmented { display: flex; gap: var(--space-1); background: var(--surface-2); padding: var(--space-1); border-radius: var(--radius-sm); margin-bottom: var(--space-4); }
.segmented a { flex: 1; text-align: center; padding: var(--space-2); border-radius: 6px; color: var(--text-muted); min-height: 44px; display: grid; place-items: center; }
.segmented a.active { background: var(--surface); color: var(--text); }

.badge { display: inline-block; padding: 2px var(--space-2); border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge-danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 999px; }
.progress-ok { background: var(--ok); }
.progress-warn { background: var(--warn); }
.progress-danger { background: var(--danger); }
/* Anchos por pasos del 10%: evita estilos inline y cumple la CSP sin 'unsafe-inline'. */
.width-0 { width: 0%; }
.width-10 { width: 10%; }
.width-20 { width: 20%; }
.width-30 { width: 30%; }
.width-40 { width: 40%; }
.width-50 { width: 50%; }
.width-60 { width: 60%; }
.width-70 { width: 70%; }
.width-80 { width: 80%; }
.width-90 { width: 90%; }
.width-100 { width: 100%; }
.budget-row + .budget-row { margin-top: var(--space-3); }
.budget-head { display: flex; gap: var(--space-2); align-items: center; justify-content: space-between; margin-bottom: var(--space-1); flex-wrap: wrap; font-size: .9rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: var(--space-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; }
.empty { color: var(--text-muted); font-style: italic; }
.alert { padding: var(--space-3); border-radius: var(--radius-sm); margin-bottom: var(--space-3); }
.alert-error { color: var(--danger); border: 1px solid var(--danger); }
.chips { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.chip { min-height: 44px; padding: var(--space-2) var(--space-3); border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }

.auth-content { display: grid; place-items: center; min-height: 100vh; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-5); }
.toast { position: fixed; top: var(--space-4); left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-4); z-index: 50; display: none; }
.toast.show { display: block; }
.offline-banner { background: var(--warn); color: #1a1300; padding: var(--space-2); text-align: center; border-radius: var(--radius-sm); margin-bottom: var(--space-3); }
.skeleton { height: 84px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.skeleton-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

@media (min-width: 768px) {
  .content { padding: var(--space-5); }
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .bottom-nav { display: none; }
  .fab { bottom: var(--space-5); }
  .app-shell { padding-bottom: 0; padding-left: 220px; }
  .sidebar { display: flex; flex-direction: column; position: fixed; left: 0; top: 0; bottom: 0; width: 220px; padding: var(--space-4); background: var(--surface); border-right: 1px solid var(--border); }
  .sidebar nav { display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-5); }
  .sidebar nav a { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); min-height: 44px; display: flex; align-items: center; color: var(--text-muted); }
  .sidebar nav a.active { background: var(--surface-2); color: var(--text); }
  .logout-form { margin-top: auto; }
  .brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
}
@media (min-width: 1280px) {
  .content { max-width: 1240px; }
  .skeleton-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 380px) {
  .content { padding: var(--space-3); }
  .stat-value { font-size: 1.1rem; }
}
