:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --navy: #111827;
  --navy-2: #253148;
  --accent: #e11d48;
  --accent-2: #f59e0b;
  --blue: #2563eb;
  --success: #0f766e;
  --danger: #b91c1c;
  --shadow: 0 16px 40px rgba(17, 24, 39, .08);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: env(safe-area-inset-top) 18px calc(34px + env(safe-area-inset-bottom));
}
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 2px 8px;
}
.brand-lockup {
  width: 210px;
  max-width: 58vw;
  height: auto;
  color: var(--navy);
  display: block;
}
.brand-login { width: 236px; max-width: 80%; }
.header-user {
  margin-top: 5px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.header-actions { display: flex; gap: 8px; }
.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  display: inline-grid;
  place-items: center;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}

.month-nav {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  margin: 12px 0;
}
.month-arrow, .month-label {
  border: 0;
  background: transparent;
  min-height: 44px;
  color: var(--text);
  cursor: pointer;
}
.month-arrow { font-size: 32px; font-weight: 300; }
.month-arrow:disabled { opacity: .18; cursor: default; }
.month-label {
  text-transform: capitalize;
  font-weight: 750;
  font-size: 16px;
}

.balance-card {
  background: linear-gradient(145deg, var(--navy), var(--navy-2));
  color: white;
  border-radius: 28px;
  padding: 24px 22px 20px;
  box-shadow: var(--shadow);
}
.balance-kicker {
  display: block;
  font-size: 14px;
  color: rgba(255,255,255,.72);
  font-weight: 650;
}
.balance-number {
  display: block;
  margin-top: 5px;
  font-size: clamp(44px, 14vw, 64px);
  line-height: 1;
  letter-spacing: -2.2px;
  font-variant-numeric: tabular-nums;
}
.balance-card.is-over .balance-number { color: #fda4af; }
.progress-track {
  height: 9px;
  background: rgba(255,255,255,.14);
  border-radius: 999px;
  margin-top: 22px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width .25s ease;
}
.balance-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
  font-size: 12px;
  color: rgba(255,255,255,.66);
}

.quick-panel {
  padding: 26px 2px 10px;
}
.section-label {
  margin: 0 0 8px;
  font-size: 11px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 800;
}
.fuel-button {
  width: 100%;
  min-height: 82px;
  border: 0;
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 26px rgba(17, 24, 39, .07);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  text-align: left;
  cursor: pointer;
}
.fuel-button:active { transform: scale(.99); }
.fuel-button:disabled { opacity: .48; cursor: default; }
.fuel-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: #fff7ed;
  font-size: 25px;
}
.fuel-button small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  margin-bottom: 2px;
}
.fuel-button strong { font-size: 23px; letter-spacing: -.3px; }
.secondary-button, .primary-button, .danger-button {
  width: 100%;
  min-height: 50px;
  border-radius: 15px;
  font-weight: 750;
  cursor: pointer;
}
.secondary-button {
  margin-top: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}
.primary-button {
  border: 0;
  background: var(--navy);
  color: #fff;
  margin-top: 20px;
}
.danger-button {
  border: 0;
  background: #fee2e2;
  color: var(--danger);
  margin-top: 10px;
}
.microcopy {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.history-section { padding: 18px 2px 0; }
.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 11px;
}
.section-heading h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -.5px;
}
.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
  min-height: 44px;
  cursor: pointer;
}
.expense-list { display: grid; gap: 9px; }
.expense-row {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 18px;
  padding: 14px 15px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  text-align: left;
  cursor: pointer;
}
.expense-info strong {
  display: block;
  font-size: 15px;
  margin-bottom: 3px;
}
.expense-info span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.expense-amount {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.empty-state {
  border: 1px dashed #d1d5db;
  border-radius: 18px;
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
  background: rgba(255,255,255,.45);
}
.empty-state strong {
  display: block;
  color: var(--text);
  margin-bottom: 5px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, .42);
  padding: 12px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: min(100%, 540px);
  background: var(--surface);
  border-radius: 26px 26px 20px 20px;
  padding: 9px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 92%;
  overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(15,23,42,.18);
}
.sheet-handle {
  width: 44px;
  height: 5px;
  background: #d1d5db;
  border-radius: 999px;
  margin: 2px auto 13px;
}
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}
.sheet-header h2 { margin: 0; font-size: 23px; }
.sheet form { margin-top: 16px; }
label {
  display: block;
  margin: 14px 0 7px;
  font-size: 13px;
  font-weight: 750;
}
.optional { color: var(--muted); font-weight: 500; }
input {
  width: 100%;
  min-height: 50px;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 11px 13px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  outline: none;
}
input:focus {
  border-color: #64748b;
  box-shadow: 0 0 0 3px rgba(100,116,139,.12);
}
.money-input { position: relative; }
.money-input input { padding-right: 46px; font-size: 22px; font-weight: 750; }
.money-input span {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  width: min(calc(100% - 32px), 500px);
  border-radius: 16px;
  background: #111827;
  color: white;
  padding: 13px 15px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  font-size: 14px;
}
.toast-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.toast button {
  border: 0;
  background: transparent;
  color: #fbbf24;
  font-weight: 800;
  min-height: 36px;
  cursor: pointer;
}

.login-page {
  background: linear-gradient(160deg, #f8fafc 0%, #eef2f7 100%);
}
.login-shell {
  width: min(100%, 440px);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  align-items: center;
  padding: calc(28px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
}
.login-card {
  background: var(--surface);
  border: 1px solid rgba(229,231,235,.8);
  border-radius: 28px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.eyebrow {
  margin: 22px 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.login-card h1 {
  margin: 0;
  font-size: 31px;
  line-height: 1.08;
  letter-spacing: -1px;
}
.login-copy {
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
  margin: 11px 0 20px;
}
.login-form label { margin-top: 14px; }
.alert {
  border-radius: 13px;
  padding: 11px 12px;
  font-size: 13px;
  margin: 14px 0;
}
.alert-error { background: #fee2e2; color: #991b1b; }

.admin-shell {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: env(safe-area-inset-top) 18px calc(34px + env(safe-area-inset-bottom));
}
.admin-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  margin-top: 14px;
}
.admin-grid { display: grid; gap: 12px; }
.user-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}
.user-card-head { display: flex; justify-content: space-between; gap: 12px; }
.user-card p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

@media (min-width: 700px) {
  .app-shell { padding-left: 24px; padding-right: 24px; }
  .balance-card { padding: 30px; }
  .quick-panel { padding-top: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}


/* Administración */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.alert-success { background: #d1fae5; color: #065f46; }
.admin-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin: 12px 0 16px;
}
.admin-summary > div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 13px;
}
.admin-summary span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 3px;
}
.admin-summary strong {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}
.admin-title {
  margin: 0;
  font-size: 25px;
  letter-spacing: -.5px;
}
.admin-help {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 16px;
  line-height: 1.45;
}
.admin-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px 12px;
}
.admin-form-grid select {
  width: 100%;
  min-height: 50px;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 11px 13px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
}
.admin-span-full { grid-column: 1 / -1; }
.admin-users-section { margin-top: 24px; }
.admin-users-list { display: grid; gap: 12px; }
.user-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 15px;
  background: var(--surface);
  transition: opacity .2s ease;
}
.user-card.is-inactive { opacity: .62; }
.user-card-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.user-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}
.user-avatar {
  flex: 0 0 auto;
  width: 43px;
  height: 43px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--navy);
  color: #fff;
  font-weight: 850;
  font-size: 18px;
}
.user-identity strong {
  display: block;
  font-size: 16px;
}
.user-identity span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
.user-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef2f7;
  color: #475569;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-success { background: #d1fae5; color: #047857; }
.badge-muted { background: #e5e7eb; color: #6b7280; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.user-balance-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}
.user-balance-grid > div {
  min-width: 0;
  background: var(--surface-2);
  border-radius: 13px;
  padding: 10px;
}
.user-balance-grid span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  min-height: 24px;
}
.user-balance-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.user-balance-grid strong.negative { color: var(--danger); }
.user-details {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 4px;
}
.user-details > summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  list-style: none;
  color: var(--blue);
  font-size: 13px;
  font-weight: 750;
}
.user-details > summary::-webkit-details-marker { display: none; }
.admin-form-grid.compact {
  margin-top: 4px;
  padding-top: 10px;
}
.inline-admin-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding-top: 14px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
}
.inline-admin-form .secondary-button { margin-top: 0; }
.admin-user-actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.admin-user-actions form { margin: 0; }
.admin-user-actions .secondary-button,
.admin-user-actions .danger-button {
  margin-top: 0;
}
.user-meta {
  margin: 13px 0 0 !important;
  color: var(--muted);
  font-size: 11px !important;
  line-height: 1.45;
}

@media (min-width: 620px) {
  .admin-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .user-card-head { flex-direction: row; align-items: center; justify-content: space-between; }
  .inline-admin-form { grid-template-columns: 1fr auto; align-items: end; }
  .inline-admin-form .secondary-button { width: auto; min-width: 180px; }
  .admin-user-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
