:root {
  --bg: #ffffff;
  --card-bg: #ffffff;
  --text: #1a1d1f;
  --text-2: #6f767e;
  --text-muted: #9a9fa5;
  --border: #edeef0;
  --shadow-sm: 0 1px 2px rgba(20, 20, 20, 0.04);
  --shadow-md: 0 4px 16px rgba(20, 20, 20, 0.06);
  --accent: #2f9e56;
  --accent-hover: #268047;
  --accent-light: rgba(47, 158, 86, 0.10);
  --danger: #e5484d;
  --danger-light: rgba(229, 72, 77, 0.10);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

input {
  font-family: inherit;
  font-size: 16px; /* evita zoom automático en iOS */
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  padding: 13px 20px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-text {
  background: none;
  color: var(--text-2);
  padding: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.field input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  background: var(--card-bg);
  color: var(--text);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.error-msg {
  color: var(--danger);
  background: var(--danger-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  display: none;
}
.error-msg.visible { display: block; }

/* ── Icons: trazo simple, mismo grosor ─────────────────────────────────── */
.icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── App shell ──────────────────────────────────────────────────────────── */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + 24px);
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 8px;
}
.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}
.topbar .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border: none;
}

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

/* ── Bottom nav ─────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  max-width: 480px;
  margin: 0 auto;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 40;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 8px;
}
.nav-item.active { color: var(--accent); }

.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(47, 158, 86, 0.35);
  cursor: pointer;
  z-index: 41;
}
.fab .icon { width: 26px; height: 26px; stroke-width: 2.2; }

/* ── Bottom sheet (formularios) ────────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.35);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sheet-overlay.visible { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--card-bg);
  border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 61;
  max-height: 88vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sheet-overlay.visible .sheet { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 0 auto 4px;
}
.sheet h2 { font-size: 18px; margin: 0; }

.field select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.field select:focus { outline: none; border-color: var(--accent); }

.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.sheet-actions .btn { flex: 1; }
.btn-danger-text { background: none; color: var(--danger); font-weight: 600; }
.btn-secundario { background: var(--bg); color: var(--text); font-weight: 600; }

/* ── Dictado por voz ────────────────────────────────────────────────────── */
.btn-mic {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--card-bg); color: var(--text-2);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.btn-mic .icon { width: 19px; height: 19px; }
.btn-mic.grabando {
  background: var(--danger); border-color: var(--danger); color: #fff;
  animation: pulso-mic 1.1s ease-in-out infinite;
}
@keyframes pulso-mic {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(229, 72, 77, 0); }
}

/* ── Captura con IA ─────────────────────────────────────────────────────── */
.ia-captura-row { display: flex; gap: 8px; }
.ia-captura-row input {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 14px; background: var(--card-bg); color: var(--text);
}
.ia-captura-row input:focus { outline: none; border-color: var(--accent); }
.btn-ia {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: var(--radius-sm);
  border: none; background: var(--accent); color: #fff; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.btn-ia:disabled { opacity: 0.6; }
.ia-captura-msg {
  font-size: 13px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--accent-light); color: var(--text); margin-top: 8px;
}
.ia-captura-msg.error { background: var(--danger-light); color: var(--danger); }
.ia-captura-separador {
  text-align: center; font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em; margin: 4px 0;
}

/* ── Segmented control (tabs) ──────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  gap: 4px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
}
.tab-btn.active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.importe-input {
  font-size: 32px;
  font-weight: 700;
  text-align: center;
  border: none;
  background: none;
  width: 100%;
  padding: 8px 0;
  color: var(--text);
}
.importe-input:focus { outline: none; }
.importe-wrap { display: flex; align-items: center; justify-content: center; gap: 6px; }
.importe-wrap .signo { font-size: 22px; font-weight: 700; color: var(--text-muted); }

/* ── Toast simple ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 84px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 90%;
  text-align: center;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
