:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #0b6bff;
  --blue2: #004fd6;
  --green: #16a34a;
  --orange: #f97316;
  --red: #ef4444;
  --purple: #7c3aed;
  --shadow: 0 12px 30px rgba(15,23,42,.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: radial-gradient(circle at top left, rgba(11,107,255,.11), transparent 32%), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Arial, sans-serif;
}

.hidden { display: none !important; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.8);
  box-shadow: var(--shadow);
  border-radius: 32px;
  padding: 26px;
}

.brand {
  width: 72px;
  height: 72px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: white;
  display: grid;
  place-items: center;
  font-size: 34px;
  box-shadow: 0 18px 36px rgba(11,107,255,.28);
}

.auth-card h1 {
  font-size: 34px;
  margin: 18px 0 8px;
  letter-spacing: -.8px;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.45;
  margin: 0 0 18px;
}

.form {
  display: grid;
  gap: 10px;
}

label {
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .35px;
}

input, select, textarea {
  width: 100%;
  min-height: 52px;
  border-radius: 17px;
  border: 1px solid #e6edf7;
  background: #f8fafc;
  color: var(--text);
  outline: none;
  padding: 0 14px;
  font-size: 16px;
}

textarea {
  min-height: 88px;
  padding-top: 14px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(11,107,255,.45);
  box-shadow: 0 0 0 4px rgba(11,107,255,.09);
  background: white;
}

.btn {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 17px;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
}

.primary {
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: white;
  box-shadow: 0 16px 30px rgba(11,107,255,.22);
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 900;
  padding: 10px;
}

.note {
  margin-top: 16px;
  padding: 12px;
  border-radius: 17px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.app {
  max-width: 640px;
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: 96px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 18px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(244,247,251,.88);
  backdrop-filter: blur(18px);
}

.header h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 38px);
  letter-spacing: -.9px;
}

.header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.user-pill {
  border: 1px solid #e8eef7;
  background: white;
  box-shadow: 0 8px 18px rgba(15,23,42,.06);
  border-radius: 999px;
  padding: 7px 11px 7px 7px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--blue);
  max-width: 150px;
}

.user-pill span {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eaf2ff;
  font-weight: 900;
}

.user-pill b {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content {
  padding: 0 16px 16px;
}

.balance-card {
  margin: 8px 0 14px;
  padding: 22px;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: white;
  border-radius: 30px;
  box-shadow: 0 22px 42px rgba(11,107,255,.25);
  overflow: hidden;
  position: relative;
}

.balance-card::after {
  content: "";
  position: absolute;
  width: 250px;
  height: 250px;
  border-radius: 50%;
  right: -90px;
  top: -90px;
  background: rgba(255,255,255,.12);
}

.balance-top {
  display: flex;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}

.wallet {
  width: 58px;
  height: 58px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: white;
  color: var(--blue);
  font-size: 28px;
}

.eye {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  color: white;
  background: rgba(0,0,0,.15);
}

.balance-card span,
.balance-card h2,
.balance-grid {
  position: relative;
  z-index: 2;
}

.balance-card span {
  display: block;
  margin-top: 18px;
  opacity: .88;
}

.balance-card h2 {
  margin: 6px 0 16px;
  font-size: clamp(36px, 11vw, 58px);
  line-height: 1;
  letter-spacing: -1.6px;
}

.balance-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.balance-grid div {
  padding: 10px;
  border-radius: 18px;
  background: rgba(255,255,255,.14);
}

.balance-grid small {
  opacity: .72;
  display: block;
  font-size: 10px;
}

.balance-grid b {
  font-size: 12px;
  display: block;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.metrics article,
.card {
  background: white;
  border: 1px solid rgba(226,232,240,.78);
  box-shadow: 0 8px 20px rgba(15,23,42,.06);
  border-radius: 24px;
}

.metrics article {
  padding: 15px;
  min-height: 116px;
  display: grid;
  gap: 8px;
  cursor: pointer;
}

.metrics i {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-style: normal;
  font-size: 22px;
}

.metrics small {
  color: var(--muted);
  font-weight: 800;
}

.metrics b {
  font-size: clamp(18px, 4.7vw, 24px);
  white-space: nowrap;
}

.blue { background: #eaf2ff; color: var(--blue); }
.green { background: #dcfce7; color: var(--green); }
.orange { background: #ffedd5; color: var(--orange); }
.purple { background: #ede9fe; color: var(--purple); }
.red { background: #fee2e2; color: var(--red); }

.card {
  padding: 16px;
  margin-top: 14px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.card h2 {
  margin: 0;
  font-size: 18px;
}

.card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.tag, .mini-btn {
  border: 1px solid #e8eef7;
  background: #f8fafc;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 10px;
  font-weight: 900;
  font-size: 12px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-form textarea,
.full {
  grid-column: 1 / -1;
}

.item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 13px;
  border: 1px solid #edf2f7;
  border-radius: 20px;
  margin-bottom: 10px;
  background: white;
}

.icon {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 21px;
}

.item b {
  display: block;
  font-size: 15px;
}

.item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.amount {
  font-weight: 900;
  white-space: nowrap;
  text-align: right;
}

.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.chip {
  border: 0;
  min-height: 32px;
  border-radius: 999px;
  padding: 0 10px;
  font-weight: 900;
  font-size: 12px;
  background: #f1f5f9;
  color: var(--muted);
}

.chip.green { background: #dcfce7; color: var(--green); }
.chip.red { background: #fee2e2; color: var(--red); }
.chip.blue { background: #eaf2ff; color: var(--blue); }
.chip.orange { background: #ffedd5; color: var(--orange); }

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.status.disponible { background: #dcfce7; color: var(--green); }
.status.vendido { background: #eaf2ff; color: var(--blue); }
.status.cancelado { background: #fee2e2; color: var(--red); }

.empty {
  text-align: center;
  color: var(--muted);
  background: #f8fafc;
  border: 1px dashed #dbe5f2;
  border-radius: 20px;
  padding: 22px 12px;
}

.report-grid {
  display: grid;
  gap: 10px;
}

.report-row {
  padding: 13px;
  border-radius: 18px;
  background: #f8fafc;
  border: 1px solid #eef2f7;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.report-row span {
  color: var(--muted);
  font-weight: 800;
}

.report-row b {
  text-align: right;
}

.profile-box {
  display: grid;
  gap: 8px;
}

.fab {
  position: fixed;
  right: max(18px, calc((100vw - 640px) / 2 + 18px));
  bottom: 84px;
  width: 66px;
  height: 66px;
  border-radius: 24px;
  border: 0;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: white;
  font-size: 36px;
  box-shadow: 0 18px 34px rgba(11,107,255,.34);
  z-index: 20;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  max-width: 640px;
  width: 100%;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(18px);
  border-top: 1px solid #e2e8f0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  z-index: 19;
}

.bottom-nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 16px;
  min-height: 58px;
  font-size: 11px;
  font-weight: 900;
}

.bottom-nav span {
  display: block;
  font-size: 22px;
  margin-bottom: 2px;
}

.bottom-nav button.active {
  color: var(--blue);
  background: #eaf2ff;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 94px;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: white;
  padding: 12px 16px;
  border-radius: 999px;
  font-weight: 900;
  opacity: 0;
  z-index: 100;
  transition: .2s;
  max-width: calc(100% - 36px);
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hide-money .money {
  filter: blur(8px);
  user-select: none;
}

@media (max-width: 430px) {
  .header {
    padding-left: 14px;
    padding-right: 14px;
  }

  .content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .balance-grid,
  .split,
  .grid-form {
    grid-template-columns: 1fr;
  }

  .metrics {
    gap: 10px;
  }

  .item {
    grid-template-columns: auto 1fr;
  }

  .item .amount {
    grid-column: 1 / -1;
    text-align: left;
    padding-left: 52px;
  }
}


.photo-field {
  display: grid;
  gap: 7px;
}

.photo-field small {
  color: var(--muted);
  font-size: 12px;
}

.product-gallery {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 7px 0 3px;
  margin-top: 7px;
}

.product-photo {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  flex: 0 0 auto;
}

.photo-wrapper {
  position: relative;
  flex: 0 0 auto;
}

.photo-delete {
  position: absolute;
  right: -5px;
  top: -5px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 0;
  background: #ef4444;
  color: #fff;
  font-weight: 900;
  font-size: 12px;
}

.add-photo-mini {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  border: 1px dashed #94a3b8;
  background: #f8fafc;
  color: var(--blue);
  font-weight: 900;
  flex: 0 0 auto;
}

.photo-modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.78);
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
}

.photo-modal img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: 22px;
  box-shadow: 0 30px 70px rgba(0,0,0,.35);
}

.photo-modal button {
  position: fixed;
  right: 18px;
  top: 18px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: white;
  color: var(--text);
  border: 0;
  font-size: 24px;
  font-weight: 900;
}


/* =========================================================
   RESPONSIVE FINAL FIX
   Corrige:
   - Scroll horizontal
   - Página demasiado larga por gráficos
   - Traba por canvas grande
   - Desbordes en iPhone
   ========================================================= */

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden !important;
  overscroll-behavior-x: none;
}

body {
  position: relative;
}

*,
*::before,
*::after {
  max-width: 100%;
}

.app {
  width: 100%;
  max-width: 640px;
  overflow-x: hidden !important;
}

.header,
.content,
.card,
.balance-card,
.metrics,
.split,
.grid-form,
.report-grid,
.item,
.bottom-nav {
  max-width: 100%;
  overflow-x: hidden;
}

.header {
  width: 100%;
}

.header > div {
  min-width: 0;
}

.header h1,
.header p {
  overflow-wrap: anywhere;
}

.user-pill {
  flex: 0 0 auto;
  min-width: 0;
  max-width: 135px;
}

.user-pill b {
  max-width: 78px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card {
  contain: layout paint;
}

.card-head {
  min-width: 0;
  flex-wrap: wrap;
}

.card-head > div {
  min-width: 0;
}

.card-head h2,
.card-head p {
  overflow-wrap: anywhere;
}

canvas {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  height: 170px !important;
  max-height: 170px !important;
  touch-action: pan-y;
}

#mainChart,
#reportChart {
  height: 170px !important;
  max-height: 170px !important;
}

.metrics article {
  min-width: 0;
}

.metrics b,
.balance-grid b,
.amount,
.report-row b {
  overflow: hidden;
  text-overflow: ellipsis;
}

.balance-card {
  width: 100%;
}

.balance-grid {
  min-width: 0;
}

.split {
  grid-template-columns: 1fr;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.report-row {
  min-width: 0;
  min-height: 68px;
  padding: 10px;
  border-radius: 16px;
  flex-direction: column;
  align-items: flex-start;
}

.report-row span {
  font-size: 11px;
  line-height: 1.15;
}

.report-row b {
  font-size: 13px;
  line-height: 1.15;
  text-align: left;
}

.item {
  width: 100%;
  min-width: 0;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: start;
}

.item .amount {
  grid-column: 1 / -1;
  text-align: left;
  padding-left: 52px;
  font-size: 14px;
}

.item > div {
  min-width: 0;
}

.item b,
.item span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions {
  max-width: 100%;
}

.chip {
  max-width: 100%;
}

.product-gallery {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  padding-bottom: 4px;
}

.product-gallery::-webkit-scrollbar {
  height: 0;
}

.product-photo,
.add-photo-mini {
  width: 62px;
  height: 62px;
  min-width: 62px;
  max-width: 62px;
}

.photo-wrapper {
  min-width: 62px;
  max-width: 62px;
}

.fab {
  right: 14px;
  bottom: 82px;
  width: 60px;
  height: 60px;
  border-radius: 22px;
}

.bottom-nav {
  width: 100%;
  max-width: 640px;
  left: 50%;
  right: auto;
  overflow-x: hidden;
}

.bottom-nav button {
  min-width: 0;
  font-size: 10px;
  padding: 4px 2px;
}

.bottom-nav span {
  font-size: 20px;
}

.auth-page {
  width: 100%;
  overflow-x: hidden;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  overflow-x: hidden;
}

/* iPhone / celulares */
@media (max-width: 430px) {
  .app {
    max-width: 100%;
    padding-bottom: 88px;
  }

  .header {
    padding: 14px 12px 10px;
  }

  .header h1 {
    font-size: 28px;
  }

  .header p {
    font-size: 13px;
  }

  .content {
    padding: 0 10px 12px;
  }

  .balance-card {
    margin-top: 6px;
    padding: 18px;
    border-radius: 26px;
  }

  .balance-card h2 {
    font-size: 34px;
    margin-bottom: 12px;
  }

  .balance-grid {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .metrics article {
    min-height: 98px;
    padding: 12px;
    border-radius: 20px;
  }

  .metrics i {
    width: 38px;
    height: 38px;
    border-radius: 14px;
    font-size: 19px;
  }

  .metrics small {
    font-size: 11px;
  }

  .metrics b {
    font-size: 15px;
  }

  .card {
    margin-top: 10px;
    padding: 12px;
    border-radius: 20px;
  }

  .card h2 {
    font-size: 16px;
  }

  .card p {
    font-size: 12px;
  }

  canvas,
  #mainChart,
  #reportChart {
    height: 150px !important;
    max-height: 150px !important;
  }

  .grid-form {
    grid-template-columns: 1fr;
  }

  input, select, textarea {
    min-height: 48px;
    font-size: 15px;
  }

  .btn {
    min-height: 50px;
  }
}

@media (max-width: 360px) {
  .metrics {
    grid-template-columns: 1fr;
  }

  .report-grid {
    grid-template-columns: 1fr 1fr;
  }

  canvas,
  #mainChart,
  #reportChart {
    height: 140px !important;
    max-height: 140px !important;
  }

  .bottom-nav button {
    font-size: 9px;
  }

  .bottom-nav span {
    font-size: 18px;
  }
}


/* =========================================================
   HISTÓRICO EN PESTAÑA APARTE
   ========================================================= */

.compact-history-card {
  cursor: pointer;
  margin-top: 12px;
  background: linear-gradient(135deg, #ffffff, #f8fbff);
}

.compact-history-card .no-margin {
  margin-bottom: 0;
}

.compact-history-card h2 {
  color: var(--text);
}

.compact-history-card p {
  max-width: 320px;
}

@media (max-width: 430px) {
  .compact-history-card {
    padding: 12px;
  }

  .compact-history-card .card-head {
    align-items: center;
  }

  .compact-history-card h2 {
    font-size: 15px;
  }

  .compact-history-card p {
    font-size: 11.5px;
  }
}

/* =========================================================
   AJUSTE PANEL AZUL COMPACTO - SOLO MOBILE
   Agregado sin cambiar el resto del CSS
   ========================================================= */

@media (max-width: 430px) {

  .balance-card {
    margin: 6px 0 10px !important;
    padding: 14px !important;
    border-radius: 24px !important;
  }

  .balance-top {
    margin-bottom: 4px !important;
  }

  .wallet {
    width: 44px !important;
    height: 44px !important;
    border-radius: 15px !important;
    font-size: 21px !important;
  }

  .eye {
    width: 34px !important;
    height: 34px !important;
    font-size: 14px !important;
  }

  .balance-card span {
    margin-top: 10px !important;
    font-size: 12px !important;
  }

  .balance-card h2 {
    font-size: 30px !important;
    margin: 4px 0 10px !important;
    letter-spacing: -1px !important;
  }

  .balance-grid {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }

  .balance-grid div {
    padding: 8px 10px !important;
    border-radius: 14px !important;
  }

  .balance-grid small {
    font-size: 10px !important;
  }

  .balance-grid b {
    font-size: 12px !important;
    margin-top: 2px !important;
  }
}


/* =========================================================
   MÓDULO GASTOS
   Agregado sin mover la base de datos
   ========================================================= */

.expense-summary {
  padding: 13px;
  border-radius: 18px;
  background: #fee2e2;
  color: var(--red);
  border: 1px solid #fecaca;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-weight: 900;
}

.expense-summary span {
  color: var(--red);
  font-size: 13px;
}

.expense-summary b {
  text-align: right;
}

/* Ahora la navegación tiene 6 botones */
.bottom-nav {
  grid-template-columns: repeat(6, 1fr);
}

@media (max-width: 430px) {
  .bottom-nav button {
    font-size: 9px !important;
    padding: 4px 1px !important;
  }

  .bottom-nav span {
    font-size: 18px !important;
  }

  .expense-summary {
    padding: 11px;
    border-radius: 16px;
  }

  .expense-summary span,
  .expense-summary b {
    font-size: 12px;
  }
}

@media (max-width: 360px) {
  .bottom-nav button {
    font-size: 8px !important;
  }

  .bottom-nav span {
    font-size: 17px !important;
  }
}

