/* Фінанси NutsBox — mobile-first. Теплий помаранчевий акцент KPIBro на спокійному графітовому тлі. */
:root {
  color-scheme: light dark;
  --bg: #f6f3ef; --card: #fff; --ink: #1f1a17; --ink2: #5f544c; --line: #e8e1d9; --field: #a89a8f; --soft: #f1ebe4; --input: #fff;
  --top: #1f1a17; --top-ink: #fff; --top-ink2: #d8cbbf;
  --accent: #f07a1a; --accent-btn: #b5560a; --accent-ink: #fff; --accent-soft: #fdebdc;
  --good: #17703d; --good-soft: #e3f4ea; --bad: #b3261e; --bad-soft: #fbe6e4; --warn: #8a5a05; --warn-soft: #fbf0d9;
  --notice-bad: #7d1f19; --notice-warn: #6d4706; --notice-good: #145c33; --notice-info: #7a3b06;
  --r: 14px; --gap: 12px; --shadow: 0 1px 2px rgba(31,26,23,.06), 0 4px 16px rgba(31,26,23,.05);
  font-synthesis: none;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141110; --card: #1f1b19; --ink: #f2ece6; --ink2: #b8aca2; --line: #36302c; --field: #6f645c; --soft: #2a2522; --input: #171412;
    --top: #0d0b0a; --top-ink: #fff; --top-ink2: #c9bcb0;
    --accent-soft: #3a2615; --good: #5fcf8b; --good-soft: #16301f; --bad: #ff8a80; --bad-soft: #3a1714; --warn: #f0c060; --warn-soft: #33270f;
    --notice-bad: #ffc4bd; --notice-warn: #f3d79a; --notice-good: #aee8c4; --notice-info: #f7c79a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-text-size-adjust: 100%; }
.boot { padding: 40px; text-align: center; color: var(--ink2); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink2); }
.small { font-size: 13px; }
.neg { color: var(--bad); }
.pos { color: var(--good); }
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--ink2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* шапка й вкладки */
.top { position: sticky; top: 0; z-index: 20; background: var(--top); color: var(--top-ink); padding: calc(10px + env(safe-area-inset-top)) 16px 0; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.brand img { width: 24px; height: 24px; }
.top .date { background: transparent; border: 1px solid #8a7b70; color: #fff; border-radius: 10px; padding: 6px 8px; font-size: 14px; min-height: 36px; width: auto; color-scheme: dark; }
.asof { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--top-ink2); flex-wrap: wrap; justify-content: center; }
.asof.past .date { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.today { border: 0; background: var(--accent-btn); color: #fff; border-radius: 10px; width: 36px; min-height: 36px; cursor: pointer; font-size: 16px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.lock { font-size: 12px; color: var(--top-ink2); white-space: nowrap; }
.iconbtn { border: 1px solid #8a7b70; background: transparent; color: #fff; border-radius: 10px; padding: 0 10px; height: 36px; cursor: pointer; font-size: 13px; }
.asof { flex-wrap: nowrap; }
@media (max-width: 380px) { .asof label { display: none; } }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 10px -16px 0; padding: 0 12px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs { mask-image: linear-gradient(90deg, #000 85%, transparent); -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); }
.tab { flex: 0 0 auto; border: 0; background: none; color: var(--top-ink2); padding: 12px 10px 12px; min-height: 44px; border-bottom: 2px solid transparent; cursor: pointer; font-weight: 550; }
.tab.on { color: #fff; border-bottom-color: var(--accent); }
.tab .badge { margin-left: 4px; }

.subtabs { display: flex; gap: 6px; overflow-x: auto; padding: 12px 16px 0; scrollbar-width: none; max-width: 980px; margin: 0 auto; }
.subtabs::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--field); background: var(--card); border-radius: 999px; padding: 8px 14px; min-height: 44px; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

main { padding: 12px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 980px; margin: 0 auto; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.one, .grid.two { grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; margin-bottom: var(--gap); }
.grid .card { margin: 0; min-width: 0; }
.grid > * { min-width: 0; }
main, .card { overflow-wrap: anywhere; }
.kpi .label { font-size: 13px; color: var(--ink2); }
.kpi .value { font-size: clamp(18px, 5.5vw, 22px); font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.kpi .sub { font-size: 12px; color: var(--ink2); margin-top: 2px; }
.kpi.alert { box-shadow: inset 0 0 0 2px var(--bad), var(--shadow); }
.kpi.accent { background: var(--top); color: #fff; }
.kpi.accent .label, .kpi.accent .sub { color: var(--top-ink2); }
.fcard > summary { list-style: none; cursor: pointer; }
.fcard > summary::-webkit-details-marker { display: none; }
.fcard[open] { grid-column: 1 / -1; }
.fcard .rows.fc { margin-top: 10px; }
.fcard .row { border-color: #3a322d; font-size: 14px; }
.fcard .row.sum { border-top-color: #fff; }
.click { cursor: pointer; }

.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--accent); color: #1f1a17; text-align: center; }
.badge.grey { background: var(--soft); color: var(--ink2); }
.st { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.st::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st.verified { background: var(--good-soft); color: var(--good); }
.st.mismatch { background: var(--bad-soft); color: var(--bad); }
.st.stale { background: var(--warn-soft); color: var(--warn); }
.st.computed { background: var(--soft); color: var(--ink2); }
.st.no_data { background: var(--warn-soft); color: var(--warn); }

/* списки рядків */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .l { min-width: 0; flex: 1; }
.row .l .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.row .l .d { font-size: 12px; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .l .d.wrap, .wrap { white-space: normal; overflow-wrap: anywhere; }
.chk { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--field); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.chk.done { background: var(--good); border-color: var(--good); color: #fff; }
.chk.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.chev { display: inline-block; width: 14px; color: var(--ink2); }
.row.sum { font-weight: 700; border-top: 2px solid var(--ink); }
.row.sub .t { font-weight: 400; color: var(--ink2); padding-left: 12px; }
.row.click { cursor: pointer; }
details.row-d > summary { list-style: none; cursor: pointer; }
details.row-d > summary::-webkit-details-marker { display: none; }

/* таблиці зрізів */
.scroll-x { overflow-x: auto; }
table.t { border-collapse: collapse; width: 100%; font-size: 14px; }
table.t th, table.t td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; position: sticky; left: 0; z-index: 1; background: var(--card); white-space: normal; min-width: 140px; max-width: 160px; box-shadow: 1px 0 0 var(--line); }
table.t th { font-size: 12px; color: var(--ink2); font-weight: 600; }
table.t tr.total td { font-weight: 700; border-top: 2px solid var(--ink); }
table.t td.mm { color: var(--bad); font-weight: 650; }
table.t td .was { font-size: 11px; color: var(--warn); font-weight: 400; }
.ic { display: inline-block; width: 16px; margin-right: 4px; font-size: 11px; font-weight: 700; text-align: center; border-radius: 4px; }
.ic.verified { color: var(--good); } .ic.mismatch { color: var(--bad); } .ic.stale, .ic.no_data { color: var(--warn); } .ic.computed { color: var(--ink2); }

/* форми */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 13px; color: var(--ink2); }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--field); background: var(--input); border-radius: 10px; padding: 10px 12px; min-height: 44px; }
input[type=file] { width: 100%; min-height: 44px; padding: 8px 0; }
select.invalid { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.field .hint { font-size: 12px; margin: 0; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent-btn); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 11px 16px; min-height: 44px; cursor: pointer; font-weight: 650; background: var(--soft); }
.btn.primary { background: var(--accent-btn); color: var(--accent-ink); }
.btn.dark { background: var(--ink); color: var(--bg); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns.center { justify-content: center; }
.form-grid { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }

/* швидке введення */
.fab { position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30; width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent-btn); color: #fff; font-size: 28px; line-height: 1; box-shadow: 0 6px 20px rgba(240,122,26,.45); cursor: pointer; }
.sheet-bg { position: fixed; inset: 0; background: rgba(31,26,23,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .sheet-bg { align-items: center; } .sheet { border-radius: 20px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.x { border: 0; background: var(--soft); width: 44px; height: 44px; border-radius: 10px; cursor: pointer; font-size: 20px; }

.notice { border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: var(--gap); }
.notice.bad { background: var(--bad-soft); color: var(--notice-bad); }
.notice.warn { background: var(--warn-soft); color: var(--notice-warn); }
.notice.good { background: var(--good-soft); color: var(--notice-good); }
.notice.info { background: var(--accent-soft); color: var(--notice-info); }
.notice.click { cursor: pointer; }
/* повідомлення — угорі, під шапкою: не перекривають кнопки дій унизу */
#toasts { position: fixed; top: calc(108px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 60; width: min(560px, 92vw); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); color: #fff; }
.toast .tx { border: 0; background: rgba(255,255,255,.2); color: inherit; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px; flex: 0 0 auto; }

.chart svg { width: 100%; height: auto; max-height: 260px; display: block; }
.chart .ax { font-size: 11px; fill: var(--ink2); }
.chart .grid { stroke: var(--line); }
.chart .zero { stroke: var(--bad); stroke-dasharray: 4 4; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .pt { fill: var(--accent); }
.chart .pt.bad { fill: var(--bad); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink2); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.legend .acc { background: var(--accent); }
.legend .res { background: var(--bad); }

.auth { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; }
.auth .logo { width: 48px; height: 48px; margin-bottom: 10px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--soft); padding: 8px 10px; border-radius: 8px; word-break: break-all; font-size: 15px; letter-spacing: .04em; }
.empty { text-align: center; padding: 28px 12px; color: var(--ink2); }
.pill-amt { font-weight: 650; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

.w100 { width: 100%; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.mb12 { margin-bottom: 12px; }
.ar { text-align: right; }
.pctcol { width: 52px; text-align: right; }
.sumtoggle { cursor: pointer; padding: 6px 0; }
.hint { font-size: 13px; margin: -4px 0 10px; }

.calday { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }
.calday:first-of-type { border-top: 0; }
.bl-row { align-items: end; }
.row-d > summary { list-style: none; cursor: pointer; }
.row-d > summary::-webkit-details-marker { display: none; }
