:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --gasto: #f87171;
  --ingreso: #4ade80;
  --border: #334155;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 76px;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  padding: 16px 20px 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }

#app { padding: 4px 16px 24px; max-width: 480px; margin: 0 auto; }

.tab { display: none; }
.tab.active { display: block; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

form { display: flex; flex-direction: column; gap: 14px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--primary); }

.category-row { display: flex; gap: 8px; }
.category-row select { flex: 1; }
#btn-sugerir {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1.1rem;
  padding: 0 14px;
  cursor: pointer;
}
.hint { font-size: 0.75rem; color: var(--primary); min-height: 1em; }

.type-toggle { display: flex; gap: 8px; }
.type-btn {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.type-btn.active[data-type="gasto"] { background: var(--gasto); color: #1a0505; border-color: var(--gasto); }
.type-btn.active[data-type="ingreso"] { background: var(--ingreso); color: #052e10; border-color: var(--ingreso); }

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}
.btn-primary:active { opacity: 0.85; }

.msg { text-align: center; font-size: 0.85rem; min-height: 1.2em; color: var(--ingreso); }
.msg.error { color: var(--gasto); }

.filters { display: flex; gap: 8px; margin: 12px 0 16px; }
.filters select, .filters input { width: auto; flex: 1; }

.lista { display: flex; flex-direction: column; gap: 8px; }
.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.item-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-cat { font-size: 0.95rem; font-weight: 600; }
.item-desc { font-size: 0.8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-date { font-size: 0.72rem; color: var(--muted); }
.item-amount { font-weight: 700; white-space: nowrap; }
.item-amount.gasto { color: var(--gasto); }
.item-amount.ingreso { color: var(--ingreso); }
.item-del {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 6px;
}
.empty { text-align: center; color: var(--muted); padding: 30px 0; font-size: 0.9rem; }

.cards-row { display: flex; gap: 8px; margin-bottom: 18px; }
.card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.card-label { font-size: 0.7rem; color: var(--muted); }
.card-value { font-size: 1rem; font-weight: 700; }
.card.ingreso .card-value { color: var(--ingreso); }
.card.gasto .card-value { color: var(--gasto); }
.card-pct { font-size: 0.7rem; color: var(--muted); }

canvas { margin: 8px 0 18px; max-height: 240px; }

.section-title { font-size: 0.85rem; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }

.group-block { display: flex; flex-direction: column; gap: 6px; }
.group-toggle {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-family: inherit;
}
.group-detail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-left: 14px;
  border-left: 2px solid var(--border);
  margin-left: 6px;
}
.sub-item { background: var(--surface-2); padding: 10px 12px; }


.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 1.2rem;
  cursor: pointer;
}
.nav-btn span { font-size: 0.68rem; }
.nav-btn.active { color: var(--primary); }
