* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #F6F1E9;
  --content-bg: #F6F1E9;
  --card: #FFFFFF;
  --card-b: 1px solid #EFE7DA;
  --card-sh: 0 1px 2px rgba(70,50,35,.05), 0 12px 30px rgba(70,50,35,.05);
  --text: #2B2320;
  --muted: #8C8074;
  --line: #EDE4D6;
  --accent: #C0603A;
  --accent-soft: #F4E4D8;
  --neg: #B4543A;
  --head-bg: #FBF7F1;
  --sb-bg: #FFFFFF;
  --sb-b: 1px solid #EFE7DA;
  --sb-text: #8C8074;
  --sb-title: #2B2320;
  --sb-card: #F6F1E9;
  --radius: 18px;
  --radius-sm: 12px;
  --pad: 24px;
  --gap: 18px;
  --kpi-num: 30px;
  --title: 27px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-feature-settings: 'tnum' 1;
}

input, select, button, textarea { font-family: inherit; font-size: inherit; color: inherit; }
::placeholder { color: var(--muted); }
a { color: inherit; }

.scr { overflow-y: auto; }
.scr::-webkit-scrollbar { width: 10px; }
.scr::-webkit-scrollbar-thumb { background: rgba(120,100,80,.22); border-radius: 8px; }

/* ---------- LOGIN ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: var(--bg);
}
.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 100%;
  max-width: 420px;
}
.login-brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 20px; letter-spacing: -.5px;
}
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: -.3px; color: var(--text); }
.brand-sub { font-size: 13px; color: var(--muted); }

.login-card {
  width: 100%;
  background: var(--card); border: var(--card-b); box-shadow: var(--card-sh);
  border-radius: var(--radius); padding: 36px 34px;
  display: flex; flex-direction: column; gap: 20px;
}
.login-card h1 { font-size: 22px; font-weight: 700; letter-spacing: -.4px; color: var(--text); }
.login-card p.sub { font-size: 14px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 7px; }
.field span { font-size: 13px; font-weight: 600; color: var(--text); }
.field input, .field select {
  height: 44px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-size: 14px; outline: none;
}
.btn-primary {
  height: 46px; border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; letter-spacing: .1px;
}
.login-note { display: flex; align-items: center; gap: 9px; padding-top: 2px; }
.login-note span { font-size: 12.5px; color: var(--muted); }

.qr-box { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.qr-box svg { width: 180px; height: 180px; }
.totp-secret {
  display: flex; flex-direction: column; gap: 5px; align-items: center;
  font-size: 12.5px; color: var(--muted); text-align: center;
}
.totp-secret code {
  font-size: 14px; letter-spacing: 1.5px; color: var(--text); background: var(--bg);
  padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
}
.link-btn {
  border: none; background: none; color: var(--muted); font-size: 13px;
  cursor: pointer; text-align: center; padding: 4px; text-decoration: underline;
}
.link-btn:hover { color: var(--text); }

/* ---------- APP LAYOUT ---------- */
.app { display: flex; height: 100vh; width: 100%; }

.sidebar {
  width: 238px; flex: 0 0 238px; background: var(--sb-bg); border-right: var(--sb-b);
  display: flex; flex-direction: column; padding: 22px 16px;
}
.sb-brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 22px; }
.sb-logo {
  width: 36px; height: 36px; border-radius: 10px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; color: #fff;
  font-weight: 700; font-size: 17px;
}
.sb-title { font-size: 15px; font-weight: 700; color: var(--sb-title); }
.sb-sub { font-size: 11.5px; color: var(--sb-text); }
.sb-section-label {
  font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase;
  color: var(--sb-text); opacity: .7; padding: 4px 10px 8px;
}
.sb-nav { display: flex; flex-direction: column; gap: 4px; }
.sb-nav-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border: none;
  border-radius: 11px; font-size: 14px; font-weight: 600; cursor: pointer;
  text-align: left; width: 100%; background: transparent; color: var(--sb-text);
  text-decoration: none;
}
.sb-nav-item.active { background: var(--accent-soft); color: #B25537; }
.sb-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.sb-total-card {
  background: var(--sb-card); border-radius: 12px; padding: 14px 15px;
  display: flex; flex-direction: column; gap: 4px;
}
.sb-total-card span:first-child { font-size: 11.5px; color: var(--sb-text); }
.sb-total-card span:last-child { font-size: 19px; font-weight: 700; color: var(--sb-title); letter-spacing: -.4px; }
.sb-user { font-size: 12px; color: var(--sb-text); padding: 0 4px; }
.sb-user strong { color: var(--sb-title); font-weight: 600; }
.sb-logout {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: none;
  background: transparent; color: var(--sb-text); font-size: 13.5px; font-weight: 500;
  cursor: pointer; border-radius: 10px; text-decoration: none; width: 100%; text-align: left;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--content-bg); }
.page { flex: 1; overflow-y: auto; padding: 26px 30px 40px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { font-size: var(--title); font-weight: 700; letter-spacing: -.6px; color: var(--text); }
.page-head p { font-size: 14px; color: var(--muted); margin-top: 5px; }
.page-head-actions { display: flex; gap: 10px; align-items: center; }

.month-select {
  height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 15px;
  background: var(--card); border: var(--card-b); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; color: var(--text); border: 1px solid var(--line);
  cursor: pointer; outline: none; appearance: none;
}
.btn-add {
  height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 17px; border: none;
  border-radius: var(--radius-sm); background: var(--accent); color: #fff; font-size: 14px;
  font-weight: 600; cursor: pointer; text-decoration: none;
}

.card { background: var(--card); border: var(--card-b); box-shadow: var(--card-sh); border-radius: var(--radius); padding: var(--pad); }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 320px)); gap: var(--gap); margin-bottom: var(--gap); }
.kpi-card { display: flex; flex-direction: column; gap: 10px; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi-num { font-size: var(--kpi-num); font-weight: 700; letter-spacing: -.8px; color: var(--text); }
.kpi-sub { font-size: 12.5px; color: var(--muted); }

/* Charts row */
.charts-row { display: grid; grid-template-columns: 1.5fr 1fr; gap: var(--gap); margin-bottom: var(--gap); }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 20px; }
.chart-title { font-size: 15px; font-weight: 700; color: var(--text); }
.chart-caption { font-size: 12.5px; color: var(--muted); }
.chart-head > div > .chart-caption { margin-left: 8px; }

.bar-track { height: 10px; border-radius: 6px; background: var(--accent-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; }

.pie-wrap { display: flex; align-items: center; gap: 22px; margin-top: 18px; }
.pie-outer { position: relative; flex: 0 0 132px; width: 132px; height: 132px; border-radius: 50%; }
.pie-outer.lg { flex: 0 0 180px; width: 180px; height: 180px; }
.pie-outer.lg .pie-center { inset: 40px; }
.pie-outer canvas { position: relative; z-index: 2; display: block; width: 100% !important; height: 100% !important; }
.pie-legend.scr { max-height: 220px; overflow-y: auto; padding-right: 6px; }
.chart-box { position: relative; width: 100%; margin-top: 12px; }
.chart-box canvas { width: 100% !important; height: 100% !important; }
.pie-center {
  position: absolute; inset: 28px; z-index: 1; background: var(--card); border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  pointer-events: none;
}
.pie-center span:first-child { font-size: 11px; color: var(--muted); }
.pie-center span:last-child { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.pie-legend { flex: 1; display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.pie-legend-row { display: flex; align-items: center; gap: 9px; }
.pie-legend-dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.pie-legend-name { font-size: 12.5px; color: var(--text); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pie-legend-pct { font-size: 12.5px; font-weight: 600; color: var(--muted); }

/* Line chart */
.line-card { margin-bottom: var(--gap); }

/* Recent list */
.recent-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.recent-link { border: none; background: transparent; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; }
.recent-row { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.recent-row:last-child { border-bottom: none; }
.recent-avatar {
  width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; color: var(--accent);
  font-weight: 700; font-size: 14px; flex: 0 0 auto;
}
.recent-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.recent-cat { font-size: 14px; font-weight: 600; color: var(--text); }
.recent-info { font-size: 12.5px; color: var(--muted); }
.recent-amounts { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 100px; }
.recent-amount { font-size: 14.5px; font-weight: 700; color: var(--text); }
.recent-date { font-size: 12px; color: var(--muted); }

.payer { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.payer-ben { color: #B25537; }
.payer-juju { color: #5E8471; }
.payer-commun { color: var(--muted); }

/* Filters bar */
.filters-bar {
  background: var(--card); border: var(--card-b); box-shadow: var(--card-sh); border-radius: var(--radius);
  padding: 16px; margin-bottom: var(--gap); display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
}
.search-field {
  flex: 1; min-width: 180px; display: flex; align-items: center; gap: 9px; height: 40px;
  padding: 0 13px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.search-field input { border: none; background: transparent; outline: none; flex: 1; font-size: 13.5px; }
.filters-bar select {
  height: 40px; padding: 0 12px; border: 1px solid var(--line); background: var(--bg);
  border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500; cursor: pointer; outline: none;
}

/* Form */
.form-card {
  background: var(--card); border: 2px solid var(--accent); box-shadow: var(--card-sh);
  border-radius: var(--radius); padding: var(--pad); margin-bottom: var(--gap);
}
.form-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.form-head span { font-size: 16px; font-weight: 700; color: var(--text); }
.form-close { border: none; background: transparent; cursor: pointer; color: var(--muted); text-decoration: none; display: flex; }
.form-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; margin-bottom: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; }
.form-grid label span { font-size: 12.5px; font-weight: 600; color: var(--text); }
.form-grid input, .form-grid select {
  height: 42px; padding: 0 13px; border: 1px solid var(--line); background: var(--bg);
  border-radius: var(--radius-sm); font-size: 14px; outline: none; cursor: pointer;
}
.combo { position: relative; }
.combo-input {
  width: 100%; height: 42px; padding: 0 13px; border: 1px solid var(--line); background: var(--bg);
  border-radius: var(--radius-sm); font-size: 14px; outline: none; cursor: text;
}
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  max-height: 220px; overflow-y: auto; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: 0 12px 28px rgba(0,0,0,.12); padding: 6px;
}
.combo-option { padding: 9px 11px; border-radius: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.combo-option:hover, .combo-option.active { background: var(--accent-soft); color: var(--accent); }

.monthpicker { position: relative; }
.monthpicker-trigger {
  width: 100%; height: 42px; padding: 0 13px; border: 1px solid var(--line); background: var(--bg);
  border-radius: var(--radius-sm); font-size: 14px; text-align: left; cursor: pointer; color: var(--text);
}
.monthpicker-trigger:hover { border-color: var(--accent); }
.monthpicker-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; width: 250px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 14px 32px rgba(60,40,25,.16); padding: 14px;
}
.monthpicker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.monthpicker-year { font-size: 14.5px; font-weight: 700; color: var(--text); letter-spacing: -.2px; }
.monthpicker-nav {
  width: 28px; height: 28px; border: none; background: var(--bg); border-radius: 8px; cursor: pointer;
  color: var(--muted); font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.monthpicker-nav:hover { background: var(--accent-soft); color: var(--accent); }
.monthpicker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.monthpicker-cell {
  padding: 10px 0; border: none; background: var(--bg); border-radius: 9px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text); transition: background .12s ease, color .12s ease;
}
.monthpicker-cell:hover { background: var(--accent-soft); color: var(--accent); }
.monthpicker-cell.selected { background: var(--accent); color: #fff; }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn-cancel {
  height: 42px; padding: 0 18px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
}
.btn-save {
  height: 42px; padding: 0 22px; border: none; background: var(--accent); color: #fff;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; cursor: pointer;
}

/* Table */
.table-card { background: var(--card); border: var(--card-b); box-shadow: var(--card-sh); border-radius: var(--radius); overflow: hidden; }
.dep-row {
  display: grid; grid-template-columns: 96px 1.1fr 1.3fr 1.1fr 110px 130px 74px; gap: 14px;
  padding: 14px 20px; align-items: center; font-size: 13.5px; border-bottom: 1px solid var(--line);
}
.dep-row:last-child { border-bottom: none; }
.table-head {
  background: var(--head-bg); font-size: 11.5px; font-weight: 600; letter-spacing: .4px;
  text-transform: uppercase; color: var(--muted);
}
.dep-row .muted { color: var(--muted); }
.dep-row .bold { font-weight: 600; color: var(--text); }
.dep-row .amount { text-align: right; font-weight: 700; color: var(--text); }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  width: 30px; height: 30px; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none;
}
.icon-btn.danger { color: var(--neg); }
.icon-btn:hover { background: var(--bg); }

/* Categories table */
.cat-row {
  display: grid; grid-template-columns: 22px 1.6fr 130px 70px 110px 1.5fr 70px; gap: 14px;
  padding: 14px 20px; align-items: center; font-size: 13.5px; border-bottom: 1px solid var(--line);
}
.cat-row:last-child { border-bottom: none; }
.cat-dot { width: 12px; height: 12px; border-radius: 4px; flex: 0 0 auto; }
.cat-row .amount { text-align: right; font-weight: 700; color: var(--text); }
.cat-row .center { text-align: center; }
.cat-row .muted { color: var(--muted); }
.cat-row .bold { font-weight: 600; color: var(--text); }
.cat-name-link { text-decoration: none; }
.cat-name-link:hover { text-decoration: underline; color: var(--accent); }
.cat-row .bar-track { height: 8px; }
.cat-link {
  font-size: 12.5px; font-weight: 600; color: var(--accent); text-decoration: none; text-align: right;
}

.empty-state { padding: 44px; text-align: center; color: var(--muted); font-size: 14px; }

/* Simple management list (categories) */
.simple-row {
  display: grid; grid-template-columns: 1fr 160px 90px; gap: 14px;
  padding: 14px 20px; align-items: center; font-size: 13.5px; border-bottom: 1px solid var(--line);
}
.simple-row:last-child { border-bottom: none; }
.simple-row .muted { color: var(--muted); }
.simple-row .bold { font-weight: 600; color: var(--text); }
.simple-row .center { text-align: center; }
.page-back {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600;
  color: var(--muted); text-decoration: none; margin-bottom: 4px;
}
.manage-link {
  display: inline-flex; align-items: center; gap: 7px; height: 42px; padding: 0 15px;
  border: 1px solid var(--line); background: var(--card); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; color: var(--text); text-decoration: none;
}

.payer-hint {
  height: 42px; display: flex; align-items: center; padding: 0 13px;
  border: 1px solid var(--line); background: var(--bg); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; color: var(--text);
}

/* Recurring expenses */
.months-field, .active-field { grid-column: 1 / -1; }
.months-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 8px; }
.month-chip {
  display: flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px;
  border: 1px solid var(--line); background: var(--bg); border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer;
}
.month-chip input { accent-color: var(--accent); cursor: pointer; }
.rec-row {
  display: grid; grid-template-columns: 1.1fr 1.3fr 1fr 100px 1.3fr 120px 100px; gap: 14px;
  padding: 14px 20px; align-items: center; font-size: 13.5px; border-bottom: 1px solid var(--line);
}
.rec-row:last-child { border-bottom: none; }
.rec-row .muted { color: var(--muted); }
.rec-row .bold { font-weight: 600; color: var(--text); }
.rec-row .amount { text-align: right; font-weight: 700; color: var(--text); }
.rec-row.is-inactive { opacity: .5; }

.info-banner {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--accent-soft); border-radius: var(--radius); padding: 18px 20px;
  margin-bottom: var(--gap); color: var(--text);
}
.info-banner svg { flex: 0 0 auto; color: var(--accent); margin-top: 1px; }
.info-banner strong { display: block; font-size: 14px; margin-bottom: 6px; }
.info-banner p { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 6px; }
.info-banner p:last-child { margin-bottom: 0; }

@media (max-width: 720px) {
  .months-grid { grid-template-columns: repeat(3, 1fr); }
}


@media (max-width: 1100px) {
  .charts-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2,1fr); }
}
