:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2330;
  --muted: #6b7482;
  --border: #e3e6eb;
  --accent: #0f9d76;
  --accent-soft: #e2f5ee;
  --danger: #d64545;
  --danger-soft: #fde8e8;
  --warn: #c77700;
  --warn-soft: #fff3df;
  --good: #128a5b;
  --good-soft: #e2f5ec;
  --info: #3b6fd4;
  --info-soft: #e6eefc;
  --income: #17a673;
  --expense: #e05a47;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2430;
    --text: #e7eaf0;
    --muted: #9aa3b2;
    --border: #2a303c;
    --accent: #2cc596;
    --accent-soft: #143a2f;
    --danger: #f07272;
    --danger-soft: #3a1c1f;
    --warn: #f0ad4e;
    --warn-soft: #3a2c14;
    --good: #3ccf8e;
    --good-soft: #143326;
    --info: #7ea6f5;
    --info-soft: #1a2540;
    --income: #3ccf8e;
    --expense: #f07a6a;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; margin: 0 0 .8rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.pos { color: var(--income); }
.neg { color: var(--text); }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 228px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; padding: 4px 10px 18px; color: var(--text); }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 17px; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .ico { width: 20px; text-align: center; }
.sidebar .bottom { margin-top: auto; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1240px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 16px; flex-direction: row; align-items: center; gap: 6px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .brand span:last-child { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { white-space: nowrap; padding: 8px 10px; margin: 0; }
  .nav a .lbl { display: none; }
  .nav a.active .lbl { display: inline; }
  .sidebar .bottom { margin: 0 0 0 auto; }
  .main { padding: 18px 16px 48px; }
}

/* Cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1050px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3-1 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 420px) { .grid-4 { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 16px; }

.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.55rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.delta-up { color: var(--danger); }
.delta-down { color: var(--good); }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: .85rem; border-radius: 8px; }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0; font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { font-size: .88rem; color: var(--muted); display: block; margin-bottom: 4px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row > div { display: flex; flex-direction: column; }
.inline { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { min-width: 220px; flex: 1; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; border: 1px solid transparent; }
.flash.ok { background: var(--good-soft); color: var(--good); }
.flash.error { background: var(--danger-soft); color: var(--danger); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 6px; border-bottom: 1px solid var(--border); }
td { padding: 9px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.tx-main { font-weight: 600; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { color: var(--muted); font-size: .82rem; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; gap: 5px; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: .8rem; background: var(--surface-2); white-space: nowrap; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; vertical-align: middle; }
.badge.new { background: var(--info-soft); color: var(--info); }
.badge.up { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: var(--surface-2); color: var(--muted); }
.cat-select { max-width: 220px; padding: 5px 8px; font-size: .88rem; }

/* Bars */
.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row .top { display: flex; justify-content: space-between; gap: 10px; font-size: .92rem; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 9px; background: var(--surface-2); border-radius: 99px; margin-top: 5px; position: relative; overflow: visible; }
.bar > span { display: block; height: 100%; border-radius: 99px; min-width: 3px; }
.bar .budget-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); opacity: .55; border-radius: 2px; }
.bar-row .meta { font-size: .78rem; color: var(--muted); margin-top: 3px; }

.chart { display: flex; align-items: flex-end; gap: 8px; height: 190px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; min-width: 0; }
.chart .pair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.chart .b { width: 42%; max-width: 18px; border-radius: 5px 5px 2px 2px; min-height: 2px; }
.chart .b.in { background: var(--income); opacity: .85; }
.chart .b.out { background: var(--expense); opacity: .85; }
.chart .lbl { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.chart .col.current .lbl { color: var(--text); font-weight: 700; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Insights */
.insights { display: flex; flex-direction: column; gap: 10px; }
.insight { display: flex; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.insight .ic { font-size: 1.25rem; line-height: 1.3; }
.insight .t { font-weight: 650; }
.insight .d { font-size: .9rem; color: var(--muted); margin-top: 1px; }
.insight.warn { background: var(--warn-soft); }
.insight.warn .t { color: var(--warn); }
.insight.good { background: var(--good-soft); }
.insight.good .t { color: var(--good); }
.ai-box { white-space: pre-line; background: var(--info-soft); border-radius: 12px; padding: 14px 16px; }
.ai-box .head { font-weight: 700; color: var(--info); margin-bottom: 4px; }

.month-nav { display: flex; gap: 6px; align-items: center; }
.empty { text-align: center; padding: 56px 20px; }
.empty .big { font-size: 3rem; }
.steps { text-align: left; max-width: 560px; margin: 18px auto; }
.steps li { margin-bottom: 6px; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.status-dot.on { background: var(--good); }
.status-dot.off { background: var(--danger); }
details summary { cursor: pointer; font-weight: 600; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .88em; word-break: break-all; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card input { width: 100%; }
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 14px; align-items: center; }
.right { text-align: right; }
.mt { margin-top: 16px; }
.show-sm { display: none; }
@media (max-width: 700px) {
  .hide-sm { display: none; }
  .show-sm { display: inline; }
  .tx-main, .tx-sub { max-width: 40vw; }
  .cat-select { max-width: 112px; }
  td { padding: 8px 4px; }
  .card { padding: 16px 14px; }
  .chart { gap: 3px; }
  .chart .col:nth-child(even):not(.current) .lbl { visibility: hidden; }
  .kpi .value { font-size: 1.35rem; }
}
