:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --border: #dfded8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7b7a74;
  --accent: #256abf;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;   /* income / single-series bars */
  --series-2: #eb6834;   /* expenses */
  --good: #006300;
  --bad: #b32626;
  --warn-bg: #fdf3d7;
  --warn-border: #e9c765;
  --chip: #ecebe6;
  --grid: #e6e5df;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #33332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #93928a;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #4fc04f;
    --bad: #f08080;
    --warn-bg: #3a3115;
    --warn-border: #7d6520;
    --chip: #2a2a27;
    --grid: #2c2c29;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, "Segoe UI", "Noto Sans Hebrew", Arial, sans-serif;
}
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--bad); min-height: 1.2em; margin: .3rem 0; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

button, select, input, textarea {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .4rem .7rem;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.danger { color: var(--bad); }
input:focus-visible, select:focus-visible, button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: .2rem; font-size: .9rem; color: var(--text-2); }
label.inline { display: flex; align-items: center; gap: .4rem; }
label.check { display: flex; align-items: center; gap: .5rem; color: var(--text); }
label.check input { width: auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; }

/* lock */
.lock { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.lock-card { width: min(420px, 100%); display: grid; gap: .7rem; }
.lock-card input { width: 100%; }

/* shell */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-size: 1.1rem; margin-inline-end: .5rem; }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; }
.nav button { border-color: transparent; background: none; }
.nav button.active { background: var(--chip); font-weight: 600; }
.spacer { flex: 1; }
.view { max-width: 1200px; margin: 0 auto; padding: 1rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.view > *, .grid2 > *, .kpis > * { min-width: 0; }

.banner { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 10px; padding: .6rem .9rem; display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.banner .spacer { flex: 1; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; }
.kpi .label { color: var(--text-2); font-size: .9rem; }
.kpi .value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.kpi .delta { font-size: .85rem; color: var(--text-2); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 1rem; align-items: start; }
.chart-box { position: relative; height: 280px; }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--text-2); margin-bottom: .4rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: .35rem; }
.sw1 { background: var(--series-1); }
.sw2 { background: var(--series-2); }

/* category bars */
.bars { display: grid; gap: .15rem; }
.bar-row {
  display: grid; grid-template-columns: minmax(110px, 28%) 1fr auto; gap: .6rem; align-items: center;
  padding: .3rem .4rem; border: 0; border-radius: 8px; background: none; text-align: start; width: 100%;
}
.bar-row:hover { background: var(--chip); }
.bar-track { height: 12px; }
.bar-fill { display: block; height: 100%; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; }
[dir="rtl"] .bar-fill { border-radius: 4px 0 0 4px; }
.bar-val { text-align: end; min-width: 150px; }
.bar-val .delta { font-size: .8rem; color: var(--text-2); margin-inline-start: .4rem; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: start; padding: .45rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-2); font-weight: 600; font-size: .82rem; white-space: nowrap; }
td.end, th.end { text-align: end; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--chip); }
tr.dim td { color: var(--muted); }
tr.dim .amount { text-decoration: line-through; }
.tag { display: inline-block; background: var(--chip); border-radius: 6px; padding: 0 .4rem; font-size: .78rem; color: var(--text-2); margin-inline-start: .3rem; white-space: nowrap; }
.tag.review { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--text); }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filters input[type="search"] { min-width: 220px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .7rem; align-items: end; }
.form-grid input, .form-grid select { width: 100%; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.ok-mark { color: var(--good); font-size: .8rem; }

/* dialog */
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 1.2rem; width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form, dialog .stack { display: grid; gap: .7rem; }
dialog input, dialog select { width: 100%; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.steps li { display: flex; gap: .5rem; }

/* AI */
.md h2, .md h3, .md h4 { margin: 1rem 0 .3rem; }
.md ul, .md ol { margin: .3rem 0; padding-inline-start: 1.3rem; }
.md table { margin: .5rem 0; }
.md code { background: var(--chip); padding: 0 .25rem; border-radius: 4px; }
.chat { display: grid; gap: .6rem; max-height: 60vh; overflow-y: auto; padding: .2rem; }
.msg { border-radius: 12px; padding: .6rem .85rem; max-width: 88%; }
.msg.user { background: var(--accent); color: var(--accent-ink); justify-self: start; white-space: pre-wrap; }
.msg.assistant { background: var(--chip); justify-self: end; }
.chat-form { display: flex; gap: .5rem; }
.chat-form textarea { flex: 1; resize: vertical; min-height: 2.6rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips button { font-size: .85rem; border-radius: 999px; }

.toast { position: fixed; bottom: 1rem; inset-inline: 0; margin: 0 auto; width: fit-content; max-width: 90vw; background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 10px; z-index: 20; }
.empty { text-align: center; padding: 2.5rem 1rem; }

@media (max-width: 640px) {
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; order: 3; }
  .bar-val { min-width: 0; }
}
