/* =========================================================
   Family Balance — Editorial finance aesthetic
   Palette: deep ink, warm cream, sage accent, copper highlight
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,300;9..144,400;9..144,500;9..144,600;9..144,700&family=Inter+Tight:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --ink: #1a1f1c;
  --ink-soft: #2d3530;
  --cream: #f5f1e8;
  --cream-warm: #ebe4d2;
  --paper: #faf7f0;
  --sage: #6b8e6b;
  --sage-deep: #4a6b4a;
  --sage-soft: #d4dcc8;
  --copper: #b8654a;
  --copper-soft: #e8c5b3;
  --gold: #c9a961;
  --rust: #a04030;
  --muted: #8a857a;
  --line: #d8d0bc;
  --line-soft: #ece5d3;
  --shadow: 0 1px 2px rgba(26, 31, 28, 0.05), 0 8px 24px rgba(26, 31, 28, 0.06);
  --shadow-lg: 0 4px 12px rgba(26, 31, 28, 0.08), 0 24px 48px rgba(26, 31, 28, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter Tight', sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(circle at 0% 0%, rgba(107, 142, 107, 0.04), transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(184, 101, 74, 0.03), transparent 40%);
  background-attachment: fixed;
}

h1, h2, h3, h4 {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--ink);
}

.serif { font-family: 'Fraunces', serif; }
.mono { font-family: 'JetBrains Mono', monospace; }

a { color: var(--sage-deep); text-decoration: none; }
a:hover { color: var(--copper); }

/* =================== LAYOUT =================== */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--ink);
  color: var(--cream);
  padding: 28px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.brand {
  font-family: 'Fraunces', serif;
  font-weight: 400;
  font-size: 24px;
  letter-spacing: -0.02em;
  color: var(--cream);
  line-height: 1.1;
  margin-bottom: 4px;
}
.brand em {
  font-style: italic;
  color: var(--gold);
  font-weight: 300;
}
.brand-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  margin-bottom: 36px;
}

.nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin: 24px 0 8px 8px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--cream-warm);
  font-size: 14px;
  margin-bottom: 2px;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}
.nav-item:hover { background: rgba(245, 241, 232, 0.06); color: var(--cream); }
.nav-item.active {
  background: rgba(201, 169, 97, 0.1);
  color: var(--gold);
  border-color: rgba(201, 169, 97, 0.2);
}
.nav-item .ico { width: 18px; opacity: 0.7; }
.nav-item.active .ico { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid rgba(245, 241, 232, 0.1);
  font-size: 12px;
  color: var(--muted);
}
.sidebar-footer .who { color: var(--cream); font-weight: 500; }
.btn-logout {
  margin-top: 8px;
  background: transparent;
  border: 1px solid rgba(245, 241, 232, 0.15);
  color: var(--cream-warm);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.btn-logout:hover { background: rgba(184, 101, 74, 0.15); border-color: var(--copper); }

/* =================== MAIN =================== */
.main {
  padding: 36px 48px 60px;
  max-width: 1500px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 8px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line-soft);
}
.page-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.page-title {
  font-size: 38px;
  line-height: 1;
  font-weight: 400;
}
.page-title em { font-style: italic; color: var(--copper); font-weight: 300; }
.page-sub { color: var(--muted); margin-top: 8px; font-size: 14px; }

/* =================== BUTTONS / FORMS =================== */
.btn {
  background: var(--ink);
  color: var(--cream);
  border: none;
  padding: 9px 18px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--ink-soft); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-primary { background: var(--sage-deep); }
.btn-primary:hover { background: var(--sage); }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--cream); border-color: var(--ink); }
.btn-danger { background: var(--rust); }
.btn-danger:hover { background: var(--copper); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  transition: all 0.15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--sage-deep);
  background: white;
  box-shadow: 0 0 0 3px rgba(74, 107, 74, 0.1);
}
.textarea { min-height: 70px; resize: vertical; }

label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

/* =================== CARDS =================== */
.card {
  background: white;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.card-title {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.card-title em { font-style: italic; color: var(--copper); }

/* =================== KPI CARDS =================== */
.kpi-grid {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.kpi {
  background: white;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 22px 22px 20px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.kpi-hero {
  background: linear-gradient(135deg, var(--ink) 0%, var(--ink-soft) 100%);
  color: var(--cream);
  border-color: var(--ink);
}
.kpi-hero::after {
  content: '';
  position: absolute;
  right: -40px; bottom: -40px;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 169, 97, 0.15), transparent 70%);
  pointer-events: none;
}
.kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}
.kpi-hero .kpi-label { color: var(--gold); }
.kpi-value {
  font-family: 'Fraunces', serif;
  font-size: 32px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
}
.kpi-hero .kpi-value { font-size: 44px; color: var(--cream); }
.kpi-sub {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.kpi-hero .kpi-sub { color: var(--cream-warm); opacity: 0.7; }
.kpi.positive .kpi-value { color: var(--sage-deep); }
.kpi.negative .kpi-value { color: var(--rust); }

/* =================== TABLE =================== */
.table-wrap { overflow-x: auto; }
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.tbl thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 700;
  border-bottom: 1.5px solid var(--ink);
}
table.tbl tbody td {
  padding: 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
table.tbl tbody tr:hover { background: var(--cream); }
table.tbl tbody tr:last-child td { border-bottom: none; }
.amt { font-family: 'JetBrains Mono', monospace; font-weight: 500; text-align: right; white-space: nowrap; }
.amt-pos { color: var(--sage-deep); }
.amt-neg { color: var(--rust); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--muted);
  font-family: inherit;
  transition: all 0.15s ease;
}
.icon-btn:hover { color: var(--ink); background: var(--cream); border-color: var(--line); }
.icon-btn.del:hover { color: var(--rust); border-color: var(--copper-soft); }

/* =================== TOOLBAR =================== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.month-pill {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
.month-pill input {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  width: 110px;
}

/* =================== MODAL =================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 31, 28, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.18s ease;
}
.modal {
  background: var(--paper);
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.modal-head {
  padding: 22px 26px 16px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-family: 'Fraunces', serif;
  font-size: 24px;
  font-weight: 500;
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.modal-body { padding: 22px 26px; }
.modal-foot {
  padding: 16px 26px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* =================== LOGIN PAGE =================== */
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.login-left {
  background: var(--ink);
  color: var(--cream);
  padding: 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login-left::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(201, 169, 97, 0.08), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(107, 142, 107, 0.06), transparent 50%);
  pointer-events: none;
}
.login-brand {
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 300;
  letter-spacing: -0.02em;
  position: relative;
}
.login-brand em { font-style: italic; color: var(--gold); }
.login-tagline {
  font-family: 'Fraunces', serif;
  font-size: 64px;
  line-height: 1;
  font-weight: 300;
  letter-spacing: -0.03em;
  position: relative;
  z-index: 1;
}
.login-tagline em { font-style: italic; color: var(--gold); }
.login-foot {
  position: relative;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.login-right {
  background: var(--paper);
  padding: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card h2 {
  font-size: 32px;
  font-weight: 400;
  margin-bottom: 6px;
}
.login-card .sub { color: var(--muted); margin-bottom: 32px; }

/* =================== TOAST =================== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  color: var(--cream);
  padding: 14px 20px;
  border-radius: 6px;
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
.toast.error { background: var(--rust); }
.toast.success { background: var(--sage-deep); }

/* =================== CHARTS =================== */
.chart-row { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; margin-bottom: 24px; }
.chart-box { background: white; border: 1px solid var(--line-soft); border-radius: 6px; padding: 24px; box-shadow: var(--shadow); }
.chart-svg { width: 100%; height: 240px; }

.distribution { display: flex; flex-direction: column; gap: 12px; }
.dist-row { display: grid; grid-template-columns: 110px 1fr 110px; align-items: center; gap: 12px; font-size: 13px; }
.dist-label { color: var(--ink); font-weight: 500; }
.dist-bar { background: var(--line-soft); height: 8px; border-radius: 999px; overflow: hidden; }
.dist-bar-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
.dist-amt { font-family: 'JetBrains Mono', monospace; text-align: right; color: var(--ink); font-weight: 500; }

/* =================== EMPTY STATE =================== */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-title {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  color: var(--ink);
  margin-bottom: 8px;
  font-weight: 500;
}
.empty-text { margin-bottom: 20px; font-size: 14px; }

/* =================== TAGS =================== */
.tag {
  display: inline-block;
  background: var(--cream);
  color: var(--ink-soft);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  border: 1px solid var(--line);
}
.tag-sage { background: var(--sage-soft); border-color: var(--sage); color: var(--sage-deep); }
.tag-copper { background: var(--copper-soft); border-color: var(--copper); color: var(--rust); }

/* Responsive */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-hero { grid-column: 1 / -1; }
  .chart-row { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .main { padding: 24px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-left { padding: 32px; min-height: 200px; }
  .login-tagline { font-size: 36px; }
  .kpi-grid { grid-template-columns: 1fr; }
}
