/* ═══════════════════════════════════════════════
   FINCA MI TESORO — gastos.css
   Misma funcionalidad, estilo de la finca
   ═══════════════════════════════════════════════ */

/* ── Variables (paleta Finca Mi Tesoro) ──────── */
:root {
  --tierra:       #3B2A1A;
  --dorado:       #C9933A;
  --dorado-claro: #E8B96A;
  --verde-pasto:  #4A6741;
  --crema:        #F5EDD8;
  --crema-oscura: #E8D9BB;
  --blanco:       #FDFAF4;
  --texto-oscuro: #2A1A0E;
  --muted:        #8B6B4A;
  --danger:       #B83232;
  --radius:       3px;
  --topbar-h:     68px;
}

/* ── Reset ────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--crema);
  color: var(--texto-oscuro);
  font-family: 'Lora', Georgia, serif;
  min-height: 100dvh;
  padding-top: var(--topbar-h);
  overflow-x: hidden;
}

/* ══════════════════════════════════════════════
   TOPBAR — igual al navbar de la finca
   ══════════════════════════════════════════════ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: rgba(59,42,26,0.96);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid var(--dorado);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5%;
  z-index: 100;
  padding-left: max(5%, env(safe-area-inset-left));
  padding-right: max(5%, env(safe-area-inset-right));
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Playfair Display', serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--dorado-claro);
  letter-spacing: 0.05em;
}

.topbar-back {
  color: var(--dorado-claro);
  text-decoration: none;
  font-size: 1.1rem;
  font-family: 'Lora', serif;
  opacity: 0.8;
  transition: opacity 0.2s;
  padding: 4px 2px;
}
.topbar-back:hover { opacity: 1; }

.topbar-icon {
  font-size: 1.1rem;
  line-height: 1;
}

/* Widget tasa de cambio */
.rate-widget {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(59,42,26,0.6);
  border: 1px solid var(--dorado);
  border-radius: var(--radius);
  padding: 6px 10px;
}

.rate-label,
.rate-unit {
  font-family: 'Lora', serif;
  font-size: 0.72rem;
  color: var(--dorado-claro);
  white-space: nowrap;
}

.rate-widget input {
  background: transparent;
  border: none;
  color: var(--dorado-claro);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
  width: 58px;
  text-align: center;
  outline: none;
  min-height: 28px;
}

.rate-widget input::-webkit-outer-spin-button,
.rate-widget input::-webkit-inner-spin-button { -webkit-appearance: none; }
.rate-widget input[type=number] { -moz-appearance: textfield; }

/* ══════════════════════════════════════════════
   CONTENIDO PRINCIPAL
   ══════════════════════════════════════════════ */
.main {
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-bottom: max(40px, env(safe-area-inset-bottom));
}

/* ══════════════════════════════════════════════
   TARJETA DE SECCIÓN
   ══════════════════════════════════════════════ */
.card {
  background: var(--blanco);
  border: 1px solid var(--crema-oscura);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 14px rgba(59,42,26,0.1);
}

/* Encabezado de tarjeta */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  background: var(--tierra);
  border-bottom: 2px solid var(--dorado);
  gap: 8px;
}

.card-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.card-emoji {
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
}

.card-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--crema);
  line-height: 1.1;
  white-space: nowrap;
}

.card-sub {
  font-size: 0.7rem;
  color: var(--dorado-claro);
  margin-top: 3px;
  font-family: 'Lora', serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Subtotal en encabezado */
.card-subtotal {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.subtotal-label {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 0.6rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dorado-claro);
  opacity: 0.75;
}

.subtotal-usd {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  color: var(--crema);
  line-height: 1.1;
  letter-spacing: 0.03em;
}

.subtotal-local {
  font-family: 'Lora', serif;
  font-size: 0.65rem;
  color: var(--dorado-claro);
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(201,147,58,0.3);
  border-radius: 2px;
  padding: 1px 6px;
  margin-top: 2px;
}

/* ══════════════════════════════════════════════
   LISTA DE ÍTEMS
   ══════════════════════════════════════════════ */
.item-list {
  padding: 6px 0;
}

.item-row {
  padding: 10px 14px;
  border-bottom: 1px solid var(--crema-oscura);
  animation: fadeSlide 0.2s ease;
}

.item-row:last-child { border-bottom: none; }

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Fila superior: nombre + botón eliminar */
.item-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.item-name-input {
  flex: 1;
  background: var(--crema);
  border: 1px solid var(--crema-oscura);
  border-radius: var(--radius);
  color: var(--texto-oscuro);
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.item-name-input:focus { border-color: var(--dorado); }
.item-name-input::placeholder { color: var(--muted); opacity: 0.6; }

/* Botón eliminar */
.btn-remove {
  background: var(--crema);
  border: 1px solid var(--crema-oscura);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.btn-remove:active,
.btn-remove:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(184, 50, 50, 0.06);
}

/* Fila inferior: monto + valor calculado */
.item-row-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-amount-input {
  flex: 1;
  background: var(--crema);
  border: 1px solid var(--crema-oscura);
  border-radius: var(--radius);
  color: var(--dorado);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  min-height: 44px;
  text-align: right;
  outline: none;
  transition: border-color 0.15s;
}

.item-amount-input:focus { border-color: var(--dorado); }

.item-amount-input::-webkit-outer-spin-button,
.item-amount-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.item-amount-input[type=number] { -moz-appearance: textfield; }

.item-computed-badge {
  background: var(--crema-oscura);
  border: 1px solid var(--crema-oscura);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: 'Lora', serif;
  font-size: 0.82rem;
  padding: 0 10px;
  min-height: 44px;
  display: flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════
   BOTÓN AGREGAR
   ══════════════════════════════════════════════ */
.btn-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: calc(100% - 28px);
  margin: 8px 14px 12px;
  min-height: 44px;
  background: transparent;
  border: 1.5px dashed var(--crema-oscura);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-family: 'Lora', serif;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-add-icon {
  font-size: 1rem;
  line-height: 1;
}

.btn-add:active,
.btn-add:hover {
  border-color: var(--dorado);
  color: var(--dorado);
  background: rgba(201, 147, 58, 0.05);
}

/* ══════════════════════════════════════════════
   FRANJA DE RECARGO
   ══════════════════════════════════════════════ */
.fee-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--crema-oscura);
  background: var(--crema);
}

.fee-strip-label {
  font-family: 'Lora', serif;
  font-size: 0.82rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}

.fee-strip-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.fee-input-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--blanco);
  border: 1px solid var(--crema-oscura);
  border-radius: var(--radius);
  padding: 0 8px;
  min-height: 40px;
}

.fee-input-wrap input {
  background: transparent;
  border: none;
  color: var(--verde-pasto);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  width: 40px;
  text-align: right;
  outline: none;
  min-height: 38px;
}

.fee-input-wrap input::-webkit-outer-spin-button,
.fee-input-wrap input::-webkit-inner-spin-button { -webkit-appearance: none; }
.fee-input-wrap input[type=number] { -moz-appearance: textfield; }

.fee-pct-sign {
  color: var(--muted);
  font-family: 'Lora', serif;
  font-size: 0.82rem;
}

.fee-result {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--verde-pasto);
  min-width: 56px;
  text-align: right;
}

/* ══════════════════════════════════════════════
   DIVISOR "+"
   ══════════════════════════════════════════════ */
.plus-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--crema-oscura);
}

/* ══════════════════════════════════════════════
   TOTAL GENERAL
   ══════════════════════════════════════════════ */
.total-card {
  margin-top: 16px;
  background: var(--tierra);
  border: 1.5px solid var(--dorado);
  border-radius: var(--radius);
  padding: 20px 16px 18px;
  position: relative;
  overflow: hidden;
}

.total-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--dorado), var(--verde-pasto));
}

.total-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.total-label {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 0.85rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--dorado-claro);
}

.total-amount {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.8rem;
  color: var(--dorado-claro);
  letter-spacing: 0.04em;
  line-height: 1;
}

.total-formula {
  font-family: 'Lora', serif;
  font-size: 0.72rem;
  color: rgba(232,185,106,0.55);
  margin-top: 10px;
  line-height: 1.6;
  word-break: break-word;
}

.total-breakdown {
  font-family: 'Lora', serif;
  font-size: 0.78rem;
  color: rgba(232,185,106,0.4);
  margin-top: 4px;
}

/* ══════════════════════════════════════════════
   TABLET — 600px+
   ══════════════════════════════════════════════ */
@media (min-width: 600px) {
  .main {
    padding: 24px 24px 48px;
  }

  .card-head { padding: 16px 20px 14px; }
  .item-row  { padding: 12px 20px; }
  .btn-add   { width: calc(100% - 40px); margin: 10px 20px 14px; }
  .fee-strip { padding: 14px 20px; }
  .total-card { padding: 24px 20px 20px; }

  .item-row-top    { margin-bottom: 0; }
  .item-row-bottom { flex: 1; }

  .item-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto;
    gap: 8px;
  }

  .item-row-top    { grid-column: 1; margin-bottom: 0; }
  .item-row-bottom { grid-column: 2; }

  .total-amount { font-size: 3.5rem; }
}

/* ══════════════════════════════════════════════
   DESKTOP — 900px+
   ══════════════════════════════════════════════ */
@media (min-width: 900px) {
  .main {
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 0 56px;
  }

  .topbar { padding: 0 calc((100% - 720px) / 2 + 20px); }

  .total-amount { font-size: 4rem; }

  .item-row {
    grid-template-columns: 1fr 180px 110px 44px;
    grid-template-rows: 1fr;
    align-items: center;
  }

  .item-row-top {
    grid-column: 1;
    margin-bottom: 0;
  }

  .item-row-top .btn-remove { display: none; }

  .item-row-bottom {
    grid-column: 2 / 4;
    display: contents;
  }

  .item-row-bottom .item-amount-input  { grid-column: 2; }
  .item-row-bottom .item-computed-badge { grid-column: 3; }

  .item-row-desktop-remove {
    grid-column: 4;
    grid-row: 1;
  }
}
