/* ============ Tokens ============ */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #f0f2f6;
  --border: #e6e8ee;
  --border-strong: #d6dae2;
  --text: #151a23;
  --muted: #667085;
  --faint: #98a2b3;
  --brand: #3d5afe;
  --brand-hover: #2f4ae0;
  --brand-soft: #eef1ff;
  --brand-contrast: #ffffff;
  --sidebar: #ffffff;
  --sidebar-2: #f3f5f9;
  --sidebar-text: #5b6474;
  --sidebar-strong: #151a23;
  --sidebar-border: #eceef3;
  --pos: #12976b;
  --pos-soft: #e7f7f0;
  --neg: #e0474c;
  --neg-soft: #fdeced;
  --warn: #c7820f;
  --warn-soft: #fdf4e2;
  --info: #2f80ed;
  --info-soft: #e8f1fd;
  --violet: #7a5af8;
  --violet-soft: #f1edfe;
  --focus: 0 0 0 3px rgba(61, 90, 254, .2);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .03);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .16);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-display: "Segoe UI Variable Display", "Inter", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #151a21; --surface-2: #1a2029; --surface-3: #202733; --border: #262e3a; --border-strong: #323c4b;
    --text: #e8ebf0; --muted: #9aa3b2; --faint: #6b7483; --brand: #7c97ff; --brand-hover: #95abff; --brand-soft: #1e2748; --brand-contrast: #0b1020;
    --sidebar: #12161c; --sidebar-2: #1b212a; --sidebar-text: #aab3c0; --sidebar-strong: #eef1f5; --sidebar-border: #232a34;
    --pos: #4cc38a; --pos-soft: #16302a; --neg: #f27c7c; --neg-soft: #3a1f23; --warn: #e9b35a; --warn-soft: #362b17;
    --info: #6aa8ff; --info-soft: #182a44; --violet: #b49cf7; --violet-soft: #2a2244;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.18); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0e1116; --surface: #151a21; --surface-2: #1a2029; --surface-3: #202733; --border: #262e3a; --border-strong: #323c4b;
    --text: #e8ebf0; --muted: #9aa3b2; --faint: #6b7483; --brand: #7c97ff; --brand-hover: #95abff; --brand-soft: #1e2748; --brand-contrast: #0b1020;
    --sidebar: #12161c; --sidebar-2: #1b212a; --sidebar-text: #aab3c0; --sidebar-strong: #eef1f5; --sidebar-border: #232a34;
    --pos: #4cc38a; --pos-soft: #16302a; --neg: #f27c7c; --neg-soft: #3a1f23; --warn: #e9b35a; --warn-soft: #362b17;
    --info: #6aa8ff; --info-soft: #182a44; --violet: #b49cf7; --violet-soft: #2a2244;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.18); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
    color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); letter-spacing: -.01em; }
.num, td.num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 16px; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* ============ Layout ============ */
.app { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 20px 14px 14px; z-index: 30; border-right: 1px solid var(--sidebar-border);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; color: var(--sidebar-strong); }
.brand .mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #5b7cff, #3d5afe); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.brand .name { font-weight: 700; font-size: 17px; letter-spacing: -.02em; line-height: 1.1; }
.brand .name span { color: var(--brand); }
.brand .co { font-size: 12px; color: var(--muted); }
.sidebar .eyebrow { color: var(--faint); padding: 6px 10px 8px; font-size: 10.5px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; color: var(--sidebar-text);
  font-weight: 500; text-decoration: none; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--sidebar-2); color: var(--sidebar-strong); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav a .count { margin-left: auto; font-size: 11px; font-weight: 600; background: var(--neg); color: #fff; border-radius: 99px; padding: 1px 7px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--sidebar-border); padding-top: 12px; }
.usercard { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.usercard .who { min-width: 0; flex: 1; }
.usercard .who b { display: block; color: var(--sidebar-strong); font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usercard .who span { font-size: 11.5px; color: var(--faint); }
.usercard button { background: none; border: 0; color: var(--sidebar-text); padding: 6px; border-radius: 8px; cursor: pointer; }
.usercard button:hover { background: var(--sidebar-2); color: var(--text); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 14px 28px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar .date { color: var(--muted); font-size: 13px; }
.topbar .menu-btn { display: none; }
.rate-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 11px; border: 1px solid var(--border); background: var(--surface); border-radius: 99px; font-size: 12.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.rate-chip b { color: var(--text); font-weight: 600; }
.rate-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); box-shadow: 0 0 0 3px var(--pos-soft); }
.rate-chip .dot.off { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
#view { padding: 24px 28px 60px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .title h2 { font-size: 24px; font-weight: 700; }
.page-head .title p { margin: 4px 0 0; color: var(--muted); }

/* ============ Controls ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 15px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { color: var(--neg); }
.btn.danger.solid { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; }
.btn.xs { height: 28px; padding: 0 9px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 30px; height: 30px; }
.btn .i { width: 16px; height: 16px; }
.btn.income { background: var(--pos); border-color: var(--pos); color: #fff; }
.btn.expense { background: var(--neg); border-color: var(--neg); color: #fff; }

.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 11px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 72px; padding: 9px 11px; resize: vertical; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.input.sm { height: 32px; font-size: 13px; }
.search { position: relative; }
.search .i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 16px; height: 16px; }
.search .input { padding-left: 32px; }
label.chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
label.chk input { width: 16px; height: 16px; accent-color: var(--brand); }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filters .input { width: auto; min-width: 150px; }
.filters .search { flex: 1; min-width: 200px; max-width: 340px; }
.filters .search .input { width: 100%; }
.date-range { display: inline-flex; align-items: center; gap: 6px; }
.date-range .input { min-width: 140px; }

/* ============ Cards ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 0; }
.card-head h3 { font-size: 15px; font-weight: 700; }
.card-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card-body { padding: 16px 20px 20px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); }

.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi .label .ic { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; }
.kpi .label .ic .i { width: 15px; height: 15px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 8px; font-variant-numeric: tabular-nums; font-family: var(--font-display); white-space: nowrap; }
.kpi .foot { color: var(--faint); font-size: 12px; margin-top: 2px; }
.ic.pos { background: var(--pos-soft); color: var(--pos); }
.ic.neg { background: var(--neg-soft); color: var(--neg); }
.ic.warn { background: var(--warn-soft); color: var(--warn); }
.ic.info { background: var(--info-soft); color: var(--info); }
.ic.violet { background: var(--violet-soft); color: var(--violet); }
.ic.brand { background: var(--brand-soft); color: var(--brand); }

.hero {
  position: relative; overflow: hidden; border-radius: var(--radius); padding: 22px 24px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.hero::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: linear-gradient(90deg, var(--brand), var(--info) 60%, var(--pos)); }
.hero .eyebrow { color: var(--brand); }
.hero h2 { font-size: 20px; margin-top: 6px; }
.hero p { margin: 4px 0 0; color: var(--muted); max-width: 520px; }
.hero .bal { margin-top: 18px; display: grid; grid-template-columns: 1.3fr repeat(3, 1fr); gap: 0; }
.hero .bal > div { padding: 2px 20px; border-left: 1px solid var(--border); }
.hero .bal > div:first-child { padding-left: 0; border-left: 0; }
.hero .bal .l { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.hero .bal .v { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; font-family: var(--font-display); margin-top: 2px; }
.hero .bal .v.small-v { font-size: 20px; margin-top: 8px; }
.hero .bal .s { font-size: 12px; color: var(--faint); }
.hero.risk::before { background: linear-gradient(90deg, var(--neg), var(--warn)); }
@media (max-width: 960px) {
  .hero .bal { grid-template-columns: 1fr 1fr; gap: 14px 0; }
  .hero .bal > div:nth-child(3) { padding-left: 0; border-left: 0; }
}

.alert {
  display: flex; align-items: center; gap: 14px; padding: 13px 16px; border-radius: var(--radius); border: 1px solid; margin-bottom: 12px;
}
.alert.danger { background: var(--surface); border-color: var(--border); box-shadow: inset 3px 0 0 var(--neg); }
.alert.warn { background: var(--surface); border-color: var(--border); box-shadow: inset 3px 0 0 var(--warn); }
.alert .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.alert.danger .ic { background: var(--neg-soft); color: var(--neg); }
.alert.warn .ic { background: var(--warn-soft); color: var(--warn); }
.alert b { display: block; }
.alert .sub { color: var(--muted); font-size: 12.5px; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; }
table.data th {
  text-align: left; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th:first-child { border-top-left-radius: var(--radius); }
table.data th:last-child { border-top-right-radius: var(--radius); }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; }
table.data td.actions { text-align: right; white-space: nowrap; width: 1%; }
table.data td.actions .btn { opacity: .65; }
table.data tr:hover td.actions .btn { opacity: 1; }
table.data tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border-strong); border-bottom: 0; }
table.data tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--neg); }
table.data tr.soon td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.data tr.done td { color: var(--muted); }
table.data tr.sel td { background: var(--brand-soft); }
table.compact td { padding: 8px 10px; }
table.compact th { padding: 8px 10px; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 12.5px; }
.cat { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.cat .dot { width: 8px; height: 8px; border-radius: 3px; flex: none; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--muted); }
.badge.pos { background: var(--pos-soft); color: var(--pos); }
.badge.neg { background: var(--neg-soft); color: var(--neg); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge .i { width: 12px; height: 12px; }

.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--pos); border-radius: 99px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .ic { width: 52px; height: 52px; border-radius: 16px; background: var(--surface-3); display: grid; place-items: center; margin: 0 auto 12px; color: var(--faint); }
.empty .ic .i { width: 24px; height: 24px; }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.more-row { display: flex; justify-content: center; padding: 12px; }
.bulkbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--brand-soft); border-radius: var(--radius-sm); margin-bottom: 12px; font-weight: 600; }

/* ============ Lists (dashboard) ============ */
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.li:last-child { border-bottom: 0; }
.li .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.li .ic .i { width: 16px; height: 16px; }
.li .body { flex: 1; min-width: 0; }
.li .body b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .body span { color: var(--muted); font-size: 12.5px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.li .amt small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.datebox { width: 44px; text-align: center; border-radius: 10px; background: var(--surface-3); padding: 5px 0; flex: none; line-height: 1.1; }
.datebox b { display: block; font-size: 17px; }
.datebox span { font-size: 10.5px; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; }
.datebox.overdue { background: var(--neg-soft); color: var(--neg); }
.datebox.overdue span { color: var(--neg); }
.datebox.soon { background: var(--warn-soft); color: var(--warn); }
.datebox.soon span { color: var(--warn); }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.donut-wrap { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 16px; align-items: center; }
.donut-wrap .chart-box { height: 140px; }
.cat-list { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.cat-list .r { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 13px; }
.cat-list .r .n { display: flex; align-items: center; gap: 7px; min-width: 0; }
.cat-list .r .n span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-list .bar { grid-column: 1 / -1; height: 4px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.cat-list .bar i { display: block; height: 100%; border-radius: 99px; }

.fc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.fc-stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.fc-stat .l { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.fc-stat .v { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.fc-stat .s { font-size: 12px; color: var(--muted); }
.fc-stat.risk { background: var(--neg-soft); border-color: color-mix(in srgb, var(--neg) 25%, transparent); }

/* ============ Modal / forms ============ */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 35, .42); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 100; animation: fade .15s ease; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 620px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); animation: pop .18s ease; }
.modal.wide { max-width: 860px; }
.modal.narrow { max-width: 440px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; font-weight: 700; flex: 1; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.span2 { grid-column: 1 / -1; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field > label .req { color: var(--neg); }
.field .hint { font-size: 12px; color: var(--faint); }
.form-error { background: var(--neg-soft); color: var(--neg); padding: 10px 12px; border-radius: 10px; font-weight: 600; margin-bottom: 14px; }
.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-switch button { height: 42px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.type-switch button.on.in { background: var(--pos-soft); border-color: var(--pos); color: var(--pos); }
.type-switch button.on.out { background: var(--neg-soft); border-color: var(--neg); color: var(--neg); }
.amount-input { font-size: 18px; font-weight: 700; height: 44px !important; font-variant-numeric: tabular-nums; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { display: flex; align-items: center; gap: 10px; background: #151a23; color: #eef6f2; padding: 11px 16px; border-radius: 11px; box-shadow: var(--shadow-lg); font-weight: 500; animation: pop .2s ease; max-width: 380px; }
.toast.err { background: #b4232a; }
.toast .i { width: 16px; height: 16px; }

.menu { position: absolute; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 200px; z-index: 90; animation: pop .12s ease; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 10px; background: none; border: 0; border-radius: 8px; cursor: pointer; font-weight: 500; text-align: left; }
.menu button:hover { background: var(--surface-3); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }

/* ============ Auth ============ */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side { background: radial-gradient(120% 120% at 0% 100%, #5b7cff 0%, #3148d6 45%, #1b2575 100%); color: #eef1ff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side h1 { font-size: 40px; line-height: 1.1; color: #fff; max-width: 460px; }
.auth-side p { color: #c9d3ff; max-width: 420px; font-size: 15px; }
.auth-side .feats { display: grid; gap: 12px; margin-top: 28px; }
.auth-side .feats div { display: flex; gap: 10px; align-items: center; color: #dfe5ff; }
.auth-side .feats .i { color: #b8c6ff; }
.auth-main { display: grid; place-items: center; padding: 32px 20px; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 26px; }
.auth-card p.lead { color: var(--muted); margin: 6px 0 24px; }
.auth-card form { display: grid; gap: 14px; }
.auth-card .btn { height: 44px; }

/* ============ Reports ============ */
table.matrix td, table.matrix th { padding: 8px 10px; font-size: 13px; }
table.matrix td.zero { color: var(--faint); }
table.matrix td:first-child, table.matrix th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.matrix th:first-child { background: var(--surface-2); z-index: 2; }
.heat { position: relative; }
.stat-rows { display: flex; flex-direction: column; }
.stat-rows .r { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.stat-rows .r:last-child { border-bottom: 0; }
.stat-rows .r.total { font-weight: 700; }

.inst-table .input { height: 34px; }
.detail-row td { background: var(--surface-2) !important; padding: 0 !important; }
.detail { padding: 16px 20px; display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.detail h4 { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

.cat-edit { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.cat-edit:last-child { border-bottom: 0; }
.cat-edit input[type=color] { width: 30px; height: 30px; border: 0; padding: 0; background: none; cursor: pointer; border-radius: 8px; }
.cat-edit .input { flex: 1; }

.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); color: var(--text); }

/* ============ Responsive ============ */
@media (max-width: 1200px) {
  .g-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g-main { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 272px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .topbar .date, .topbar .hide-sm { display: none; }
  #view { padding: 18px 16px 60px; }
  .g-4, .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .detail { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .g-2, .g-3, .g-4, .g-5 { grid-template-columns: 1fr; }
  .g-5.kpis, .g-4.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 19px; }
  .form-grid { grid-template-columns: 1fr; }
  .fc-stats { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; }
  .page-head .title h2 { font-size: 20px; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 94vh; overflow-y: auto; }
  .filters .input, .filters .search { min-width: 0; max-width: none; flex: 1 1 140px; }
  .rate-chip .rate-extra { display: none; }
  table.data.responsive thead { display: none; }
  table.data.responsive, table.data.responsive tbody, table.data.responsive tr, table.data.responsive td { display: block; width: 100%; }
  table.data.responsive tr { border-bottom: 1px solid var(--border); padding: 10px 4px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
  table.data.responsive td { border: 0; padding: 2px 8px; }
  table.data.responsive td.hide-m { display: none; }
  table.data.responsive td.num { text-align: right; }
  table.data.responsive td.actions { grid-column: 1 / -1; text-align: left; }
  table.data.responsive td.actions .btn { opacity: 1; }
  table.data.responsive tfoot { display: block; }
}
@media print {
  .sidebar, .topbar, .btn, .filters, .tabs { display: none !important; }
  .app { display: block; }
  #view { padding: 0; }
  .card { box-shadow: none; }
}

/* page-level headings replace the topbar title; the topbar keeps the date */
.main:has(.page-head) .topbar h1 { display: none; }
.main:has(.page-head) .topbar .date { font-size: 14px; color: var(--text); font-weight: 600; }
.g-main { align-items: start; }
.grid > * { min-width: 0; }
.card-head { flex-wrap: wrap; }

/* ============ Ajanda ============ */
svg.i.flip { transform: scaleX(-1); }
.c-in { --c: var(--pos); --cs: var(--pos-soft); }
.c-out { --c: var(--neg); --cs: var(--neg-soft); }
.c-check { --c: var(--info); --cs: var(--info-soft); }
.c-debt { --c: var(--violet); --cs: var(--violet-soft); }
.c-over { --c: var(--neg); --cs: var(--neg-soft); }
.ev-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--neg); flex: none; }

.ag-tabs { align-items: center; }
.ag-tabs button { display: inline-flex; align-items: center; gap: 7px; }
.ag-tabs button .i { width: 16px; height: 16px; }
.ag-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.ag-title { font-size: 20px; font-weight: 700; min-width: 170px; }
.ag-nav { display: inline-flex; gap: 4px; }
.ag-range { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; font-weight: 600; white-space: nowrap; }
.ag-range .i { width: 15px; height: 15px; color: var(--muted); }

.ag-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.ag-stat { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; flex: 1 1 150px; }
.ag-stat .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.ag-stat .dot.ring { background: transparent; box-shadow: inset 0 0 0 2.5px var(--c); }
.ag-stat .l { font-size: 12px; color: var(--muted); }
.ag-stat .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.ag-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.ag-month { overflow: hidden; }
.ag-dow { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.ag-dow div { padding: 9px 10px; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.ag-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.ag-cell { min-height: 132px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: background .12s; min-width: 0; }
.ag-cell:nth-child(7n) { border-right: 0; }
.ag-cell:hover { background: var(--surface-2); }
.ag-cell.wknd { background: repeating-linear-gradient(135deg, transparent 0 7px, color-mix(in srgb, var(--surface-3) 55%, transparent) 7px 8px); }
.ag-cell.out { background: var(--surface-2); }
.ag-cell.out .ag-dn, .ag-cell.out .ev { opacity: .45; }
.ag-cell.sel { background: var(--brand-soft); box-shadow: inset 0 0 0 1.5px var(--brand); }
.ag-dh { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 0 2px; }
.ag-dn { font-size: 13px; font-weight: 600; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.ag-cell.today .ag-dn { background: var(--brand); color: var(--brand-contrast); }
.ag-net { font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-evs { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ev { display: flex; flex-wrap: wrap; align-items: center; gap: 0 5px; width: 100%; min-width: 0; border: 0; border-left: 3px solid var(--c); background: var(--cs); color: var(--text); border-radius: 6px; padding: 3px 6px; font-size: 11.5px; cursor: pointer; text-align: left; line-height: 1.3; }
.ev:hover { box-shadow: 0 0 0 1px var(--c); }
.ev .i { width: 11px; height: 11px; color: var(--c); stroke-width: 2.6; }
.ev-t { flex: 1 1 60%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.ev-a { flex-basis: 100%; font-weight: 700; color: var(--c); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev.s-done { opacity: .62; }
.ev.s-planned, .ag-card.s-planned { background-image: repeating-linear-gradient(135deg, transparent 0 5px, color-mix(in srgb, var(--c) 10%, transparent) 5px 7px); }
.ev.s-planned { border-left-style: dashed; }
.ev-more { border: 0; background: none; color: var(--muted); font-size: 11.5px; font-weight: 600; text-align: left; padding: 1px 6px; cursor: pointer; }
.ev-more:hover { color: var(--brand); }
.ag-mdots { display: none; }

.ag-day { position: sticky; top: 84px; padding: 16px; }
.ag-day-head { display: flex; align-items: flex-start; gap: 10px; justify-content: space-between; }
.ag-day-head h3 { font-size: 16px; margin-top: 3px; }
.ag-day-tot { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.ag-day-tot > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; min-width: 0; }
.ag-day-tot b { font-variant-numeric: tabular-nums; font-size: 13px; overflow-wrap: anywhere; line-height: 1.3; }
.ag-day-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.ag-item { display: flex; align-items: center; gap: 10px; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 10px 9px 0; cursor: pointer; text-align: left; overflow: hidden; color: var(--text); }
.ag-item:hover { border-color: var(--c); }
.ag-item .bar { width: 4px; align-self: stretch; background: var(--c); border-radius: 0 3px 3px 0; flex: none; }
.ag-item.s-planned .bar { background: repeating-linear-gradient(180deg, var(--c) 0 4px, transparent 4px 7px); }
.ag-item .body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ag-item .body b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-item .body span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-item .amt { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ag-item.s-done { opacity: .72; }
.ag-legend { margin-top: 12px; }
.ag-legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); display: inline-block; }
.ag-legend i.planned { background: transparent; border: 1.5px dashed var(--muted); }
.ag-legend i.ev-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--neg); }
.ag-legend .i { width: 13px; height: 13px; }

.ag-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); overflow: hidden; }
.ag-col { border-right: 1px solid var(--border); min-width: 0; display: flex; flex-direction: column; }
.ag-col:last-child { border-right: 0; }
.ag-col.wknd .ag-col-b { background: repeating-linear-gradient(135deg, transparent 0 7px, color-mix(in srgb, var(--surface-3) 55%, transparent) 7px 8px); }
.ag-col-h { padding: 10px 10px 8px; border-bottom: 1px solid var(--border); background: var(--surface-2); cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.ag-col-h span { font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.ag-col-h b { font-size: 20px; line-height: 1.2; }
.ag-col-h small { display: flex; flex-wrap: wrap; gap: 0 6px; font-size: 11px; font-weight: 600; }
.ag-col-h small em { font-style: normal; }
.ag-col.today .ag-col-h { background: var(--brand-soft); }
.ag-col.today .ag-col-h b { color: var(--brand); }
.ag-col-b { padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 420px; flex: 1; }
.ag-card { display: flex; flex-direction: column; gap: 2px; border: 0; border-top: 3px solid var(--c); background: var(--cs); border-radius: 8px; padding: 7px 9px 9px; text-align: left; cursor: pointer; color: var(--text); min-width: 0; }
.ag-card:hover { box-shadow: 0 0 0 1px var(--c); }
.ag-card .top { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: 12px; font-weight: 700; color: var(--c); padding-bottom: 4px; margin-bottom: 2px; border-bottom: 1px dashed color-mix(in srgb, var(--c) 35%, transparent); font-variant-numeric: tabular-nums; }
.ag-card .top .i { width: 13px; height: 13px; stroke-width: 2.6; }
.ag-card b { font-size: 12.5px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.ag-card small { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-card.s-done { opacity: .62; }
.ag-card.s-planned { border-top-style: dashed; }
.ag-add { border: 1px dashed var(--border-strong); background: transparent; border-radius: 8px; height: 30px; color: var(--faint); cursor: pointer; display: grid; place-items: center; opacity: 0; transition: opacity .15s; }
.ag-col:hover .ag-add { opacity: 1; }
.ag-add:hover { color: var(--brand); border-color: var(--brand); }
.ag-add .i { width: 15px; height: 15px; }

.ag-list { padding: 6px 16px; }
.ag-lday { padding: 12px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.ag-lday:last-child { border-bottom: 0; }
.ag-lday-h { display: flex; align-items: center; gap: 12px; }
.ag-lday-h .grow { flex: 1; display: flex; flex-direction: column; }
.ag-lday.past .ag-lday-h { opacity: .75; }
.ag-lday .ag-item { margin-left: 56px; width: calc(100% - 56px); }

.ag-detail .amt { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; font-family: var(--font-display); }
.ag-detail h3 { font-size: 16px; margin-top: 6px; }

@media (max-width: 1200px) {
  .ag-layout { grid-template-columns: 1fr; }
  .ag-day { position: static; }
}
@media (max-width: 760px) {
  .ag-cell { min-height: 58px; padding: 4px; align-items: center; }
  .ag-cell .ag-evs, .ag-cell .ag-net { display: none; }
  .ag-mdots { display: flex; gap: 3px; justify-content: center; }
  .ag-mdots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
  .ag-dow div { padding: 8px 4px; text-align: center; font-size: 10.5px; }
  .ag-week { grid-template-columns: 1fr; }
  .ag-col { border-right: 0; border-bottom: 1px solid var(--border); }
  .ag-col-b { min-height: 0; }
  .ag-add { opacity: 1; }
  .ag-lday .ag-item { margin-left: 0; width: 100%; }
  .ag-title { min-width: 0; font-size: 18px; }
  .ag-range { display: none; }
}

/* ============ Phone app (tab bar, safe areas) ============ */
.tabbar { display: none; }
.install-steps { margin: 0 0 10px; padding-left: 20px; display: grid; gap: 8px; }
@media (max-width: 960px) {
  .topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
  .topbar [data-quick] { display: none; }
  .sidebar { padding-top: calc(20px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  #view { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); left: 16px; right: 16px; }
  .toast { max-width: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px);
    border-top: 1px solid var(--border); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0; color: var(--faint); font-size: 11px; font-weight: 600; text-decoration: none; border-radius: 10px; }
  .tabbar a .i { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--brand); }
  .tabbar .tab-add { justify-self: center; width: 48px; height: 48px; border-radius: 16px; border: 0; background: var(--brand); color: var(--brand-contrast); display: grid; place-items: center; box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 35%, transparent); cursor: pointer; }
  .tabbar .tab-add .i { width: 24px; height: 24px; stroke-width: 2.2; }
  .overlay { padding-bottom: 0; }
  .modal { padding-bottom: env(safe-area-inset-bottom); }
}
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
}
