:root {
  --side: #0f1b33; --side-2: #18284a; --side-text: #c4cee3; --side-muted: #7b89a8;
  --bg: #e6ebf3; --card: #ffffff; --text: #17202e; --muted: #5d6b82;
  --line: #c9d2e0; --line-strong: #aebad0;
  --accent: #2456e6; --accent-soft: #e3ebff; --accent-text: #ffffff;
  --good: #0f7a4a; --good-soft: #dcf5e8; --bad: #bd2a2a; --bad-soft: #fde4e2; --warn-soft: #fff1d6;
  --thead: #1d2b4a; --thead-text: #ffffff; --zebra: #f3f6fb; --hover: #dde8ff;
  --shadow: 0 1px 2px rgba(15, 27, 51, .08), 0 4px 14px rgba(15, 27, 51, .07);
}
@media (prefers-color-scheme: dark) {
  :root {
    --side: #0a1020; --side-2: #141d33; --side-text: #c4cee3; --side-muted: #6f7d9c;
    --bg: #0e1422; --card: #172033; --text: #e8edf6; --muted: #96a3bb;
    --line: #2c3a56; --line-strong: #3b4c70;
    --accent: #5b8cff; --accent-soft: #1d2d57; --accent-text: #08101f;
    --good: #4cc38a; --good-soft: #14352a; --bad: #ff8078; --bad-soft: #43211f; --warn-soft: #3a2f1c;
    --thead: #0b1222; --thead-text: #dfe7f6; --zebra: #1b2539; --hover: #22335c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); margin: 8px 0 0; min-height: 1em; font-weight: 500; }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--side) 0%, #1c3a8a 100%); }
.login-card { width: 100%; max-width: 380px; padding: 30px 28px; display: grid; gap: 14px; background: var(--card); border-radius: 16px; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); text-align: center; }
.login-card h1 { margin: 0; font-size: 20px; letter-spacing: .08em; }
.login-card .sub { margin: -8px 0 4px; color: var(--muted); }
.login-card label { text-align: left; }
.logo { width: 52px; height: 52px; margin: 0 auto; border-radius: 14px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 800; font-size: 20px; letter-spacing: .02em; }
.logo.sm { width: 36px; height: 36px; margin: 0; border-radius: 10px; font-size: 14px; flex: none; }
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
input[type=text], input[type=password], input[type=search], input:not([type]) {
  font: inherit; color: var(--text); background: var(--card); border: 1.5px solid var(--line-strong); border-radius: 9px; padding: 10px 12px;
}
input:focus-visible, button:focus-visible { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.btn { font: inherit; font-weight: 600; border: 1.5px solid var(--line-strong); background: var(--card); color: var(--text); border-radius: 9px; padding: 9px 16px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.wide { width: 100%; padding: 11px; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--side-text); border-color: var(--side-muted); }
.btn.ghost:hover { background: var(--side-2); }

/* каркас */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 800; letter-spacing: .08em; font-size: 13px; line-height: 1.2; color: #fff; }
.side-nav { display: grid; gap: 3px; align-content: start; flex: 1; overflow: auto; }
.grp { text-transform: uppercase; font-size: 11px; letter-spacing: .1em; color: var(--side-muted); padding: 14px 10px 6px; }
.tab { font: inherit; display: flex; align-items: center; gap: 10px; text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 9px; color: var(--side-text); cursor: pointer; }
.tab i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
.tab:hover:not(.off) { background: var(--side-2); }
.tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.tab.off { opacity: .45; cursor: default; }
.side-foot { border-top: 1px solid var(--side-2); padding-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; color: #fff; font-weight: 600; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 13px; flex: none; }

.content { padding: 22px 26px 40px; min-width: 0; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.pagehead h2 { margin: 0; font-size: 24px; }

.panel { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 16px; }

/* показатели */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1.5px solid var(--line); border-left: 6px solid var(--accent); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 16px; }
.kpi:nth-child(2) { border-left-color: var(--good); }
.kpi:nth-child(3) { border-left-color: #8a5cf6; }
.kpi.bad { border-left-color: var(--bad); background: var(--bad-soft); }
.kpi .v { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi.bad .v { color: var(--bad); }

.bars { display: grid; gap: 7px; }
.bars .title { font-weight: 700; margin-bottom: 4px; }
.bar-row { display: grid; grid-template-columns: 190px 1fr 80px; gap: 12px; align-items: center; font-size: 13px; }
.bar { height: 14px; background: var(--accent-soft); border-radius: 7px; overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #7aa2ff); }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }

/* таблица */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 10px; }
.search { flex: 1 1 280px; max-width: 460px; }
.chk { display: flex; flex-direction: row; align-items: center; gap: 7px; color: var(--text); font-size: 13px; }
.chk input { width: 17px; height: 17px; accent-color: var(--accent); }
.right { margin-left: auto; }
.note { background: var(--warn-soft); border-radius: 9px; padding: 8px 12px; color: var(--muted); font-size: 12px; margin: 0 0 10px; max-height: 4.2em; overflow: auto; }
.note:empty { display: none; }

.tablewrap { overflow: auto; border: 1.5px solid var(--line-strong); border-radius: 10px; max-height: calc(100vh - 330px); min-height: 220px; background: var(--card); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 12px; white-space: nowrap; text-align: left; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
th:last-child, td:last-child { border-right: 0; }
th { position: sticky; top: 0; z-index: 2; background: var(--thead); color: var(--thead-text); font-size: 12px; font-weight: 600; cursor: pointer; user-select: none; border-right-color: rgba(255, 255, 255, .14); border-bottom: 2px solid var(--accent); }
th:hover { filter: brightness(1.25); }
th.sorted::after { content: " ▲"; font-size: 10px; } th.sorted.desc::after { content: " ▼"; }
td.num, th.num { text-align: right; }
tbody tr:nth-child(even) td { background: var(--zebra); }
tbody tr:hover td { background: var(--hover); }
td.zero { color: var(--muted); opacity: .6; }
td.pos { background: var(--good-soft) !important; color: var(--good); font-weight: 600; }
td.neg { background: var(--bad-soft) !important; color: var(--bad); font-weight: 700; }
td.tot { font-weight: 800; border-left: 2px solid var(--line-strong); }
td.key { font-weight: 600; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 10px; }
  .side-nav { display: flex; flex-wrap: wrap; } .grp { display: none; } .tab.off { display: none; }
  .side-foot { border: 0; padding: 6px 4px 0; }
  .content { padding: 14px; }
  .bar-row { grid-template-columns: 110px 1fr 60px; }
  .tablewrap { max-height: none; }
}

/* --- v3: логотип, кликабельные показатели, фото, предупреждения --- */
.brand-img { display: block; width: 100%; height: auto; border-radius: 10px; }
.login-card .brand-img { width: 240px; margin: 0 auto; }
.side-brand { padding: 4px 4px 14px; }
button.kpi { font: inherit; text-align: left; cursor: pointer; width: 100%; color: var(--text); transition: transform .08s, box-shadow .08s; }
button.kpi:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(15, 27, 51, .18); }
button.kpi.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.kpi, .kpi:nth-child(2), .kpi:nth-child(3) { border-left-color: var(--accent); }
.kpi.good { border-left-color: var(--good); } .kpi.violet { border-left-color: #8a5cf6; } .kpi.ok { border-left-color: var(--good); }
.kpi.bad { border-left-color: var(--bad); background: var(--bad-soft); }
.warnbox { background: var(--warn-soft); border: 1.5px solid #e0a53a; color: var(--text); border-radius: 9px; padding: 9px 13px; margin: 0 0 10px; font-weight: 500; }
td.photo, th.photo { width: 52px; padding: 3px 6px; text-align: center; }
td.photo img { display: block; width: 38px; height: 50px; object-fit: cover; border-radius: 5px; border: 1px solid var(--line); margin: auto; background: var(--zebra); }
td.photo img:hover { position: relative; transform: scale(3.2); transform-origin: left center; z-index: 5; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
td.warnc { background: var(--warn-soft) !important; color: #a35f00; font-weight: 700; }
.bar-row .closed { color: #a35f00; font-weight: 600; }

/* --- v4: «Закрытие ФФ» --- */
.ffcard { padding: 16px 18px; }
.ffhead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ffhead h3 { margin: 0; font-size: 18px; }
.badge { padding: 3px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.b-ok { background: var(--good-soft); color: var(--good); border: 1px solid var(--good); }
.b-warn { background: var(--warn-soft); color: #a35f00; border: 1px solid #e0a53a; }
.b-info { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); }
.verdict { font-weight: 600; margin: 8px 0 4px; }
.small-note { font-size: 12px; margin: 2px 0 6px; }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 6px 18px; margin: 10px 0; }
.chk-row { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--zebra); }
.chk-row .mark { font-weight: 800; }
.chk-row.ok .mark { color: var(--good); } .chk-row.bad { background: var(--bad-soft); border-color: var(--bad); } .chk-row.bad .mark { color: var(--bad); }
.chain.ok { border-left: 6px solid var(--good); } .chain.warn { border-left: 6px solid #e0a53a; background: var(--warn-soft); }
.chain .title { font-weight: 700; margin-bottom: 4px; }
.tablewrap.small { max-height: 340px; min-height: 0; }
td.trail { white-space: normal; min-width: 360px; font-size: 12px; color: var(--muted); }

/* подсказки «?» */
.q { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; margin-left: auto; border-radius: 50%; border: 1.5px solid currentColor; font: 700 11px/1 inherit; opacity: .6; background: none; color: inherit; padding: 0; cursor: help; flex: none; }
.tab:hover .q, .q:hover { opacity: 1; }
.q.big { margin-left: 8px; width: 22px; height: 22px; font-size: 13px; vertical-align: middle; color: var(--muted, #667); }
.tip { position: fixed; z-index: 50; max-width: 340px; background: #1b2438; color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.28); font-size: 13.5px; line-height: 1.45; pointer-events: none; }
.tip b { display: block; margin-bottom: 4px; font-size: 14px; }
.tip.hidden { display: none; }

/* сворачиваемая группа меню */
.grp-toggle { font: inherit; width: 100%; text-align: left; background: none; border: 0; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 9px; color: inherit; }
.grp-toggle:hover { background: var(--side-2); }
.grp-toggle .chev { width: 14px; font-size: 12px; }
.grp-body { display: flex; flex-direction: column; gap: 2px; padding-left: 10px; }
.grp-body.collapsed { display: none; }
@media (max-width: 800px) { .grp-toggle { display: none; } .grp-body { display: flex !important; flex-direction: row; flex-wrap: wrap; padding-left: 0; } }

/* Аналитика */
.analytics { padding: 22px 26px; }
.analytics .gs-link { float: right; font-size: 13px; color: var(--accent); text-decoration: none; }
.an-title { margin: 0 0 6px; font-size: 20px; }
.an-h { margin: 22px 0 8px; font-size: 16px; padding-bottom: 5px; border-bottom: 2px solid var(--line-strong); }
.an-p { margin: 6px 0; line-height: 1.5; max-width: 1100px; }
.an-wrap { max-height: none; min-height: 0; margin: 8px 0 4px; }
.an-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.an-table th, .an-table td { padding: 7px 10px; border-bottom: 1px solid var(--line, #e3e6ee); white-space: pre-line; vertical-align: middle; }
.an-table th { background: #1b2438; color: #fff; text-align: center; font-weight: 600; position: static; }
.an-table td.num { text-align: right; }
.an-table td.key { font-weight: 600; text-align: left; }
.an-table td.photo-c { text-align: center; }
.chart-ph { margin: 10px 0; padding: 14px 16px; border: 1.5px dashed var(--line-strong); border-radius: 10px; color: #667; font-size: 13px; }

.chart-row { display: flex; flex-wrap: wrap; gap: 16px; margin: 10px 0 6px; }
.chart-box { flex: 1 1 460px; max-width: 700px; border: 1.5px solid var(--line-strong); border-radius: 10px; padding: 8px; background: #fff; }
.an-table td a { color: #2a52be; }

/* РНП «как в таблице» */
.rnp { margin-top: 4px; }
.rnp .gs-link { display: inline-block; margin-bottom: 8px; font-size: 13px; color: var(--accent); text-decoration: none; }
.rg-wrap { overflow: auto; border: 1.5px solid var(--line-strong); border-radius: 10px; background: #fff; max-height: calc(100vh - 150px); }
.rg { border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 12.5px; }
.rg td { padding: 2px 6px; border-right: 1px solid #e3e6ee; border-bottom: 1px solid #e3e6ee; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; vertical-align: middle; line-height: 1.25; }
.rg td.fz-edge { border-right: 2px solid #9aa3b8; }
.rg td a { color: inherit; text-decoration: underline; }


/* Шрифты (локально, без внешних запросов) */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400 700; font-display: swap; src: url('/fonts/inter-cyrillic.woff2') format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400 700; font-display: swap; src: url('/fonts/inter-latin.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 600 800; font-display: swap; src: url('/fonts/manrope-cyrillic.woff2') format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 600 800; font-display: swap; src: url('/fonts/manrope-latin.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
body, button, input, select, textarea, .rg { font-family: 'Inter', 'Segoe UI', system-ui, sans-serif; font-feature-settings: 'tnum' 1, 'cv11' 1; }
h2, h3, h4, .kpi .v, .grp-toggle, .login-card h1, .pagehead h2 { font-family: 'Manrope', 'Inter', system-ui, sans-serif; letter-spacing: -.01em; }
.pagehead h2 { font-weight: 800; }

/* Меню: у каждой группы свой цвет, чтобы раскрытые блоки не сливались */
#grpUchet, #grpUchetBody { --gc: #4f8cff; }
#grpAnal, #grpAnalBody { --gc: #a78bfa; }
#grpRnpWb, #grpRnpWbBody { --gc: #e879f9; }
#grpRnpOz, #grpRnpOzBody { --gc: #2dd4bf; }
.grp-toggle { margin-top: 8px; background: color-mix(in srgb, var(--gc) 16%, transparent); border-left: 3px solid var(--gc); color: #fff; font-weight: 700; letter-spacing: .06em; }
.grp-toggle:hover { background: color-mix(in srgb, var(--gc) 28%, transparent); }
.grp-toggle .chev { color: var(--gc); }
.grp-body { margin: 2px 0 6px 6px; padding: 4px 0 4px 8px; border-left: 2px solid color-mix(in srgb, var(--gc) 60%, transparent); background: color-mix(in srgb, var(--gc) 6%, transparent); border-radius: 0 9px 9px 0; }
.grp-body .tab:hover:not(.off) { background: color-mix(in srgb, var(--gc) 22%, transparent); }
.grp-body .tab.active { background: var(--gc); color: #0d1424; font-weight: 700; }
.grp-body .tab.active .q { color: #0d1424; }

/* РНП: заметная сетка и фото */
.rg td { border-right: 1px solid #c3cada; border-bottom: 1px solid #c3cada; }
.rg td.has-img { text-align: center; padding: 3px; }
.rg-img { display: block; margin: 0 auto; object-fit: contain; border-radius: 4px; }
.rg td.fz-edge { border-right: 2px solid #7d88a6; }

#grpSro, #grpSroBody { --gc: #fbbf24; }
#grpBal, #grpBalBody { --gc: #4ade80; }
#grpUnit, #grpUnitBody { --gc: #fb7185; }

/* сворачиваемое левое меню */
.side-toggle { position: fixed; z-index: 60; top: 14px; left: 226px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--accent, #2f6bff); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; padding: 0 0 2px; transition: left .15s; }
.side-toggle:hover { filter: brightness(1.15); }
.layout.side-collapsed { grid-template-columns: 0 1fr; }
.layout.side-collapsed .side { display: none; }
.layout.side-collapsed ~ .side-toggle, .layout.side-collapsed .side-toggle { left: 8px; }
.layout.hidden ~ .side-toggle { display: none; }
#app.hidden .side-toggle { display: none; }

/* кнопки группировок «+/−» в РНП/таблицах */
.rg td.gut { background: #eef1f7; border-right: 1px solid #c3cada; border-bottom: 1px solid #dfe3ee; padding: 0; text-align: left; overflow: visible; }
.gbtn { width: 14px; height: 14px; line-height: 11px; padding: 0; border: 1px solid #7d88a6; background: #fff; color: #334; font: 700 11px/12px 'Inter', sans-serif; border-radius: 3px; cursor: pointer; margin: 1px 1px; vertical-align: middle; }
.gbtn:hover { background: #dbe5ff; border-color: #2f6bff; }

/* группы: кнопки внутри фиксированных «слотов» по уровням вложенности */
.rg td.gut { position: relative; overflow: hidden; box-sizing: border-box; }
.rg .gbtn { position: absolute; margin: 0; z-index: 3; }

/* меню свёрнуто: контент занимает всю ширину, кнопка не наезжает на заголовок */
.layout.side-collapsed { grid-template-columns: 1fr !important; }
.layout.side-collapsed .content { padding-left: 54px; }
@media (max-width: 800px) { .side-toggle { display: none; } .layout.side-collapsed .side { display: flex; } .layout.side-collapsed .content { padding-left: 14px; } }

.rg td.gut .gbtn:not([style*="top"]) { top: 50%; margin-top: -7px; }

.rg td.editable { cursor: cell; box-shadow: inset 0 0 0 1px #2f6bff55; background-image: linear-gradient(#fff9d6,#fff9d6); }
.rg td.editable:hover { box-shadow: inset 0 0 0 2px #2f6bff; }
.rg .cell-input { width: 100%; box-sizing: border-box; font: inherit; padding: 1px 3px; border: 2px solid #2f6bff; border-radius: 3px; text-align: right; background: #fff; color: #111; }
