:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --card-border: #e6e9ef;
  --text: #16213a;
  --text-dim: #6b7280;
  --navy: #0f1b3d;
  --navy-soft: #16264f;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --green: #16a34a;
  --green-soft: rgba(22, 163, 74, 0.12);
  --yellow: #d97706;
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.1);
  --purple: #7c3aed;
  --orange: #f97316;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px -4px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

/* Muchos formularios se togglean con el atributo [hidden] pero tambien traen un
   style="display:flex" inline para cuando SI se muestran. Sin este !important, ese inline
   style gana siempre (origen "author" vs UA stylesheet) y el formulario nunca se oculta
   de verdad — se veia expandido de entrada aunque hidden=true. */
[hidden] { display: none !important; }

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

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding-bottom: 72px;
}

/* ---------- Sidebar (desktop) ---------- */
.sidebar {
  display: none;
  width: 240px;
  flex-shrink: 0;
  background: var(--navy);
  color: #cbd5e1;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 800;
  font-size: 19px;
  padding: 6px 10px 22px;
  letter-spacing: -0.02em;
}
.sidebar-logo-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #60a5fa);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo-plus { color: #60a5fa; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.sidebar-nav a, .sidebar-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #aab4c8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active {
  background: var(--accent);
  color: #fff;
}
.sidebar-nav .icon, .sidebar-profile .icon { font-size: 16px; width: 18px; text-align: center; }

.sidebar-modes {
  margin: 14px 0;
  padding: 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-mode {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}
.sidebar-mode.active { background: rgba(37, 99, 235, 0.25); }
.sidebar-mode.disabled { color: #6b7686; cursor: not-allowed; justify-content: space-between; }
.sidebar-soon {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 999px;
}

.sidebar-profile {
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 8px;
  padding-top: 14px;
}
.sidebar-profile.active { color: #fff; }


header.top {
  padding: 24px 16px 10px;
}
header.top h1 {
  font-size: 24px;
  margin: 0 0 2px;
  letter-spacing: -0.02em;
  font-weight: 800;
}
header.top p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

main {
  padding: 12px 16px 24px;
  max-width: 640px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 12px;
  font-weight: 700;
}

.big-number {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-card .stat-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.stat-card .stat-trend {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
}
.stat-icon {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.progress-track {
  background: #eef1f6;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  margin: 10px 0 6px;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width 0.3s ease;
}
.progress-fill.warn { background: var(--yellow); }
.progress-fill.danger { background: var(--red); }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--card-border);
  font-size: 14px;
}
.row:last-child { border-bottom: none; }
.row .muted { color: var(--text-dim); font-size: 12px; }
.muted { color: var(--text-dim); }

.amount { font-weight: 700; }
.amount.neg { color: var(--red); }
.amount.pos { color: var(--green); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #eef1f6;
  color: var(--text-dim);
}

.badge-cat {
  background: var(--cat-color-soft, #eef1f6);
  color: var(--cat-color, var(--text-dim));
}

.cat-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cat-color, var(--text-dim));
  flex-shrink: 0;
}

nav.bottom {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--card-border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
}
nav.bottom a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  text-align: center;
}
nav.bottom a.active { color: var(--accent); }
nav.bottom a .icon { font-size: 18px; }

select, input {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
}
select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

.progress-mini {
  background: #eef1f6;
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-mini > div {
  height: 100%;
  background: var(--accent);
}

canvas { max-width: 100%; }

a { color: var(--accent); }

button {
  font-family: inherit;
  cursor: pointer;
}

@media (min-width: 900px) {
  .sidebar { display: flex; }
  .app-main { padding-bottom: 32px; }
  nav.bottom { display: none; }
  main { max-width: 880px; margin: 0 auto; padding: 28px 32px; }
}
