:root {
  --navy: #1A3A5C;
  --navy-dark: #12283f;
  --amber: #F5A623;
  --amber-dark: #d68f14;
  --bg: #ffffff;
  --text: #1c2733;
  --muted: #6b7885;
  --border: #e2e6ea;
  --danger: #c0392b;
  --success: #2e8b57;
}

* {
  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);
}

header.topbar {
  background: var(--navy);
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header.topbar a {
  color: #fff;
  text-decoration: none;
}

header.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
}

nav.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  background: var(--navy-dark);
}

nav.tabs a {
  color: #cfd9e3;
  text-decoration: none;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

nav.tabs a.active {
  color: #fff;
  border-bottom: 2px solid var(--amber);
}

main {
  padding: 1rem;
  max-width: 1000px;
  margin: 0 auto;
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.tile-value {
  font-size: 2rem;
  font-weight: 700;
}

.tile-label {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.btn {
  display: inline-block;
  background: var(--amber);
  color: #1c2733;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background: var(--amber-dark);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

input, select, textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.form-row {
  margin-bottom: 0.75rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.amount-debit {
  color: var(--danger);
}

.amount-credit {
  color: var(--success);
}

.progress {
  background: var(--border);
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
}

.progress-bar {
  background: var(--amber);
  height: 100%;
}

.progress-bar.over {
  background: var(--danger);
}

.chart-card {
  background: var(--navy);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.chart-card canvas {
  max-height: 320px;
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  padding: 1rem;
}

.login-card {
  background: #fff;
  border-radius: 10px;
  padding: 2rem;
  width: 100%;
  max-width: 340px;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.receipt-thumb {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 6px;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.pending {
  background: #fdf1dc;
  color: var(--amber-dark);
}

.badge.confirmed {
  background: #e3f3ea;
  color: var(--success);
}

@media (max-width: 600px) {
  main {
    padding: 0.75rem;
  }
  .grid {
    grid-template-columns: 1fr;
  }
}

/* Monthly Register — checkbook-style, color-coded per the original spreadsheet */
.sheet-header {
  background: #1A3A5C;
  color: #fff;
  text-align: center;
  font-weight: 700;
  padding: 0.6rem;
  border-radius: 6px 6px 0 0;
}

.col-header {
  background: #2E4057;
  color: #fff;
}

.period-header {
  color: #fff;
  font-weight: 700;
  padding: 0.5rem 0.75rem;
}

.period-header.p1 { background: #1B4F72; }
.period-header.p2 { background: #154360; }

.reg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.reg-table td, .reg-table th {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.reg-table td.amount, .reg-table td.balance {
  text-align: right;
  white-space: nowrap;
}

.row-opening { background: #EBF5FB; }
.row-closing { background: #D6EAF8; font-weight: 700; }
.row-income { background: #D5F5E3; }
.row-bill { background: #F2F3F4; }
.row-household { background: #FEF9E7; }
.row-active { background: #ffffff; }
.row-maintain { background: #FAD7A0; }
.row-fixed { background: #F2F3F4; }
.row-paidoff { background: #A9DFBF; }
.row-dead { background: #E8DAEF; color: #6b5b78; font-style: italic; }
.row-onetime { background: #FAD7A0; }
.row-blitz { background: #FFE082; font-weight: 700; }
.row-savings { background: #B2EBF2; }

.summary-block {
  background: #2E4057;
  color: #fff;
  padding: 0.5rem 0.75rem;
  font-weight: 700;
}

.summary-table td {
  padding: 0.3rem 0.6rem;
}

.summary-table td.amount {
  text-align: right;
}

.strategy-note {
  font-style: italic;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
}

.month-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.overview-blitz-row {
  background: #D4EFDF;
}

/* Dashboard debt-progress rings — pure CSS conic-gradient donuts, no JS/canvas */
.ring-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 1.25rem;
  text-align: center;
}

.debt-ring {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  margin: 0 auto 0.5rem;
  background: conic-gradient(var(--success) calc(var(--pct) * 1%), var(--border) 0);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-inner {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-pct {
  font-weight: 700;
  font-size: 1rem;
}

.ring-label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

.ring-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Bills page — cards + modal */
.bill-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.bill-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  cursor: pointer;
  background: #fff;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.bill-card:hover {
  border-color: var(--amber);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.bill-card .card-title {
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.bill-card .card-value {
  font-size: 1.15rem;
  font-weight: 700;
}

.bill-card .card-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.bill-card.add-card {
  display: flex;
  align-items: center;
  justify-content: center;
  border-style: dashed;
  color: var(--muted);
  font-weight: 600;
  min-height: 90px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 1rem;
  overflow-y: auto;
  z-index: 100;
}

.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem;
  width: 100%;
  max-width: 420px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.modal-box h3 {
  margin-top: 0;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
