:root {
  --bg: #f6f3ec; --panel: #ffffff; --ink: #24221f; --muted: #6f6a61; --line: #e3ddd1; --soft: #efe9dd;
  --accent: #2f4b6e; --accent-soft: #dfe7f1; --good: #2f7a4b; --bad: #b3362d; --warn: #9a6a00; --warn-soft: #fbf0d4;
  --s1: #2f4b6e; --s2: #c2772f; --s3: #5c8a5a; --s4: #8b5a8c; --s5: #b3362d; --s6: #6f6a61;
  --radius: 8px; font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; line-height: 1.4; }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
button, select, input, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button:disabled { opacity: .5; cursor: not-allowed; }
select, input, textarea { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 8px; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
.app { display: grid; grid-template-columns: 190px 1fr; min-height: 100vh; }
nav.side { background: #24221f; color: #e9e4d8; padding: 14px 0; position: sticky; top: 0; height: 100vh; overflow: auto; }
nav.side .brand { padding: 0 16px 14px; font-weight: 600; font-size: 15px; color: #fff; } 
nav.side a.brand:hover { background: none; }
body.noperiod .topbar .per { display: none; }
nav.side .brand small { display: block; font-weight: 400; color: #a9a294; font-size: 12px; }
nav.side a { display: block; padding: 8px 16px; color: #e9e4d8; }
nav.side a:hover { background: #34312c; text-decoration: none; }
nav.side a.on { background: #f6f3ec; color: var(--ink); font-weight: 600; }
nav.side .sep { border-top: 1px solid #3c3934; margin: 10px 0; }
nav.side .me { padding: 8px 16px; color: #a9a294; font-size: 12px; }
main { padding: 0 22px 40px; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0 8px; display: flex; flex-wrap: wrap;
  gap: 8px 14px; align-items: center; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.topbar .grow { flex: 1; }
.topbar label { color: var(--muted); font-size: 12px; margin-right: 4px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; background: var(--soft);
  font-size: 12px; color: var(--muted); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--good); } .pill.warn .dot { background: var(--warn); } .pill.bad .dot { background: var(--bad); }
.pill.bad { background: #f6dcd9; color: var(--bad); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.testbanner { display: none; background: repeating-linear-gradient(45deg, #f7d64a, #f7d64a 14px, #f3c623 14px, #f3c623 28px);
  color: #2a2300; font-weight: 700; padding: 6px 22px; text-align: center; letter-spacing: .02em; }
body.test .testbanner { display: block; }
h1 { font-size: 20px; margin: 4px 0 12px; font-weight: 600; }
h2 { font-size: 15px; margin: 22px 0 8px; font-weight: 600; }
h3 { font-size: 13px; margin: 14px 0 6px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; position: relative; }
.kpi .t { color: var(--muted); font-size: 12px; padding-right: 18px; }
.kpi .v { font-size: 22px; font-weight: 600; margin: 2px 0; white-space: nowrap; }
.kpi .d { font-size: 12px; color: var(--muted); }
.kpi[data-go] { cursor: pointer; } .kpi[data-go]:hover { border-color: var(--accent); }
.q { position: absolute; top: 8px; right: 9px; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line);
  color: var(--muted); font-size: 11px; display: inline-flex; align-items: center; justify-content: center; cursor: help; background: #fff; }
.qi { display: inline-flex; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--line); color: var(--muted);
  font-size: 10px; align-items: center; justify-content: center; cursor: help; margin-left: 4px; vertical-align: 1px; }
.up { color: var(--good); } .down { color: var(--bad); }
.na { color: var(--muted); border: 1px dashed #c9c1b2; border-radius: 4px; padding: 0 5px; font-size: 12px; font-weight: 400; white-space: nowrap; }
.zero { color: var(--muted); }
.err { background: #f6dcd9; border: 1px solid #e7b3ad; color: #7b2019; border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.warnbox { background: var(--warn-soft); border: 1px solid #ecd38f; color: #5f4300; border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.info { background: var(--accent-soft); border: 1px solid #c3d1e3; border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.loading { color: var(--muted); padding: 30px 0; }
table.t { border-collapse: collapse; width: 100%; background: var(--panel); font-size: 13px; }
table.t th, table.t td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; user-select: none; background: #fbfaf6;
  position: sticky; top: 0; }
table.t th.s { cursor: pointer; } table.t th.s:hover { color: var(--ink); }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.t tr[data-go] { cursor: pointer; } table.t tr[data-go]:hover td { background: #f4f1e8; }
.tablewrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: 70vh; background: var(--panel); }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0 8px; }
.tools input[type=search] { min-width: 260px; }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 11px; background: var(--soft); color: var(--muted);
  margin-right: 3px; white-space: nowrap; }
.tag.bad { background: #f6dcd9; color: var(--bad); } .tag.good { background: #dcefe2; color: var(--good); }
.tag.warn { background: var(--warn-soft); color: var(--warn); } .tag.blue { background: var(--accent-soft); color: var(--accent); }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft);
  color: var(--accent); font-size: 12px; }
.chip a { color: var(--accent); font-weight: 700; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs a { padding: 7px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { font-size: 11px; fill: var(--muted); }
svg.chart .grid line { stroke: var(--line); }
svg.chart .hov { fill: transparent; cursor: pointer; } svg.chart .hov:hover { fill: rgba(47, 75, 110, .07); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin: 4px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bars .row { display: grid; grid-template-columns: 180px 1fr 130px; gap: 8px; align-items: center; padding: 3px 0; }
.bars .row[data-go] { cursor: pointer; } .bars .row[data-go]:hover .lbl { color: var(--accent); text-decoration: underline; }
.bars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .bar { height: 16px; background: var(--soft); border-radius: 3px; position: relative; overflow: hidden; }
.bars .bar span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--s1); border-radius: 3px; }
.bars .bar span.prev { background: transparent; border-right: 2px solid var(--s2); }
.bars .val { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; }
#tip { position: fixed; z-index: 50; pointer-events: none; background: #24221f; color: #f6f3ec; padding: 6px 9px; border-radius: 6px;
  font-size: 12px; max-width: 360px; display: none; white-space: pre-line; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.tl { position: relative; margin: 4px 0 4px 8px; border-left: 2px solid var(--line); padding-left: 14px; }
.tl .it { position: relative; padding: 4px 0 8px; }
.tl .it::before { content: ""; position: absolute; left: -20px; top: 9px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--accent); }
.tl .it.bad::before { border-color: var(--bad); background: var(--bad); }
.tl .it.warn::before { border-color: var(--warn); }
.tl .it.gap { color: var(--muted); font-style: italic; }
.tl .it.gap::before { border-style: dashed; border-color: var(--muted); }
.tl .ts { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-right: 8px; }
.chat { max-height: 480px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: #fbfaf6; }
.msg { margin: 6px 0; max-width: 78%; padding: 6px 10px; border-radius: 8px; background: #fff; border: 1px solid var(--line);
  white-space: pre-wrap; word-wrap: break-word; }
.msg.client { margin-left: auto; background: var(--accent-soft); border-color: #c3d1e3; }
.msg.hidden { background: transparent; border-style: dashed; color: var(--muted); font-style: italic; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
dl.kv { display: grid; grid-template-columns: 190px 1fr; gap: 5px 12px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; }
.result { margin-top: 8px; padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.result.готово { background: #dcefe2; color: #1d5232; } .result.отказ { background: var(--warn-soft); color: #5f4300; }
.result.ошибка { background: #f6dcd9; color: #7b2019; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; align-items: end; }
.form label { display: block; font-size: 12px; color: var(--muted); }
.form label input, .form label select { width: 100%; margin-top: 2px; }
.login { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 100; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 26px 28px; width: 330px; }
.login input { width: 100%; margin: 4px 0 12px; padding: 8px 10px; }
.login button { width: 100%; padding: 8px; }
.modal { position: fixed; inset: 0; background: rgba(36, 34, 31, .45); display: flex; align-items: center; justify-content: center; z-index: 60; }
.modal .box { background: var(--panel); border-radius: 10px; padding: 18px 20px; width: 520px; max-width: calc(100vw - 40px); max-height: 85vh; overflow: auto; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.flow .st { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; min-width: 120px; }
.flow .arrow { color: var(--muted); }
@media (max-width: 1100px) { .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) { .app { grid-template-columns: 1fr; } nav.side { position: static; height: auto; display: flex; flex-wrap: wrap; }
  .g2, .g3 { grid-template-columns: 1fr; } .bars .row { grid-template-columns: 120px 1fr 100px; } }
