:root {
  --pine: #123b36;
  --pine-2: #0c2a26;
  --pine-soft: #dcebe4;
  --paper: #f7f2e9;
  --paper-2: #fffaf1;
  --ink: #1d2422;
  --muted: #68736e;
  --line: #ddd3c2;
  --coral: #e76f51;
  --coral-dark: #c84f35;
  --amber: #e9c46a;
  --green: #2a7f62;
  --red: #b3261e;
  --shadow: 0 18px 50px rgba(18, 59, 54, 0.14);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(233, 196, 106, 0.28), transparent 32rem),
    linear-gradient(180deg, #fbf7ee 0%, var(--paper) 46%, #efe7d7 100%);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 20px);
  background: var(--pine-2);
  color: #fff;
  padding: 12px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 60;
  max-width: min(92vw, 560px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
}
.auth-card {
  width: min(100%, 460px);
  background: rgba(255, 250, 241, 0.92);
  border: 1px solid rgba(18, 59, 54, 0.12);
  border-radius: 30px;
  padding: 34px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: var(--paper-2);
  background: var(--pine);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
}
.brand-mark svg { width: 36px; height: 36px; }
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; }
.brand-mark.small svg { width: 27px; height: 27px; }
.eyebrow {
  margin: 20px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--coral-dark);
}
.eyebrow.light { color: var(--amber); margin-top: 0; }
.auth-card h1, .section-head h2, .panel h2, .panel h3 {
  font-family: Fraunces, Georgia, serif;
  letter-spacing: 0;
}
.auth-card h1 { font-size: 2.35rem; line-height: 1; margin: 0 0 12px; color: var(--pine-2); }
.auth-lead { color: var(--muted); line-height: 1.55; margin: 0 0 24px; }
.auth-form { display: grid; gap: 14px; }
.auth-form h2 { font-size: 1.25rem; margin: 4px 0 2px; }
label { display: grid; gap: 7px; font-weight: 650; color: #31413c; font-size: 0.92rem; }
label small { color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cfc4ae;
  background: #fffdf8;
  color: var(--ink);
  border-radius: 13px;
  padding: 12px 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--pine);
  box-shadow: 0 0 0 3px rgba(18, 59, 54, 0.13);
}
textarea { resize: vertical; }

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 17px;
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: 0.18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--pine); color: #fff; }
.btn.primary:hover { background: var(--pine-2); }
.btn.secondary { background: #fffaf1; color: var(--pine); border-color: rgba(18,59,54,0.25); }
.btn.ghost { background: transparent; color: var(--pine); border-color: transparent; }
.btn.danger { background: var(--coral); color: #fff; }
.btn.small { padding: 8px 12px; font-size: 0.88rem; }
.btn.wide { width: 100%; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--coral-dark);
  font-weight: 750;
  padding: 4px;
}
.form-note { color: var(--muted); font-size: 0.88rem; line-height: 1.45; margin: 0; }
.error-text {
  margin-top: 16px;
  background: #fdecea;
  color: var(--red);
  border: 1px solid #f3c1bc;
  border-radius: 13px;
  padding: 11px 13px;
  font-weight: 650;
}

.app-shell { width: min(1180px, 100%); margin: 0 auto; padding: 18px clamp(14px, 3vw, 30px) 52px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.topbar-brand strong { display: block; font-family: Fraunces, Georgia, serif; font-size: 1.28rem; color: var(--pine-2); }
.topbar-brand span { color: var(--muted); font-size: 0.9rem; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }

.monthbar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--pine);
  color: #fff;
  border-radius: 24px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.monthbar span { display: block; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.12em; color: #cfe2d8; font-weight: 800; }
.monthbar strong { font-family: Fraunces, Georgia, serif; font-size: 1.55rem; text-transform: capitalize; }
.monthbar .btn { margin-left: auto; }
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.1);
  color: inherit;
  font-size: 1.55rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 18px 2px 8px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1px solid rgba(18,59,54,0.14);
  background: rgba(255,250,241,0.78);
  color: var(--pine);
  border-radius: 999px;
  padding: 10px 15px;
  font-weight: 750;
  white-space: nowrap;
}
.tab.active { background: var(--coral); border-color: var(--coral); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.content { padding-top: 12px; }

.hero-card {
  display: grid;
  grid-template-columns: 1.45fr 0.75fr;
  gap: 24px;
  background: linear-gradient(135deg, var(--pine-2), var(--pine) 58%, #1d5c50);
  color: #fff;
  border-radius: 30px;
  padding: clamp(24px, 4vw, 40px);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}
.hero-card::after {
  content: "";
  position: absolute;
  width: 290px;
  height: 290px;
  border-radius: 50%;
  border: 52px solid rgba(233,196,106,0.13);
  right: -110px;
  top: -130px;
}
.hero-value { font-family: Fraunces, Georgia, serif; font-size: clamp(2.6rem, 7vw, 5rem); line-height: 0.95; margin: 4px 0 12px; }
.hero-value.negative, .negative { color: #ff9d88 !important; }
.metric strong.negative, .item-value.negative { color: var(--red) !important; }
.hero-formula { color: #dcebe4; line-height: 1.5; margin: 0; max-width: 560px; }
.hero-side {
  align-self: center;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 20px;
  padding: 20px;
  position: relative;
  z-index: 1;
}
.hero-side span { display: block; color: #cfe2d8; font-weight: 750; margin-bottom: 8px; }
.hero-side strong { display: block; font-size: 1.65rem; margin-bottom: 8px; }
.hero-side small { color: #dcebe4; line-height: 1.45; display: block; }

.alert-card {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: #fff0eb;
  border: 1px solid #f2b8a6;
  color: #742d20;
  padding: 16px 18px;
  border-radius: 20px;
}
.alert-card strong { display: block; margin-bottom: 3px; }
.alert-card span { color: #97503d; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 16px;
}
.metric, .panel {
  background: rgba(255,250,241,0.94);
  border: 1px solid rgba(18,59,54,0.11);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 10px 30px rgba(18,59,54,0.06);
}
.metric span { display: block; color: var(--muted); font-weight: 750; font-size: 0.86rem; margin-bottom: 8px; }
.metric strong { display: block; color: var(--pine-2); font-size: 1.45rem; margin-bottom: 6px; }
.metric small { color: var(--muted); line-height: 1.4; display: block; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.panel-head h2, .panel-head h3 { margin: 0; color: var(--pine-2); }
.panel-head span { color: var(--muted); font-size: 0.9rem; text-align: right; }
.panel.subtle { margin-top: 18px; background: rgba(255,250,241,0.72); }

.mini-list, .item-list, .template-list { display: grid; gap: 10px; }
.mini-row, .item-row, .template-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid rgba(18,59,54,0.09);
}
.mini-row:last-child, .item-row:last-child, .template-row:last-child { border-bottom: 0; }
.mini-row strong, .item-main strong, .template-row strong { display: block; color: var(--pine-2); }
.mini-row span, .item-main span, .template-row span { display: block; color: var(--muted); font-size: 0.9rem; margin-top: 3px; line-height: 1.4; }
.empty { color: var(--muted); background: rgba(18,59,54,0.05); border-radius: 15px; padding: 16px; line-height: 1.5; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin: 10px 0 18px;
}
.section-head h2 { font-size: 2rem; margin: 0 0 6px; color: var(--pine-2); }
.section-head p { margin: 0; color: var(--muted); line-height: 1.5; max-width: 650px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; }
.chip {
  border: 1px solid rgba(18,59,54,0.16);
  background: #fffaf1;
  color: var(--pine);
  padding: 9px 13px;
  border-radius: 999px;
  font-weight: 750;
  white-space: nowrap;
}
.chip.active { background: var(--pine); color: #fff; }
.item-list { gap: 12px; }
.item-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  background: rgba(255,250,241,0.95);
  border: 1px solid rgba(18,59,54,0.11);
  border-radius: 20px;
  padding: 17px;
}
.item-card.overdue { border-color: #ef9d88; background: #fff6f1; }
.item-card.paid { opacity: 0.78; }
.item-main h3 { margin: 0 0 5px; color: var(--pine-2); font-size: 1.05rem; }
.item-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 800;
  background: var(--pine-soft);
  color: var(--pine);
}
.pill.red { background: #fdecea; color: var(--red); }
.pill.green { background: #e0f2e7; color: #176344; }
.pill.amber { background: #fff1cf; color: #7a5410; }
.item-side { text-align: right; display: grid; align-content: start; gap: 10px; }
.item-value { font-size: 1.22rem; font-weight: 850; color: var(--pine-2); white-space: nowrap; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.mini-btn {
  border: 1px solid rgba(18,59,54,0.16);
  background: #fff;
  color: var(--pine);
  border-radius: 999px;
  padding: 7px 10px;
  font-weight: 750;
  font-size: 0.86rem;
}
.mini-btn.primary { background: var(--pine); color: #fff; border-color: var(--pine); }
.mini-btn.warn { color: var(--coral-dark); border-color: #efb3a2; }
.status-buttons { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.status-buttons .mini-btn.active { background: var(--pine); color: #fff; border-color: var(--pine); }

.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.credit-card {
  min-height: 178px;
  border-radius: 24px;
  padding: 20px;
  color: #fff;
  background: linear-gradient(135deg, #173f39, #1d5c50 60%, #d0684e 140%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.credit-card span { color: #cfe2d8; font-size: 0.86rem; }
.credit-card strong { display: block; font-size: 1.35rem; margin-top: 5px; }
.credit-card .card-bottom { display: flex; justify-content: space-between; gap: 12px; align-items: end; }
.credit-card .card-actions { display: flex; gap: 6px; }
.credit-card .mini-btn { background: rgba(255,255,255,0.14); color: #fff; border-color: rgba(255,255,255,0.2); }

.category-list { display: grid; gap: 13px; }
.category-row { display: grid; gap: 7px; }
.category-row-head { display: flex; justify-content: space-between; gap: 12px; }
.category-row-head span { color: var(--muted); font-weight: 650; }
.category-row-head strong { color: var(--pine-2); }
.bar { height: 9px; background: rgba(18,59,54,0.1); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--pine), var(--coral)); border-radius: inherit; }
.category-list.large .category-row { padding: 10px 0; border-bottom: 1px solid rgba(18,59,54,0.08); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 10px; border-bottom: 1px solid rgba(18,59,54,0.09); text-align: right; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: 0.83rem; text-transform: uppercase; letter-spacing: 0.06em; }
td { font-weight: 650; }
tr.current td { background: rgba(233,196,106,0.16); }
.two-forms { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.mini-form { display: grid; gap: 12px; align-content: start; }
.mini-form h4 { margin: 0; color: var(--pine-2); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 42, 38, 0.54);
  display: grid;
  place-items: end center;
  padding: 18px;
  z-index: 50;
}
.modal {
  width: min(100%, 620px);
  max-height: min(92vh, 860px);
  overflow: auto;
  background: var(--paper-2);
  border-radius: 26px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-family: Fraunces, Georgia, serif; color: var(--pine-2); }
.modal-head .icon-btn { background: rgba(18,59,54,0.07); border-color: rgba(18,59,54,0.1); color: var(--pine); }
.modal-form { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-row { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 10px; background: rgba(18,59,54,0.05); padding: 11px 12px; border-radius: 13px; }
.check-row input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (max-width: 860px) {
  .hero-card, .two-col, .two-forms { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: 1fr; }
  .section-head { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 560px) {
  .auth-card { padding: 26px 20px; }
  .app-shell { padding-inline: 10px; }
  .topbar { align-items: flex-start; }
  .topbar-actions .btn { padding: 9px 11px; }
  .monthbar { flex-wrap: wrap; }
  .monthbar .btn { margin-left: 0; width: 100%; }
  .metric-grid { grid-template-columns: 1fr; }
  .item-card { grid-template-columns: 1fr; }
  .item-side { text-align: left; }
  .item-actions, .status-buttons { justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 8px; }
  .modal { padding: 20px 16px; border-radius: 22px; }
  .alert-card { align-items: flex-start; flex-direction: column; }
}
