:root {
  --ink: #1E2A28;
  --bg: #ECEAE0;
  --surface: #FFFFFF;
  --line: #D9D5C7;
  --income: #2F6F62;
  --expense: #B85C4A;
  --accent: #1B4B5A;
  --muted: #6B675C;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'IBM Plex Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
}

h1, h2, h3, .brand-name { font-family: 'Fraunces', serif; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
  gap: 12px;
}
.brand-name { font-size: 1.6rem; font-weight: 600; }
.brand-sub { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tabs a {
  margin-left: 20px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.95rem;
  padding-bottom: 4px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a:first-child { margin-left: 0; }
.tabs a.active, .tabs a:hover { color: var(--ink); border-bottom-color: var(--accent); }

.content { max-width: 1150px; margin: 0 auto; padding: 40px 24px; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.subtle { color: var(--muted); margin: 4px 0; }

.summary-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 32px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.card-label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.card-value { font-size: 1.8rem; font-family: 'Fraunces', serif; display: block; }
.card-sub { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 6px; }
.card.income .card-value { color: var(--income); }
.card.expense .card-value { color: var(--expense); }
.card.net.positive .card-value { color: var(--income); }
.card.net.negative .card-value { color: var(--expense); }
.card.unpaid .card-value { color: var(--expense); }

.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.chart-box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.chart-box h2 { font-size: 1.1rem; margin-top: 0; }

table.txn-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
table.txn-table th, table.txn-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); }
table.txn-table th { background: #F5F3EC; font-weight: 600; font-size: 0.85rem; color: var(--muted); }
.badge { padding: 2px 8px; border-radius: 4px; font-size: 0.8rem; background: #1B4B5A1A; color: var(--accent); }
.badge.income { background: #2F6F621A; color: var(--income); }
.badge.expense { background: #B85C4A1A; color: var(--expense); }
.amount.income { color: var(--income); font-weight: 600; }
.amount.expense { color: var(--expense); font-weight: 600; }
.row-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-actions a { color: var(--accent); text-decoration: none; }
.row-actions form { display: inline; margin: 0; }
.row-actions button { background: none; border: none; color: var(--expense); cursor: pointer; padding: 0; font: inherit; }

.filters { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-family: inherit; }
.filters button { padding: 8px 14px; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px; cursor: pointer; }
.filters a { color: var(--muted); align-self: center; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.entry-form { display: grid; gap: 16px; max-width: 520px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 24px; }
.entry-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.entry-form input, .entry-form select { padding: 10px; border: 1px solid var(--line); border-radius: 6px; font-family: inherit; font-size: 1rem; color: var(--ink); }
.entry-form .checkbox-label { flex-direction: row; align-items: center; gap: 8px; }
.entry-form .checkbox-label input { width: auto; }
#recurring-fields { display: grid; gap: 16px; }
.form-actions { display: flex; gap: 16px; align-items: center; }
.form-actions a { color: var(--muted); text-decoration: none; }

.btn-primary { background: var(--accent); color: #fff; border: none; padding: 10px 18px; border-radius: 6px; text-decoration: none; cursor: pointer; font-weight: 500; display: inline-block; }
.btn-secondary { background: var(--surface); color: var(--accent); border: 1px solid var(--accent); padding: 8px 14px; border-radius: 6px; cursor: pointer; font-weight: 500; }

.income-row { display: grid; gap: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 12px; background: #FAF8F3; }
.income-row-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; color: var(--muted); }
.income-row-head button { background: none; border: none; color: var(--expense); cursor: pointer; font-size: 1rem; }

.cat-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.cat-column { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.cat-column-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.cat-column-head button { background: none; border: none; color: var(--expense); cursor: pointer; font-size: 1rem; }
.cat-list { list-style: none; padding: 0; margin: 0 0 14px; }
.cat-list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 0.92rem; gap: 8px; }
.cat-list li form { margin: 0; }
.cat-list button { background: none; border: none; color: var(--expense); cursor: pointer; font-size: 0.95rem; }
.rename-form { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.rename-form input { flex: 1; min-width: 0; padding: 4px 6px; border: 1px solid transparent; border-radius: 4px; background: transparent; font-family: inherit; font-size: 0.92rem; color: var(--ink); }
.rename-form input:hover, .rename-form input:focus { border-color: var(--line); background: var(--surface); }
.rename-form button { color: var(--income) !important; }
.move-form { display: flex; gap: 2px; }
.move-form button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.7rem; padding: 2px; }
.move-form button:hover { color: var(--accent); }
.cat-column-head { flex-wrap: wrap; row-gap: 4px; }
.add-cat { display: flex; gap: 8px; }
.add-cat input { flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 6px; font-family: inherit; }
.add-cat button { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 8px 14px; cursor: pointer; }

.range-picker { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.range-picker label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.range-picker input { padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.range-picker button { padding: 8px 14px; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px; cursor: pointer; }

.quick-ranges { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.quick-ranges a { font-size: 0.85rem; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--muted); background: var(--surface); }
.quick-ranges a:hover { border-color: var(--accent); color: var(--ink); }
.quick-ranges a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.date-hint { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

.id-col { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.date-invalid { border-color: var(--expense) !important; background: #B85C4A0D; }

.date-field { display: inline-flex; align-items: center; gap: 6px; position: relative; width: 100%; }
.date-field input[type="text"] { flex: 1; min-width: 0; }
.date-pick-btn {
  flex-shrink: 0; border: 1px solid var(--line); background: var(--surface);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 0.95rem; line-height: 1;
}
.date-pick-btn:hover { border-color: var(--accent); }
.date-native-overlay { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; right: 0; top: 0; }

.notice { background: #B85C4A1A; border: 1px solid var(--expense); color: var(--expense); padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

@media (max-width: 900px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .summary-cards, .charts-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .tabs a { margin-left: 0; margin-right: 16px; }
}
