* { box-sizing: border-box; }
body {
  font-family: -apple-system, Segoe UI, Arial, sans-serif;
  background: #f4f5f7;
  color: #1c1e21;
  margin: 0;
}
nav {
  background: #1c2b3a;
  padding: 0.75rem 1.5rem;
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}
nav a {
  color: #cfe1f0;
  text-decoration: none;
  font-size: 0.95rem;
}
nav a:hover { color: #fff; }
main {
  max-width: 960px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}
h1, h2, h3 { color: #1c2b3a; }
.card {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.92rem;
}
th { color: #6b7280; font-weight: 600; }
.total-row td { font-weight: 700; border-top: 2px solid #1c2b3a; }
.bucket-bar {
  display: flex; height: 28px; border-radius: 6px; overflow: hidden; margin: 0.75rem 0;
}
.bucket-bar span { display: block; height: 100%; }
.bucket-recurring { background: #4c8bf5; }
.bucket-installment { background: #f59e4c; }
.bucket-bimonthly { background: #9b59d0; }
.bucket-variable { background: #55b585; }
.bucket-wishlist { background: #d0d5dd; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.85rem; margin-bottom: 1rem; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.35rem; }
.pill {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  background: #e5e7eb; font-size: 0.78rem;
}
.pill.dup { background: #fde2e1; color: #a12622; }
.pill.new { background: #dcf5e3; color: #14532d; }
.pill.low-conf { background: #fef3c6; color: #7a5b00; }
form.inline { display: inline; }
input, select, button {
  font-family: inherit; font-size: 0.92rem; padding: 0.4rem 0.55rem;
  border-radius: 6px; border: 1px solid #d1d5db;
}
button {
  background: #1c2b3a; color: #fff; border: none; cursor: pointer;
}
button:hover { background: #2c4157; }
button.secondary { background: #e5e7eb; color: #1c2b3a; }
.flash { background: #dcf5e3; padding: 0.6rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.muted { color: #6b7280; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

details {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}
details summary {
  cursor: pointer;
  padding: 0.4rem 0;
  list-style: none;
}
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▶ "; font-size: 0.8em; }
details[open] summary::before { content: "▼ "; }
details table { margin-top: 0.5rem; }

@media (max-width: 640px) {
  nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem 1rem;
    gap: 1rem;
  }
  nav a { white-space: nowrap; flex-shrink: 0; }

  main { padding: 0 0.75rem; }
  .card { padding: 1rem; }

  /* Plain key-value tables (2-3 short columns) just wrap their text -
     forcing nowrap here pushed the value column off-screen with no hint
     that it was scrollable. Genuinely wide tables opt in via .table-wide,
     where nowrap + the card's horizontal scroll is the better tradeoff. */
  .table-wide td, .table-wide th { white-space: nowrap; }

  form:not(.inline) label { display: block; margin-bottom: 0.5rem; }
  form:not(.inline) input[type="text"],
  form:not(.inline) input[type="number"],
  form:not(.inline) input[type="date"],
  form:not(.inline) input[type="password"],
  form:not(.inline) select {
    width: 100%;
  }

  /* iOS Safari auto-zooms the page when focusing a field with a
     computed font-size under 16px - keep inputs at 16px to avoid it. */
  input, select, button {
    font-size: 16px;
    padding: 0.6rem 0.7rem;
  }
}
