* { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  margin: 0;
  background: #f5f5f5;
  color: #222;
}
.topnav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  background: #1f2937;
  color: white;
  padding: 0.75rem 1.5rem;
}
.topnav a { color: white; text-decoration: none; }
.topnav a:hover { text-decoration: underline; }
.topnav a.brand { font-weight: 700; margin-right: 0.5rem; }
.topnav a.brand:hover { text-decoration: none; }
.topnav .spacer { flex: 1; }
.topnav button {
  background: none;
  border: 1px solid white;
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
}
.container {
  max-width: 720px;
  margin: 2rem auto;
  padding: 0 1rem;
}
form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 360px;
  width: 100%;
}
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
input, select, button {
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}
button {
  background: #2563eb;
  color: white;
  border: none;
  cursor: pointer;
}
button:hover { background: #1d4ed8; }
.error { color: #b91c1c; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid #ddd; white-space: nowrap; }
.container { max-width: 960px; }
.filters {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  max-width: none;
  gap: 0.75rem 1rem;
}
.filters label { font-size: 0.85rem; }
.totals { margin-top: 1rem; font-size: 1rem; }
.presets { margin-top: 0.5rem; font-size: 0.85rem; }
.future-note { font-size: 0.8rem; color: #666; margin-left: 0.5rem; }
.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}
.checkbox-label input { width: auto; }
tr.future-row { opacity: 0.7; background: repeating-linear-gradient(45deg, transparent, transparent 8px, rgba(0,0,0,0.02) 8px, rgba(0,0,0,0.02) 16px); }
tr.pendiente-row { background: #fffbeb; }
.badge {
  display: inline-block;
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  white-space: nowrap;
}
.badge-programado { background: #eef2ff; color: #3730a3; }
.badge-hecho { background: #dcfce7; color: #166534; }
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-atrasado { background: #fee2e2; color: #991b1b; }
.ingreso { color: #15803d; }
.egreso { color: #b91c1c; }
td.ingreso, td.egreso { text-transform: capitalize; font-weight: 600; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.card {
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.card-label { font-size: 0.8rem; color: #666; }
.card-value { font-size: 1.4rem; font-weight: 700; }

.chart {
  width: 100%;
  max-width: 640px;
  height: auto;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.5rem;
}
.bar-ingreso { fill: #15803d; }
.bar-egreso { fill: #b91c1c; }
.chart-label { font-size: 10px; fill: #555; }
.legend { font-size: 0.85rem; color: #444; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.legend .dot.ingreso { background: #15803d; }
.legend .dot.egreso { background: #b91c1c; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 2rem;
  margin-top: 1.5rem;
}

@media (max-width: 640px) {
  .container { padding: 0 0.75rem; margin: 1rem auto; }
  .topnav { padding: 0.6rem 0.85rem; font-size: 0.85rem; gap: 0.5rem 0.75rem; }
  .topnav .spacer { flex-basis: 100%; height: 0; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.6rem; }
  .card { padding: 0.75rem; }
  .card-value { font-size: 1.15rem; }
  .dashboard-grid { grid-template-columns: 1fr; gap: 1.5rem; }
  th, td { padding: 0.4rem; font-size: 0.85rem; }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.1rem; }
}
