:root {
  color-scheme: light;
  --page: #edf1f8;
  --surface: #ffffff;
  --surface2: #eef2f9;
  --ink: #0c1426;
  --ink2: #47526b;
  --muted: #7a859c;
  --line: #e3e8f2;
  --border: rgba(12, 20, 38, 0.08);
  --accent: #2a6fe8;
  --accent-soft: rgba(42, 111, 232, 0.12);
  --prev: #a3adc2;
  --good: #0a8a3c;
  --bad: #d5372f;
  --good-soft: rgba(10, 138, 60, 0.12);
  --bad-soft: rgba(213, 55, 47, 0.12);
  --shadow: 0 1px 2px rgba(12, 20, 38, 0.05), 0 8px 24px rgba(12, 20, 38, 0.05);
  --hero: linear-gradient(135deg, #1f4fd1 0%, #5a3bd6 55%, #9a35c2 100%);
  --brand: linear-gradient(135deg, #3d8bff, #7a4dff);
  --h0: #cde2fb; --h1: #86b6ef; --h2: #3987e5; --h3: #1c5cab; --h4: #0d366b;
  --h0-ink: #0b0b0b; --h1-ink: #0b0b0b; --h2-ink: #fff; --h3-ink: #fff; --h4-ink: #fff;
  /* палітра категорій: фіксований порядок */
  --c0: #8a94a8; --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --c5: #e87ba4; --c6: #008300; --c7: #6250d6; --c8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #090e1c;
    --surface: #111a30;
    --surface2: #1a2644;
    --ink: #eef2fb;
    --ink2: #b7c1d8;
    --muted: #7f8cab;
    --line: #1e2a49;
    --border: rgba(160, 185, 255, 0.10);
    --accent: #5b93ff;
    --accent-soft: rgba(91, 147, 255, 0.18);
    --prev: #5d6a8a;
    --good: #34c366;
    --bad: #ff6b63;
    --good-soft: rgba(52, 195, 102, 0.16);
    --bad-soft: rgba(255, 107, 99, 0.16);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    --h0: #12305f; --h1: #184f95; --h2: #1c5cab; --h3: #256abf; --h4: #86b6ef;
    --h0-ink: #fff; --h1-ink: #fff; --h2-ink: #fff; --h3-ink: #fff; --h4-ink: #0b0b0b;
    --c0: #6f7b96; --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
    --c5: #d55181; --c6: #0ca30c; --c7: #9085e9; --c8: #e66767;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 12px; margin: 0 0 14px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
h3 { font-size: 15px; margin: 0; }
button, select, input { font: inherit; color: inherit; }
button, select, input[type="password"], input[type="text"], input[type="number"], input[type="date"] {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
input:not([type="checkbox"]), select { background: var(--surface2); border-color: transparent; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--brand); border-color: transparent; color: #fff; font-weight: 600; box-shadow: 0 4px 14px rgba(77, 120, 255, 0.35); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); border-color: transparent; }
button.danger { color: var(--bad); }
button.link { border: 0; background: transparent; color: var(--accent); padding: 0; font-size: 13px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- вхід і блокування ---------- */
.setup { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(900px 500px at 15% -10%, rgba(90, 59, 214, 0.28), transparent 60%), radial-gradient(700px 500px at 100% 110%, rgba(42, 111, 232, 0.25), transparent 60%), var(--page); }
.setupbox { width: 100%; max-width: 460px; }
.setupbox h1 { font-size: 28px; margin: 22px 0 8px; }
.lead { color: var(--ink2); margin: 0 0 20px; }
.setup label { font-weight: 600; display: block; }
.setup label.gap { margin-top: 18px; }
.setup input { width: 100%; margin-top: 8px; }
.setup label.gap[hidden] + input { margin-top: 0; }
.codebox { font: 700 20px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.06em; text-align: center; padding: 18px 12px; border-radius: 12px; background: var(--surface2); border: 1px dashed var(--muted); user-select: all; overflow-wrap: anywhere; }
.status { min-height: 1.45em; color: var(--ink2); font-size: 13px; margin: 12px 0; }
.status.error { color: var(--bad); }

/* ---------- каркас ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { font-size: 16px; display: block; letter-spacing: -0.01em; }
.brand small { color: #8f9cc0; font-size: 12px; display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { width: 36px; height: 36px; border-radius: 11px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; box-shadow: 0 6px 16px rgba(77, 120, 255, 0.4); }

.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100%; }
.side { background: linear-gradient(180deg, #101936 0%, #0a1024 100%); color: #dfe6f7; padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 26px; }
.side .brand { padding: 0 8px; }
.nav { display: grid; gap: 4px; }
.navbtn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px; background: transparent; color: #a9b4d0; text-align: left; }
.navbtn:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.navbtn.active { background: var(--brand); color: #fff; font-weight: 600; box-shadow: 0 6px 18px rgba(77, 120, 255, 0.35); }
.navbtn svg, .syncbtn svg, .ico svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.navbtn .short { display: none; }
.lockbtn { margin-top: auto; }

.main { padding: 24px 32px 48px; max-width: 1280px; width: 100%; min-width: 0; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 22px; }
.topbar h1 { margin-right: auto; }
.monthnav { display: flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 3px; box-shadow: var(--shadow); }
.monthnav button { border: 0; background: transparent; padding: 4px 12px; font-size: 16px; line-height: 1.3; border-radius: 9px; }
.monthnav button:hover:not(:disabled) { background: var(--surface2); }
.monthnav strong { min-width: 12ch; text-align: center; font-weight: 600; }
.syncbtn { display: inline-flex; align-items: center; gap: 8px; color: var(--ink2); font-size: 12.5px; padding: 8px 12px; border-radius: 12px; font-variant-numeric: tabular-nums; box-shadow: var(--shadow); }
.syncbtn.busy svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .syncbtn.busy svg { animation: none; } }
.banner { margin: 0 0 16px; padding: 10px 14px; border-radius: 12px; background: var(--bad-soft); color: var(--bad); font-size: 13px; }

/* ---------- картки й показники ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 20px 22px; margin-bottom: 18px; min-width: 0; box-shadow: var(--shadow); }
.cardhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px 20px; min-width: 0; box-shadow: var(--shadow); display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 14px; align-items: center; }
.tile .ico { grid-row: 1 / span 3; width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tile .ico.out { background: var(--bad-soft); color: var(--bad); }
.tile .ico.in { background: var(--good-soft); color: var(--good); }
.tile .ico.violet { background: color-mix(in srgb, var(--c7) 18%, transparent); color: var(--c7); }
.tile .ico.amber { background: color-mix(in srgb, var(--c4) 20%, transparent); color: var(--c4); }
.tile .ico svg { width: 22px; height: 22px; }
.tile .k, .tile .v, .tile .s { grid-column: 2; min-width: 0; }
.tile .k { color: var(--muted); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
.tile .v { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .s { color: var(--muted); font-size: 12.5px; }
.delta { font-weight: 700; }

.dash { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.dash > * { margin: 0; }
.span3 { grid-column: span 3; } .span4 { grid-column: span 4; } .span5 { grid-column: span 5; } .span6 { grid-column: span 6; }
.span7 { grid-column: span 7; } .span8 { grid-column: span 8; } .span12 { grid-column: span 12; }

.hero { position: relative; overflow: hidden; background: var(--hero); border: 0; color: #fff; box-shadow: 0 14px 34px rgba(70, 60, 210, 0.35); }
.hero::after { content: ""; position: absolute; right: -70px; top: -90px; width: 260px; height: 260px; border-radius: 50%; background: rgba(255, 255, 255, 0.10); pointer-events: none; }
.hero::before { content: ""; position: absolute; right: 60px; bottom: -120px; width: 220px; height: 220px; border-radius: 50%; background: rgba(255, 255, 255, 0.07); pointer-events: none; }
.hero { display: flex; flex-direction: column; }
.hero .split:first-of-type { margin-top: auto; }
.hero h2 { color: rgba(255, 255, 255, 0.75); }
.hero .big { font-size: 40px; font-weight: 750; letter-spacing: -0.03em; line-height: 1.15; margin: 2px 0 18px; white-space: nowrap; position: relative; z-index: 1; }
.hero .hint { color: rgba(255, 255, 255, 0.75); }
.split { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid rgba(255, 255, 255, 0.18); color: rgba(255, 255, 255, 0.82); position: relative; z-index: 1; }
.split b { color: #fff; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpis { display: grid; grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 18px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 18px; }

/* ---------- курси валют ---------- */
.rate { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.rate:first-of-type { border-top: 0; padding-top: 0; }
.chip { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 16px; color: #fff; background: var(--c0); flex: none; }
.chip.usd { background: var(--c3); } .chip.eur { background: var(--c1); } .chip.uah { background: var(--c7); }
.rate .code { font-weight: 650; }
.rate small { display: block; color: var(--muted); font-size: 12px; }
.rate .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; }
.rate .num small { font-weight: 400; }

/* ---------- графіки ---------- */
.chartlegend { display: flex; flex-wrap: wrap; gap: 16px; color: var(--ink2); font-size: 12.5px; margin: -4px 0 8px; }
.chartlegend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.lg-cur { background: var(--accent); } .lg-prv { background: var(--prev); }
.trend svg { display: block; width: 100%; overflow: visible; }
.trend text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.trend .endlabel { fill: var(--ink); font-weight: 700; }
.trend .gridline { stroke: var(--line); stroke-width: 1; }
.trend .cur { stroke: var(--accent); }
.trend .prv { stroke: var(--prev); }
.trend .area { fill: url(#trendFill); }
.trend .stop-a { stop-color: var(--accent); stop-opacity: 0.32; }
.trend .stop-b { stop-color: var(--accent); stop-opacity: 0; }
.trend .dot-cur { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.trend .dot-prv { fill: var(--prev); stroke: var(--surface); stroke-width: 2; }
.trend .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }

.donutwrap { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 20px; align-items: center; }
.donut { width: 170px; height: 170px; }
.donut circle { fill: none; stroke-width: 18; }
.donut .hole { fill: var(--c0); font-size: 11px; }
.donut text { text-anchor: middle; fill: var(--muted); font-size: 11px; }
.donut text.total { fill: var(--ink); font-size: 17px; font-weight: 700; }
.lgrow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 6px 0; }
.lgrow .dot { width: 10px; height: 10px; border-radius: 3px; }
.lgrow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lgrow b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.lgrow .pct { color: var(--muted); font-size: 12px; min-width: 2.6em; text-align: right; }
.st0 { stroke: var(--c0); } .st1 { stroke: var(--c1); } .st2 { stroke: var(--c2); } .st3 { stroke: var(--c3); } .st4 { stroke: var(--c4); }
.st5 { stroke: var(--c5); } .st6 { stroke: var(--c6); } .st7 { stroke: var(--c7); } .st8 { stroke: var(--c8); }
.bg0 { background: var(--c0); } .bg1 { background: var(--c1); } .bg2 { background: var(--c2); } .bg3 { background: var(--c3); } .bg4 { background: var(--c4); }
.bg5 { background: var(--c5); } .bg6 { background: var(--c6); } .bg7 { background: var(--c7); } .bg8 { background: var(--c8); }
.bg4, .av.bg4 { color: #0b0b0b; }

/* ---------- календар ---------- */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendar .dow { text-align: center; color: var(--muted); font-size: 11.5px; font-weight: 600; padding-bottom: 4px; }
.day {
  min-height: 62px; line-height: 1.2;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;
  padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; color: var(--ink2); text-align: left; overflow: hidden;
}
.day .n { font-size: 12px; font-weight: 600; }
.day .a { font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.day .inc, .day .plan { font-size: 10.5px; white-space: nowrap; }
.day.sel { outline: 2px solid var(--ink); outline-offset: 1px; }
.day.future { color: var(--muted); }
.h0 { background: var(--h0); color: var(--h0-ink); border-color: transparent; }
.h1 { background: var(--h1); color: var(--h1-ink); border-color: transparent; }
.h2 { background: var(--h2); color: var(--h2-ink); border-color: transparent; }
.h3 { background: var(--h3); color: var(--h3-ink); border-color: transparent; }
.h4 { background: var(--h4); color: var(--h4-ink); border-color: transparent; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.legend span { margin: 0 6px; }
.legend i { width: 18px; height: 10px; border-radius: 3px; }
.legend .planmark { margin-left: auto; }
.daypanel { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.daypanel .group { display: flex; justify-content: space-between; gap: 12px; margin: 16px 0 2px; font-weight: 700; }
.daypanel .group span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- смуги категорій ---------- */
.bars { display: grid; gap: 2px; }
.bar { display: grid; grid-template-columns: auto minmax(0, 10em) minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%; padding: 8px; margin: 0 -8px; border: 0; border-radius: 10px; background: transparent; text-align: left; }
button.bar:hover, .bar.sel { background: var(--surface2); }
.bar .dot { width: 10px; height: 10px; border-radius: 3px; }
.bar .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .track { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; min-width: 3px; border-radius: 4px; }
.bar .val { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 650; }
.bar .pct { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 8px; display: inline-block; min-width: 2.6em; text-align: right; }

/* ---------- рядки списків ---------- */
.row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 0 12px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .av { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff; }
.row .av.in { background: var(--good); }
.row .body { min-width: 0; }
.row .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.row .m { color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.row .m select { font-size: 12px; padding: 1px 4px; border-radius: 6px; color: var(--ink2); max-width: 100%; }
.row .amt { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; text-align: right; }
.row .acts { display: flex; gap: 4px; }
.row .acts:empty { display: none; }
.row .acts button { padding: 3px 8px; font-size: 13px; color: var(--ink2); border-radius: 8px; }
.row .meter { grid-column: 2 / -1; }
.meter { height: 7px; background: var(--surface2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.meter > div { height: 100%; background: var(--brand); border-radius: 4px; }
.empty { color: var(--muted); padding: 10px 0; }

.addform { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; align-items: end; margin-top: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.addform label { font-size: 12px; color: var(--ink2); display: grid; gap: 4px; }
.addform input, .addform select { width: 100%; min-width: 0; padding: 9px 10px; }

.setrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.setrow:first-of-type { border-top: 0; }
.setrow .grow { flex: 1; min-width: 0; font-weight: 600; }
.setrow small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.setrow input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.tip { position: fixed; z-index: 30; pointer-events: none; max-width: 260px; background: #0c1426; color: #eef2fb; padding: 8px 11px; border-radius: 10px; font-size: 12px; white-space: pre-line; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }

/* ---------- планшет і телефон ---------- */
@media (max-width: 1120px) {
  .span3, .span4, .span5, .span6, .span7, .span8 { grid-column: span 12; }
  .kpis { grid-template-rows: none; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .side { position: fixed; inset: auto 0 0 0; top: auto; height: auto; z-index: 20; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .side .brand, .lockbtn { display: none; }
  .nav { grid-template-columns: repeat(5, minmax(0, 1fr)); width: 100%; gap: 0; }
  .navbtn { flex-direction: column; gap: 3px; padding: 7px 2px; font-size: 10.5px; text-align: center; }
  .navbtn.active { background: transparent; box-shadow: none; color: #7fb0ff; }
  .navbtn .full { display: none; }
  .navbtn .short { display: block; }
  .main { padding: calc(16px + env(safe-area-inset-top)) 16px calc(88px + env(safe-area-inset-bottom)); }
  .setup { padding-top: calc(24px + env(safe-area-inset-top)); }
  .topbar { margin-bottom: 16px; }
  .topbar h1 { flex-basis: 100%; margin-right: 0; }
  .monthnav { margin-right: auto; }
  .tiles, .tiles.three, .kpis { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .dash { gap: 12px; }
  .card { padding: 16px; margin-bottom: 12px; border-radius: 16px; }
  .tile { padding: 14px 16px; border-radius: 16px; }
  .hero .big { font-size: 34px; }
  .day { min-height: 54px; padding: 4px 5px; }
  .bar { grid-template-columns: auto minmax(0, 8em) minmax(0, 1fr) auto; }
  .legend .planmark { margin-left: 6px; flex-basis: 100%; }
  .donutwrap { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .donutwrap > div { width: 100%; }
}
