:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2733;
  --muted: #6b7688;
  --border: #e3e8f0;
  --primary: #2f6bff;
  --primary-dark: #1f4fd1;
  --income: #17a673;
  --expense: #e0475b;
  --th-bg: #fafbfe;
  --row-hover: #f8faff;
  --input-bg: #ffffff;
  --btn-bg: #eef1f6;
  --danger-bg: #fce6ea;
  --filter-bg: #fbfcfe;
  --shadow: 0 1px 3px rgba(20,30,60,.08), 0 6px 20px rgba(20,30,60,.06);
  --radius: 12px;
}
:root[data-theme="dark"] {
  --bg: #0e1523;
  --card: #182133;
  --text: #e7ecf6;
  --muted: #97a3ba;
  --border: #283246;
  --primary: #4d84ff;
  --primary-dark: #3a6be0;
  --income: #2bbd85;
  --expense: #f2637a;
  --th-bg: #141c2c;
  --row-hover: #1e2740;
  --input-bg: #0f1a2b;
  --btn-bg: #273249;
  --danger-bg: #3a1f28;
  --filter-bg: #131b2a;
  --shadow: 0 1px 3px rgba(0,0,0,.45), 0 8px 24px rgba(0,0,0,.35);
}
:root[data-theme="dark"] .badge.income { background: rgba(43,189,133,.20); }
:root[data-theme="dark"] .badge.expense { background: rgba(242,99,122,.20); }
:root[data-theme="dark"] .badge.role { background: rgba(77,132,255,.22); color: #a9c2ff; }
:root[data-theme="dark"] .badge.muted { background: rgba(151,163,186,.20); color: #b6c1d6; }
:root[data-theme="dark"] .btn:hover { filter: brightness(1.12); }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
.hidden { display: none !important; }
a { color: var(--primary); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.login-card {
  background: var(--card); width: 100%; max-width: 380px; padding: 32px;
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-logo { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 11px 12px; }

/* ---------- App layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; background: #101828; color: #cfd6e4; display: flex; flex-direction: column;
  padding: 18px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 18px; font-weight: 700; color: #fff; padding: 8px 10px; margin-bottom: 12px; cursor: pointer; border-radius: 9px; user-select: none; display: inline-flex; align-items: center; gap: 6px; }
.brand:hover { background: rgba(255,255,255,.08); }
.brand:active { transform: scale(.97); }
.brand span { margin-left: 4px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
  color: #cfd6e4; text-decoration: none; font-weight: 500; cursor: pointer;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav .ic { width: 18px; text-align: center; }
.nav-sep { margin-top: auto; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 8px; padding-top: 10px; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 9px 10px; background: rgba(255,255,255,.05); border-radius: 11px; cursor: pointer; transition: background .12s; user-select: none; }
.user-card:hover { background: rgba(255,255,255,.11); }
.user-card:active { transform: scale(.98); }
.u-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--primary) 0%, #6a4bff 100%); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; letter-spacing: .02em; }
.u-meta { min-width: 0; }
.user-card .u-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card .u-role { color: #8b96ab; font-size: 11px; margin-top: 1px; }
.foot-actions { display: flex; gap: 8px; }
.fbtn { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 36px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.10); color: #cfd6e4; border-radius: 10px; padding: 8px 0; font-size: 16px; line-height: 1; cursor: pointer; transition: background .12s, border-color .12s; }
.fbtn:hover { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.22); }
.fbtn:active { transform: scale(.96); }
.fbtn-danger:hover { background: rgba(224,71,91,.22); border-color: rgba(224,71,91,.45); }

.main { flex: 1; min-width: 0; }
.content { padding: 26px 30px; max-width: 1200px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }

/* ---------- Cards / grid ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat .value { font-size: 24px; font-weight: 700; }
.value.income { color: var(--income); }
.value.expense { color: var(--expense); }
.value.net-pos { color: var(--income); }
.value.net-neg { color: var(--expense); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px){ .grid-2 { grid-template-columns: 1fr; } }
.card h3 { margin: 0 0 14px; font-size: 15px; }
.chart-box { position: relative; height: 280px; }

/* ---------- Tables ---------- */
.table-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--th-bg); }
tbody tr:hover { background: var(--row-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Data table (sortable + filterable) ---------- */
table.dt th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.dt th.sortable:hover { color: var(--primary); }
table.dt th .arr { color: var(--primary); font-size: 11px; }
tr.filter-row td { padding: 6px 8px; background: var(--filter-bg); border-bottom: 2px solid var(--border); }
tr.filter-row input, tr.filter-row select { padding: 6px 8px; font-size: 13px; border-radius: 7px; }
tr.filter-row input::placeholder { color: #b7c0d0; }

/* ---------- Column toggle menu ---------- */
.col-menu-wrap { position: relative; display: inline-block; }
.col-menu { position: absolute; right: 0; top: 110%; background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px; z-index: 70; min-width: 190px; }
.col-menu label { display: flex; align-items: center; gap: 8px; padding: 5px 2px; font-size: 13px; cursor: pointer; }
.col-menu input { width: auto; }
.head-tools { display: flex; gap: 8px; align-items: center; }

/* ---------- Bulk-action bar ---------- */
.bulkbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--primary); border-radius: var(--radius); padding: 10px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
table.dt td input[type="checkbox"], table.dt th input[type="checkbox"] { cursor: pointer; }
table.dt th.nosort { cursor: default; }
table.dt th.th-tools { text-align: right; width: 64px; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 14px; line-height: 1; color: var(--muted); padding: 3px 7px; border-radius: 7px; }
.icon-btn:hover { color: var(--primary); background: var(--btn-bg); }

/* ---------- Profile page ---------- */
.profile-head { display: flex; align-items: center; gap: 16px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 16px; max-width: 520px; }
.u-avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.p-name { font-weight: 700; font-size: 18px; }
.profile-actions { display: flex; flex-direction: column; gap: 10px; max-width: 520px; }
.pa-btn { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; font: inherit; font-weight: 600; color: var(--text); cursor: pointer; text-align: left; box-shadow: var(--shadow); transition: border-color .12s; }
.pa-btn:hover { border-color: var(--primary); }
.pa-btn.danger { color: var(--expense); }
.pa-btn.danger:hover { border-color: var(--expense); background: var(--danger-bg); }

/* ---------- Settings hub ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.settings-tile { display: flex; gap: 14px; align-items: center; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; text-decoration: none; color: var(--text); border: 1px solid transparent; transition: border-color .12s, transform .12s; cursor: pointer; font: inherit; text-align: left; }
.settings-tile:hover { border-color: var(--primary); transform: translateY(-1px); }
.stile-ic { font-size: 28px; line-height: 1; }
.stile-title { font-weight: 600; font-size: 15px; margin-bottom: 3px; }
.stile-desc { font-size: 13px; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 4px 2px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- Transfer type ---------- */
.badge.transfer { background: #eef2fb; color: #4a5b7d; }
.amt.transfer { color: #4a5b7d; font-weight: 600; }
:root[data-theme="dark"] .badge.transfer { background: rgba(120,140,180,.22); color: #aab7d0; }
:root[data-theme="dark"] .amt.transfer { color: #aab7d0; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.income { background: #e3f6ee; color: var(--income); }
.badge.expense { background: #fce6ea; color: var(--expense); }
.badge.role { background: #eef2fb; color: #4a5b7d; }
.badge.muted { background: #eef1f6; color: var(--muted); }
.amt.income { color: var(--income); font-weight: 600; }
.amt.expense { color: var(--expense); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; padding: 9px 15px; border-radius: 9px; border: 1px solid transparent;
  cursor: pointer; font-weight: 600; background: var(--btn-bg); color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); filter: none; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.16); color: #cfd6e4; }
.btn-ghost:hover { background: rgba(255,255,255,.08); }
.btn-danger { background: var(--danger-bg); color: var(--expense); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 4px 6px; font-weight: 600; }
.btn-link.danger { color: var(--expense); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ---------- Forms ---------- */
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--input-bg); color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,107,255,.14); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--expense); font-size: 13px; min-height: 18px; }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin-bottom: 0; min-width: 140px; }
.filters .field.small { min-width: 120px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { position: relative; background: var(--card); border-radius: 14px; width: 100%; max-width: 520px; padding: 24px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 18px; font-size: 18px; padding-right: 30px; }
.modal.modal-wide { max-width: min(1100px, 96vw); }
.form-line { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.form-line .field { margin-bottom: 10px; min-width: 0; }
@media (max-width: 720px){ .form-line .field { flex: 1 1 100% !important; } }
.modal-close { position: absolute; top: 12px; right: 14px; background: transparent; border: none; color: var(--muted); font-size: 16px; line-height: 1; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.modal-close:hover { background: var(--btn-bg); color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #101828; color: #fff; padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow); z-index: 80; }
.toast.err { background: var(--expense); }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.mt { margin-top: 18px; }
/* mobile top bar + off-canvas sidebar (hidden on desktop) */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 720px){
  .app { display: block; }
  .mobile-topbar { display: flex; align-items: center; gap: 12px; background: #101828; color: #fff; padding: 12px 14px; position: sticky; top: 0; z-index: 45; }
  .mtb-btn { background: transparent; border: 1px solid rgba(255,255,255,.22); color: #fff; font-size: 18px; line-height: 1; border-radius: 8px; padding: 6px 11px; cursor: pointer; }
  .mtb-title { font-weight: 600; font-size: 16px; }
  .sidebar { position: fixed; top: 0; left: 0; height: 100vh; width: 240px; z-index: 60; transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; }
  .sidebar-backdrop.show { display: block; }
  .main { width: 100%; }
  .content { padding: 16px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .head-tools { flex-wrap: wrap; }
  .form-row { grid-template-columns: 1fr; }
  .modal { max-width: 100%; }
  .filters { gap: 8px; }
}
