*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #eff6ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --radius: 12px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

/* ── Header ── */
.header {
  background: white;
  padding: 16px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.header h1 { font-size: 1.25rem; font-weight: 700; color: var(--gray-800); }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav button {
  background: none; border: none; cursor: pointer;
  color: var(--primary); font-size: 1.2rem; padding: 4px 6px;
  border-radius: 6px;
  transition: background .15s;
}
.month-nav button:hover { background: var(--primary-light); }
.month-label { font-size: .9rem; font-weight: 600; color: var(--gray-600); min-width: 90px; text-align: center; }

/* ── Summary card ── */
.summary-card {
  margin: 16px 16px 0;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: var(--radius);
  padding: 20px;
  color: white;
  box-shadow: var(--shadow-md);
}
.summary-label { font-size: .8rem; opacity: .85; text-transform: uppercase; letter-spacing: .05em; }
.summary-total { font-size: 2rem; font-weight: 800; margin: 4px 0 12px; }
.summary-meta { display: flex; gap: 16px; font-size: .82rem; opacity: .9; }
.summary-meta span { display: flex; align-items: center; gap: 4px; }
.summary-descuento { color: #bfdbfe; font-size: .78rem; margin-top: 4px; }

/* ── Lista de gastos ── */
.section-header {
  padding: 16px 16px 8px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .07em;
}
.gastos-list { padding: 0 16px 100px; display: flex; flex-direction: column; gap: 8px; }

.gasto-item {
  background: white;
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  -webkit-tap-highlight-color: transparent;
}
.gasto-item:active { transform: scale(.98); }

.gasto-avatar {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}
.gasto-info { flex: 1; min-width: 0; }
.gasto-negocio { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gasto-fecha { font-size: .8rem; color: var(--gray-400); margin-top: 2px; }
.gasto-right { text-align: right; flex-shrink: 0; }
.gasto-monto { font-weight: 700; font-size: 1rem; color: var(--gray-800); }
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  margin-top: 3px;
}
.badge-debito { background: #dcfce7; color: #166534; }
.badge-credito { background: #fef3c7; color: #92400e; }
.badge-contado { background: var(--gray-100); color: var(--gray-600); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: .95rem; }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 24px;
  right: calc(50% - 240px + 20px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59,130,246,.5);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .15s;
  z-index: 20;
  -webkit-tap-highlight-color: transparent;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 16px rgba(59,130,246,.6); }
.fab:active { transform: scale(.95); }

/* ── Modales ── */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
.overlay.active { display: flex; }

.modal {
  background: white;
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 0 0 24px;
  animation: slideUp .25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-handle {
  width: 36px; height: 4px;
  background: var(--gray-200);
  border-radius: 2px;
  margin: 12px auto 0;
}
.modal-title {
  padding: 16px 20px 12px;
  font-size: 1.1rem;
  font-weight: 700;
}
.modal-divider { height: 1px; background: var(--gray-100); margin-bottom: 16px; }

/* ── Opciones de agregar ── */
.add-options { display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }
.add-option {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; border-radius: var(--radius);
  border: 2px solid var(--gray-200);
  background: white; cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: left;
}
.add-option:hover { border-color: var(--primary); background: var(--primary-light); }
.add-option .opt-icon { font-size: 1.8rem; }
.add-option .opt-title { font-weight: 600; font-size: .95rem; }
.add-option .opt-sub { font-size: .8rem; color: var(--gray-400); margin-top: 2px; }

/* ── Scan loading ── */
.scan-loading { text-align: center; padding: 32px 20px; }
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.scan-loading p { color: var(--gray-600); font-size: .9rem; }

/* ── Formulario ── */
.form-body { padding: 0 16px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .82rem; font-weight: 600; color: var(--gray-600); margin-bottom: 6px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  font-size: .95rem;
  color: var(--gray-800);
  background: white;
  transition: border-color .15s;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: var(--primary); }

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

.medio-pago-group { display: flex; gap: 8px; }
.medio-pago-btn {
  flex: 1; padding: 10px 6px;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  background: white; cursor: pointer;
  font-size: .82rem; font-weight: 600;
  text-align: center; color: var(--gray-600);
  transition: all .15s;
}
.medio-pago-btn.selected.debito { border-color: var(--success); background: #f0fdf4; color: #166534; }
.medio-pago-btn.selected.credito { border-color: var(--warning); background: #fffbeb; color: #92400e; }
.medio-pago-btn.selected.contado { border-color: var(--gray-400); background: var(--gray-100); color: var(--gray-800); }

.confianza-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600;
  margin-bottom: 16px;
}
.confianza-alta { background: #dcfce7; color: #166534; }
.confianza-media { background: #fef3c7; color: #92400e; }
.confianza-baja { background: #fee2e2; color: #991b1b; }

.observaciones-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .82rem;
  color: #92400e;
  margin-bottom: 16px;
}

.btn-primary {
  width: 100%; padding: 14px;
  background: var(--primary); color: white;
  border: none; border-radius: var(--radius);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: background .15s;
  margin-top: 8px;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-secondary {
  width: 100%; padding: 12px;
  background: var(--gray-100); color: var(--gray-600);
  border: none; border-radius: var(--radius);
  font-size: .9rem; font-weight: 600; cursor: pointer;
  margin-top: 8px;
}

/* ── Detalle de gasto (eliminar) ── */
.gasto-detalle { padding: 0 16px; }
.detalle-row {
  display: flex; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--gray-100);
  font-size: .9rem;
}
.detalle-row:last-of-type { border-bottom: none; }
.detalle-label { color: var(--gray-600); }
.detalle-valor { font-weight: 600; }
.btn-danger {
  width: 100%; padding: 12px;
  background: #fee2e2; color: var(--danger);
  border: none; border-radius: var(--radius);
  font-size: .9rem; font-weight: 600; cursor: pointer;
  margin-top: 16px;
}

/* ── Loading inicial ── */
#app-loading { display: flex; align-items: center; justify-content: center; height: 50dvh; color: var(--gray-400); }

/* ── Settings ── */
.btn-settings {
  background: none; border: none; cursor: pointer;
  font-size: 1.15rem; padding: 6px;
  color: var(--gray-400); border-radius: 6px;
  transition: background .15s, color .15s;
  line-height: 1;
}
.btn-settings:hover { background: var(--gray-100); color: var(--gray-800); }

.provider-badge {
  font-size: .68rem; font-weight: 700; padding: 2px 7px;
  border-radius: 20px; background: var(--primary-light); color: var(--primary);
  text-transform: uppercase; letter-spacing: .04em;
}

.key-field-wrap { position: relative; }
.key-field-wrap input { padding-right: 42px; }
.btn-show-key {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1rem; padding: 2px;
  line-height: 1;
}

.cfg-hint { font-size: .75rem; color: var(--gray-400); margin-top: 5px; }

/* Prompt accordion */
.prompt-accordion { margin-bottom: 16px; }
.prompt-accordion-btn {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--gray-100); border: 2px solid var(--gray-200);
  border-radius: 8px; cursor: pointer; font-size: .85rem; font-weight: 600;
  color: var(--gray-600); transition: background .15s;
}
.prompt-accordion-btn:hover { background: var(--gray-200); }
#cfg-prompt { resize: vertical; }

/* Provider toggle reutiliza .medio-pago-btn pero con color neutro al seleccionar */
#provider-group .medio-pago-btn.selected {
  border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark);
}

/* ── Botón de vista reportes ── */
.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 1.05rem; padding: 6px;
  border-radius: 6px; line-height: 1;
  transition: background .15s;
}
.btn-icon:hover { background: var(--gray-100); }
.btn-icon.active { background: var(--primary-light); }

/* ── Costo del scan ── */
.scan-meta-info {
  font-size: .75rem; color: var(--gray-400);
  margin-bottom: 12px; padding: 6px 10px;
  background: var(--gray-100); border-radius: 6px;
}

/* ── Reportes ── */
.report-list { padding: 0 16px 8px; display: flex; flex-direction: column; gap: 10px; }

.report-item {
  background: white; border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.report-item-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px;
}
.report-item-name { font-weight: 600; font-size: .9rem; }
.report-item-amount { font-weight: 700; font-size: .95rem; color: var(--gray-800); }
.report-bar { height: 6px; background: var(--gray-100); border-radius: 3px; overflow: hidden; }
.report-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width .4s ease; }
.report-item-meta { font-size: .75rem; color: var(--gray-400); margin-top: 4px; }

.report-historial-item {
  background: white; border-radius: var(--radius); padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .1s;
}
.report-historial-item:active { transform: scale(.98); }
.report-historial-item.activo { border: 2px solid var(--primary); }
.historial-mes { font-size: .85rem; font-weight: 600; color: var(--gray-600); }
.historial-total { font-weight: 700; font-size: 1rem; }
.historial-meta { font-size: .75rem; color: var(--gray-400); }

/* ── Campo categoría ── */
.cat-badge {
  display: inline-block; font-size: .72rem; font-weight: 600;
  padding: 2px 8px; border-radius: 20px;
  background: #e0f2fe; color: #0369a1;
}

@media (min-width: 480px) {
  .fab { right: calc(50% - 240px + 20px); }
}
