:root {
  --bg: #f3f5fa;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --text: #0f172a;
  --text-soft: #1e293b;
  --muted: #6b7488;
  --muted-soft: #94a1b8;
  --border: #e6e9f2;
  --border-soft: #eef0f7;

  --ink: #0b1220;
  --ink-soft: #16213a;

  --accent: #4f46e5;
  --accent-2: #6366f1;
  --accent-soft: #eef0ff;
  --danger: #e11d48;
  --success: #16a34a;
  --whatsapp: #25d366;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 1px rgba(15, 23, 42, .03);
  --shadow-md: 0 8px 24px -8px rgba(15, 23, 42, .16);
  --shadow-lg: 0 16px 40px -12px rgba(15, 23, 42, .22);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: 'Manrope', var(--font);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0e17;
    --bg-elevated: #121826;
    --card: #131a29;
    --text: #f1f5f9;
    --text-soft: #e2e8f0;
    --muted: #93a0b8;
    --muted-soft: #64748b;
    --border: #1f2937;
    --border-soft: #1a2233;
    --accent-soft: #1c1f3d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, .5);
    --shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  padding-bottom: 96px;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

::selection { background: var(--accent); color: white; }

/* Fondo decorativo sutil, fijo detrás de todo */
.bg-decor {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(600px circle at 100% -10%, rgba(99, 102, 241, .16), transparent 60%),
    radial-gradient(500px circle at -10% 10%, rgba(22, 163, 74, .10), transparent 55%);
}

/* ============ HEADER ============ */
header.app-header {
  background: linear-gradient(160deg, var(--ink) 0%, var(--ink-soft) 100%);
  color: white;
  padding: 20px 18px 22px;
  position: sticky;
  top: 0;
  z-index: 20;
  border-radius: 0 0 26px 26px;
  box-shadow: var(--shadow-lg);
}

.app-header-top { margin-bottom: 16px; }

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 46px;
  height: auto;
  flex: none;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(191, 158, 84, .35));
}

.brand-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #c9a86a;
  background: rgba(201, 168, 106, .12);
  border: 1px solid rgba(201, 168, 106, .3);
  padding: 3px 9px;
  border-radius: var(--radius-pill);
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 800;
  margin: 0 0 2px;
  letter-spacing: -.01em;
}

.brand p {
  margin: 0;
  font-size: 12px;
  color: #94a3b8;
  font-weight: 500;
}

.modo-toggle {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
  padding: 4px;
  border-radius: var(--radius-pill);
  margin-bottom: 12px;
}

.modo-btn {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: var(--radius-pill);
  padding: 9px 0;
  font-size: 12.5px;
  font-weight: 700;
  color: #94a3b8;
  cursor: pointer;
  transition: all .15s ease;
}

.modo-btn.active {
  background: rgba(255, 255, 255, .95);
  color: var(--ink);
}

.header-stat {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.hs-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #94a3b8;
  font-weight: 700;
  margin-bottom: 4px;
}

.hs-monto {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.02em;
}

/* ============ LAYOUT ============ */
main {
  padding: 18px 16px 6px;
  max-width: 480px;
  margin: 0 auto;
}

.screen { display: none; }
.screen.active {
  display: block;
  animation: screenIn .32s cubic-bezier(.2, .7, .2, 1);
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-title {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 24px 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-title em {
  font-style: normal;
  text-transform: none;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted-soft);
  font-size: 11.5px;
}

.st-icon { font-size: 14px; }

/* ============ EMPRESA ============ */
.empresa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 10px;
}

.empresa-btn {
  border: 2px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px 8px 12px;
  font-size: 12.5px;
  line-height: 1.3;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  color: var(--text-soft);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease, background .12s ease;
  box-shadow: var(--shadow-sm);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.empresa-btn .eb-logo {
  height: 34px;
  max-width: 100%;
  object-fit: contain;
}

.empresa-btn .eb-icon {
  font-size: 26px;
  line-height: 1;
}

.empresa-btn .eb-nombre { color: var(--text-soft); }

.empresa-btn:active { transform: scale(0.96); }

.empresa-btn.selected {
  border-color: var(--emp-color, var(--accent));
  background: color-mix(in srgb, var(--emp-color, var(--accent)) 10%, var(--card));
  box-shadow: 0 8px 20px -10px var(--emp-color, var(--accent));
  transform: translateY(-2px);
}

.empresa-btn.selected::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--emp-color, var(--accent));
  color: white;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empresa-btn.selected .eb-nombre { color: var(--emp-color, var(--accent)); }

/* ============ CHIPS ============ */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1.5px solid var(--border);
  background: var(--card);
  padding: 10px 15px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-soft);
  transition: all .12s ease;
  box-shadow: var(--shadow-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip:active { transform: scale(0.96); }

.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 700;
  box-shadow: 0 8px 18px -6px rgba(79, 70, 229, .55);
}

.otro-input {
  margin-top: 10px;
}

.otro-input.hidden { display: none; }

.sub-row {
  margin-top: 10px;
  padding: 10px 10px 4px;
  background: var(--border-soft);
  border-radius: var(--radius-md);
  gap: 7px;
}

.sub-row.hidden { display: none; }

.sub-row .chip {
  background: var(--card);
  padding: 8px 13px;
  font-size: 12.5px;
}

.sub-row .chip.selected {
  background: var(--accent);
  border-color: var(--accent);
}

.sugerencias-row {
  margin-top: 8px;
  gap: 6px;
}

.sugerencias-row.hidden { display: none; }

.sugerencias-row .chip-sug {
  border: 1.5px dashed var(--border);
  background: transparent;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.sugerencias-row .chip-sug:active { transform: scale(0.96); }
.sugerencias-row .chip-sug::before { content: '↺ '; }

/* ============ INPUTS ============ */
.amount-wrap {
  background: var(--card);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.amount-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.amount-wrap span {
  font-size: 26px;
  font-weight: 700;
  color: var(--muted-soft);
}

.amount-wrap input {
  border: none;
  outline: none;
  font-size: 30px;
  font-weight: 800;
  font-family: var(--font-display);
  width: 100%;
  background: transparent;
  color: var(--text);
}

input[type="text"], textarea, select {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 14.5px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}

input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

textarea { resize: none; min-height: 60px; }

.metodo-grid { display: flex; gap: 8px; }
.metodo-grid .chip { flex: 1; justify-content: center; }

/* ============ BOTONES ============ */
.submit-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 17px;
  font-size: 15.5px;
  font-weight: 700;
  margin-top: 26px;
  cursor: pointer;
  box-shadow: 0 12px 24px -10px rgba(79, 70, 229, .6);
  transition: transform .12s ease, box-shadow .12s ease;
}

.submit-btn:active { transform: scale(0.985); }
.submit-btn:disabled { opacity: .5; box-shadow: none; }

.status-msg {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
  min-height: 18px;
}

.status-msg.ok { color: var(--success); }
.status-msg.error { color: var(--danger); }
.status-msg.pending { color: #d97706; }

/* ============ RESUMEN ============ */
.periodo-toggle {
  display: flex;
  gap: 8px;
  background: var(--border-soft);
  padding: 4px;
  border-radius: var(--radius-pill);
  margin-bottom: 16px;
}

.periodo-btn {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: var(--radius-pill);
  padding: 10px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s ease;
}

.periodo-btn.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.combinado-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, var(--ink) 0%, var(--ink-soft) 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  margin-bottom: 8px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.cc-decor {
  position: absolute;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, .35), transparent 70%);
  top: -110px;
  right: -60px;
}

.cc-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #94a3b8;
  font-weight: 700;
  position: relative;
}

.cc-sub { font-size: 12px; color: #64748b; margin-top: 2px; position: relative; }

.cc-monto {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 800;
  margin: 10px 0 4px;
  letter-spacing: -.02em;
  position: relative;
}

.cc-desde { font-size: 11.5px; color: #64748b; position: relative; }

.breakdown-item {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-soft);
}

.breakdown-item .bi-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13.5px;
  margin-bottom: 8px;
}

.breakdown-item .bi-nombre { font-weight: 600; display: flex; align-items: center; color: var(--text-soft); }
.breakdown-item .bi-monto { font-weight: 700; font-family: var(--font-display); }
.breakdown-item .bi-pct { font-weight: 600; color: var(--muted-soft); font-size: 11.5px; margin-left: 6px; }

.breakdown-bar {
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--border-soft);
  overflow: hidden;
}

.breakdown-bar > div {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width .5s cubic-bezier(.2, .7, .2, 1);
}

.bi-logo {
  height: 18px;
  max-width: 84px;
  object-fit: contain;
  margin-right: 8px;
}

.icon-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  font-size: 12px;
  margin-right: 8px;
  flex: none;
}

.whatsapp-btn {
  width: 100%;
  background: var(--whatsapp);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 14.5px;
  font-weight: 700;
  margin-top: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  box-shadow: 0 12px 24px -10px rgba(37, 211, 102, .55);
  transition: transform .12s ease;
}

.whatsapp-btn:active { transform: scale(0.985); }
.whatsapp-btn:disabled { opacity: .5; box-shadow: none; }

/* ============ HISTORIAL ============ */
.historial-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gasto-item {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-soft);
}

.gasto-item .left { flex: 1; min-width: 0; }
.gasto-item .categoria { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; font-weight: 600; }
.gasto-item .descripcion { font-size: 14.5px; font-weight: 700; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-soft); }
.gasto-item .fecha { font-size: 11.5px; color: var(--muted-soft); }
.gasto-item .monto { font-size: 15.5px; font-weight: 800; font-family: var(--font-display); white-space: nowrap; }
.gasto-item .badge { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; flex: none; }

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding: 44px 16px;
  background: var(--card);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
}

.pending-tag {
  display: inline-block;
  font-size: 10px;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin-left: 6px;
  font-weight: 700;
}

.refresh-btn {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease;
}

.refresh-btn:active { transform: rotate(180deg); }

/* ============ NAV ============ */
nav.bottom-nav {
  position: fixed;
  bottom: 14px;
  left: 14px;
  right: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  padding: 6px;
  z-index: 20;
  box-shadow: var(--shadow-lg);
  max-width: 452px;
  margin: 0 auto;
}

nav.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  padding: 9px 0;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-weight: 600;
  position: relative;
  z-index: 2;
  transition: color .15s ease;
  border-radius: var(--radius-md);
}

nav.bottom-nav button .icon { font-size: 19px; }
nav.bottom-nav button.active { color: var(--accent); font-weight: 800; }

.nav-pill {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 6px;
  width: calc((100% - 12px) / 3);
  background: var(--accent-soft);
  border-radius: var(--radius-md);
  z-index: 1;
  transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}
