/* Клиентская часть: чат-аналитик, оформление «ответ-дашборд».
   Прохладный светлый фон, ответы — белые карточки с цветными плитками показателей,
   акцент — тёмно-бирюзовый; рост — зелёный, падение — терракотовый. */
:root {
  --bg: #f4f6f8; --surface: #ffffff; --fg: #1b2228; --muted: #61707b; --faint: #9aa5ad; --line: #dde3e7;
  --accent: #0f6e56; --accent-strong: #04342c; --accent-soft: #e1f5ee; --accent-mid: #9fe1cb;
  --user: #1b2228;
  --up: #3b6d11; --up-soft: #eaf3de; --up-strong: #173404;
  --down: #993c1d; --down-soft: #faece7; --down-strong: #4a1b0c;
  --neutral-soft: #f1efe8; --neutral: #5f5e5a; --neutral-strong: #2c2c2a;
  --err: #a32d2d;
  --chart: #1d9e75; --chart-2: #b4b2a9;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* атрибут hidden сильнее display: flex у блоков (анкета, панели) */
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.55 var(--font); display: flex; flex-direction: column; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 10px; padding: 8px 16px; }
button.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
button.ghost:hover { border-color: var(--faint); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* шапка */
.bar { display: flex; align-items: center; gap: 12px; padding: 10px max(16px, 3vw); background: var(--surface);
       border-bottom: 1px solid var(--line); }
.avatar { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; flex: none;
          display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.who { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.25; }
.tenant { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 8px; }
.actions form { margin: 0; }
.actions button { padding: 6px 12px; font-size: 14px; }

/* лента */
.chat { flex: 1; overflow-y: auto; padding: 20px max(16px, 3vw) 12px; }
.chat > * { max-width: 920px; margin-left: auto; margin-right: auto; }
.intro { padding: 12px 0 4px; }
.intro h1 { font-size: 24px; font-weight: 600; margin: 8px 0 4px; }
.intro .chips { margin-top: 16px; }

.msg { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.q { align-self: flex-end; background: var(--user); color: #fff; padding: 9px 14px; border-radius: 16px 16px 4px 16px;
     max-width: 80%; white-space: pre-wrap; display: flex; flex-direction: column; }
.a { background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 16px 18px;
     display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.a .text p { margin: 0 0 6px; } .a .text p:last-child { margin-bottom: 0; }
.a .text ul { margin: 4px 0; padding-left: 20px; }
.a.offtopic .text, .a.failed .text { color: var(--muted); }
.a.pending { flex-direction: row; }
.a.pending .text { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.dots { display: inline-flex; gap: 4px; } .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.phrase { transition: opacity .18s ease; }
.phrase.swap { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .7; } .phrase { transition: none; } .phrase.swap { opacity: 1; } }

/* блоки ответа: плитки, таблица, график */
.block { min-width: 0; }
.block h3 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 8px; text-transform: none; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { border-radius: 12px; padding: 10px 14px; background: var(--neutral-soft); color: var(--neutral-strong); min-width: 0; }
.kpi .k { font-size: 12px; color: var(--neutral); }
.kpi .v { font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.main { background: var(--accent-soft); color: var(--accent-strong); } .kpi.main .k { color: var(--accent); }
.kpi.up { background: var(--up-soft); color: var(--up-strong); } .kpi.up .k { color: var(--up); }
.kpi.down { background: var(--down-soft); color: var(--down-strong); } .kpi.down .k { color: var(--down); }
.tbl { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
td.num, th.num { text-align: right; }
td.pos { color: var(--up); } td.neg { color: var(--down); }
tfoot td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: none; background: #fafbfc; }
.basis { font-size: 12px; color: var(--faint); margin-top: 6px; }
.chart { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 4px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .val { fill: var(--fg); font-weight: 600; }

/* быстрые вопросы */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
        text-align: left; font-size: 14px; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.quick { padding: 8px max(16px, 3vw) 0; }
.quick .chips { max-width: 920px; margin: 0 auto; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
.quick .chips::-webkit-scrollbar { display: none; }
.quick .chip { flex: none; white-space: nowrap; }

/* поле ввода */
.composer { display: flex; gap: 10px; align-items: flex-end; padding: 10px max(16px, 3vw) 14px; background: var(--surface); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; max-height: 160px; background: #fff; line-height: 1.45; overflow-y: hidden; }
.composer textarea:focus { border-color: var(--accent-mid); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.composer .send { width: 44px; height: 44px; padding: 0; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: none; }
.composer .send svg { width: 20px; height: 20px; }
@media (min-width: 960px) {
  .composer, .quick { padding-left: calc((100% - 920px) / 2); padding-right: calc((100% - 920px) / 2); }
}
@media (max-width: 560px) {
  .actions .label-long { display: none; }
  .a { padding: 14px; }
  .kpi .v { font-size: 18px; }
  .q { max-width: 88%; }
}

/* время сообщения: мелко, бледно, в правом нижнем углу пузыря */
.ts { display: block; align-self: flex-end; text-align: right; font-size: 11px; line-height: 1; color: var(--faint); margin-top: -6px; font-variant-numeric: tabular-nums; }
.q .ts { color: #fff; opacity: .55; margin-top: 4px; }

/* вход */
.login-page { align-items: center; justify-content: center; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(380px, calc(100% - 32px)); }
.login-card .logo { font-size: 20px; font-weight: 600; display: flex; align-items: center; gap: 12px; line-height: 1.2; }
.login-card .logo small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.err { color: var(--err); }

/* правила клиента */
.badge { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; margin-left: 6px; padding: 0 5px; border-radius: 9px;
         background: #ef9f27; color: #412402; font-size: 11px; font-weight: 600; text-align: center; vertical-align: 1px; }
.rules-line { font-size: 12px; color: var(--muted); }
.rules-line a { color: var(--accent); }
.clarify, .proposal, .sq { background: #faeeda; color: #633806; border-radius: 12px; padding: 12px 14px; }
.proposal { background: var(--accent-soft); color: var(--accent-strong); }
.clarify p, .proposal p, .sq p { margin: 0 0 8px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { background: #fff; color: var(--fg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-size: 14px; }
.opt:hover { border-color: var(--accent); color: var(--accent); }
.opt.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.saved { font-size: 13px; color: var(--accent); }
.survey { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; margin: 8px auto 16px; display: flex; flex-direction: column; gap: 10px; }
.survey h2 { font-size: 17px; margin: 0; }
.survey-foot { display: flex; justify-content: flex-end; }
.overlay { position: fixed; inset: 0; background: rgba(27, 34, 40, .35); display: flex; justify-content: flex-end; z-index: 20; }
.overlay[hidden] { display: none; }
.rules-panel { background: var(--surface); width: min(460px, 100%); height: 100%; overflow-y: auto; padding: 18px 20px; box-shadow: -8px 0 24px rgba(0,0,0,.08); }
.rp-head { display: flex; align-items: center; justify-content: space-between; }
.rp-head h2 { font-size: 18px; margin: 0; }
.rp-head button { padding: 4px 10px; }
.rules-panel h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 0 8px; }
.rules-panel .sq { margin-bottom: 8px; }
.rule { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.rule.off .rule-title { color: var(--muted); text-decoration: line-through; }
.rule-main { flex: 1; min-width: 0; }
.rule-act { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.rule-act select { font: inherit; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; max-width: 170px; }
button.link { background: none; border: none; color: var(--accent); padding: 0; font-size: 13px; }
button.link.danger { color: var(--err); }
.lock { font-size: 13px; }
.add-rule { display: flex; gap: 8px; align-items: flex-end; }
.add-rule textarea { flex: 1; resize: vertical; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
#rule-proposal { margin-top: 10px; }
.badge[hidden] { display: none; }

/* переключатель «Чат / Дашборд» */
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 2px; flex: none; }
.seg button { background: transparent; border: none; color: var(--muted); border-radius: 8px; padding: 5px 14px; font-size: 14px; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--accent-strong); box-shadow: 0 0 0 1px var(--line); font-weight: 600; }
body.view-dash #new-chat, body.view-dash .composer, body.view-dash .quick, body.view-dash #chat { display: none; }
body.view-dash .dash { display: block; }

/* дашборд */
.dash { flex: 1; overflow-y: auto; padding: 18px max(16px, 3vw) 28px; }
.dash[hidden] { display: none; }
.dash > * { max-width: 1100px; margin-left: auto; margin-right: auto; }
.dash-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.dash-top h1 { font-size: 20px; font-weight: 600; margin: 0 auto 0 0; }
.dash-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.dash-filters select { font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--surface); max-width: 260px; }
.d-grid { display: grid; gap: 12px; margin-bottom: 12px; }
.d-grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.d-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; min-width: 0; }
.d-card h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 10px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.d-card h2 .legend { font-weight: 400; }
.d-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.d-kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.d-kpi.main { background: var(--accent-soft); border-color: transparent; }
.d-kpi .k { font-size: 12px; color: var(--muted); }
.d-kpi.main .k { color: var(--accent); }
.d-kpi .v { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-kpi.main .v { color: var(--accent-strong); }
.delta { font-size: 12px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); } .delta.down { color: var(--down); } .delta.flat { color: var(--faint); }
.d-chart svg { width: 100%; height: auto; display: block; }
.d-chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.legend { display: inline-flex; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--chart); vertical-align: middle; margin-right: 5px; }
.legend i.prev { border-top: 2px dashed var(--chart-2); }
.legend i.sw { width: 10px; height: 10px; border: none; border-radius: 2px; }
.hm { display: grid; gap: 2px; font-size: 11px; color: var(--faint); }
.hm span { line-height: 18px; white-space: nowrap; }
.hm .c { height: 18px; border-radius: 3px; }
.hm-foot { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.hm-scale { display: inline-flex; gap: 2px; } .hm-scale b { width: 12px; height: 8px; border-radius: 2px; display: inline-block; }
.d-row { width: 100%; text-align: left; background: none; border: none; color: inherit; border-radius: 8px; padding: 6px 4px; display: block; }
.d-row:hover { background: var(--bg); }
.d-row .top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.d-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.d-row .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.d-bar { height: 6px; border-radius: 3px; background: var(--bg); margin-top: 4px; overflow: hidden; }
.d-bar > div { height: 100%; border-radius: 3px; background: var(--chart); }
.meter { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--bg); gap: 2px; margin: 10px 0 6px; }
.meter .f { background: var(--chart); } .meter .r { background: var(--accent-mid); }
.stack { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; }
.d-big { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.d-sub { font-size: 12px; color: var(--muted); }
.d-table { width: 100%; font-size: 14px; }
.d-table td, .d-table th { padding: 6px 8px; }
.d-table td:first-child { white-space: normal; overflow-wrap: anywhere; min-width: 110px; }  /* длинное название переносится, числа помещаются */
.d-table tbody tr { cursor: pointer; } .d-table tbody tr:hover td { background: var(--bg); }
.d-table .warn { color: var(--down); }
.d-foot { font-size: 12px; color: var(--faint); margin-top: 4px; display: flex; flex-direction: column; gap: 4px; }
.d-empty { font-size: 13px; color: var(--faint); padding: 8px 0; }
.d-loading { color: var(--muted); padding: 30px 0; text-align: center; }
.d-hint { font-size: 12px; color: var(--faint); margin-top: 6px; }
@media (max-width: 560px) {
  .seg button { padding: 5px 10px; }
  .who .sub { display: none; }
  .d-kpi .v { font-size: 20px; }
  .dash-filters select { max-width: 100%; flex: 1 1 140px; }
}

/* свой период и выбор нескольких ресторанов */
.d-custom { display: inline-flex; align-items: center; gap: 6px; }
.d-custom[hidden] { display: none; }
.d-custom input { font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 10px; padding: 5px 8px; background: var(--surface); }
.ms { position: relative; }
.ms[hidden] { display: none; }
.ms summary { list-style: none; cursor: pointer; font-size: 14px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 30px 6px 10px;
              background: var(--surface); max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.ms summary::-webkit-details-marker { display: none; }
.ms summary::after { content: ""; position: absolute; right: 12px; top: 50%; width: 6px; height: 6px; margin-top: -5px;
                     border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); }
.ms-pop { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--surface); border: 1px solid var(--line);
          border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .1); padding: 8px; width: min(320px, calc(100vw - 32px)); }
#d-rest-list { max-height: 300px; overflow-y: auto; }
.ms-item { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.ms-item:hover { background: var(--bg); }
.ms-item input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.ms-foot { display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.ms-foot button { padding: 6px 12px; font-size: 14px; }

/* выбор после входа: чат или дашборд */
.start { flex: 1; overflow-y: auto; padding: 8vh max(16px, 3vw) 24px; text-align: center; }
.start[hidden] { display: none; }
.start h1 { font-size: 24px; font-weight: 600; margin: 0 0 20px; }
.start-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px; max-width: 620px; margin: 0 auto 14px; }
.start-opt { background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 16px; padding: 22px 20px;
             display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; }
.start-opt:hover { border-color: var(--accent); }
.start-opt svg { width: 28px; height: 28px; color: var(--accent); margin-bottom: 6px; }
.start-opt .t { font-size: 17px; font-weight: 600; }
.start-opt .s { font-size: 13px; color: var(--muted); }
body.view-start #chat, body.view-start .dash, body.view-start .composer, body.view-start .quick,
body.view-start .seg, body.view-start #new-chat { display: none; }
@media (max-width: 560px) {
  .ms, .d-custom { flex: 1 1 100%; }
  .ms summary { max-width: none; }
  .ms-pop { left: 0; right: auto; }
  .d-custom input { flex: 1; min-width: 0; }
}

/* дашборд: склад StoreHouse, скрытие плашек */
.d-card h2 .h2t { display: inline-flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.d-hide { background: none; border: none; color: var(--faint); font-size: 16px; line-height: 1; padding: 0 2px; cursor: pointer; margin-left: auto; }
.d-hide:hover { color: var(--down); }
.d-kpis { position: relative; }
.d-pair { display: flex; flex-wrap: wrap; gap: 18px 32px; margin-bottom: 8px; }
.d-big.neg { color: var(--down); }
.d-svg { width: 100%; height: auto; display: block; margin-top: 6px; }
.d-svg text, svg.spark text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
svg.spark { width: 100%; height: auto; display: block; margin: 4px 0 8px; }
.d-card h3 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.d-row.static { cursor: default; } .d-row.static:hover { background: none; }
.quads { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 10px 16px; margin-top: 8px; }
.quad .qh { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.quad .sw, .legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; border: none; }
.qi { font-size: 13px; padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 0 20px; }
.d-ok { color: var(--accent); font-size: 14px; padding: 6px 0; }
.d-table .good { color: var(--up); }
.d-table.plain tbody tr { cursor: default; } .d-table.plain tbody tr:hover td { background: none; }
.ms-pop.right { right: 0; left: auto; }

/* дашборд: плашка, данные которой ещё считаются */
.d-wait .sk { height: 64px; border-radius: 6px; background: var(--line); opacity: .55; margin-top: 10px; animation: sk-pulse 1.4s ease-in-out infinite; }
.d-wait .sk.short { height: 14px; width: 60%; }
.d-wait .sk-v { height: 26px; width: 70%; margin-top: 6px; }
.d-wait h2 { color: var(--muted); }
@keyframes sk-pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .d-wait .sk { animation: none; } }

/* вход и пароль: сообщение «готово», ссылки под формой */
.login-card .ok { color: var(--accent); }
.login-card p.small { margin: 14px 0 0; font-size: 13px; }
.login-card a { color: var(--accent); }
/* переключатель объекта в шапке (если объектов несколько) */
.obj-switch { margin: 0; min-width: 0; }
.obj-switch select { font: inherit; font-weight: 600; color: var(--fg); background: transparent; border: 1px solid var(--line);
  border-radius: 8px; padding: 2px 6px; width: 100%; min-width: 96px; cursor: pointer; }
@media (max-width: 560px) {
  /* на телефоне шапке не хватает ширины: с переключателем объектов — вторая строка шапки целиком под него */
  .bar:has(.obj-switch) { flex-wrap: wrap; row-gap: 8px; }
  .who:has(.obj-switch) { order: 10; flex: 1 0 100%; }
}

/* экран загрузки после открытия чата (поиск неоднозначностей в данных) */
.prepare { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(2px); padding: 16px; }
.prepare[hidden] { display: none; }
.prep-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px;
  width: min(380px, 100%); box-shadow: 0 8px 30px rgba(0, 0, 0, .08); }
.prep-bar { height: 4px; border-radius: 2px; background: var(--accent-soft); overflow: hidden; position: relative; }
.prep-bar i { position: absolute; top: 0; bottom: 0; width: 35%; border-radius: 2px; background: var(--accent);
  animation: prep-run 1.3s ease-in-out infinite; }
@keyframes prep-run { from { left: -35%; } to { left: 100%; } }
.prep-card p { margin: 14px 0 0; font-size: 15px; color: var(--fg); min-height: 1.4em; }
@media (prefers-reduced-motion: reduce) { .prep-bar i { animation: none; left: 0; width: 100%; opacity: .5; } }

/* дашборд: нажимаемые элементы плашек → детализация */
button.d-kpi { text-align: left; color: var(--fg); width: 100%; display: block; }
button.d-kpi.main { color: var(--fg); }
button.d-kpi:hover { border-color: var(--accent); }
.d-kpi.main:hover { border-color: var(--accent-mid); }
.hm .c[data-d] { cursor: pointer; } .hm .c[data-d]:hover { outline: 2px solid var(--accent); outline-offset: -1px; }
.d-svg rect.hit, .d-chart rect.hit { fill: transparent; cursor: pointer; } .d-chart rect.hit:hover { fill: var(--line); fill-opacity: .45; }
.d-svg circle[data-d] { cursor: pointer; }
button.qi { display: block; width: 100%; text-align: left; background: none; border: none; border-radius: 6px; color: var(--fg); padding: 3px 4px; }
button.qi:hover, button.d-chip:hover { background: var(--bg); }
button.d-chip { background: none; border: 1px solid var(--line); border-radius: 14px; padding: 3px 10px; color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
button.d-chip .sw { margin: 0; }
.d-more { background: none; border: none; color: var(--accent); padding: 6px 0 0; font-size: 14px; }
.d-more:hover { text-decoration: underline; }
.d-hide { min-width: 32px; min-height: 32px; margin: -8px -8px -8px auto; font-size: 18px; border-radius: 8px; }

/* панель детализации: справа, на телефоне — снизу */
dialog.det { padding: 0; border: none; border-left: 1px solid var(--line); background: var(--surface); color: var(--fg);
             width: min(560px, 100vw); max-width: 100vw; height: 100%; max-height: 100%; margin: 0 0 0 auto; box-shadow: -8px 0 24px rgba(0, 0, 0, .08); }
dialog.det::backdrop { background: rgba(27, 34, 40, .35); }
.det-body { height: 100%; overflow-y: auto; padding: 0 18px 20px; }
.det-head { position: sticky; top: 0; z-index: 1; background: var(--surface); display: flex; align-items: flex-start; gap: 8px; padding: 14px 0 10px; }
.det-head button { padding: 4px 10px; flex: none; }
.det-t { flex: 1; min-width: 0; }
.det-t h2 { font-size: 17px; font-weight: 600; margin: 0; overflow-wrap: anywhere; }
.det .d-kpis { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.det .d-kpi .v { font-size: 19px; }
.det-sec h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 0 6px; }
.det-more summary { font-size: 13px; color: var(--accent); cursor: pointer; margin: 4px 0; }
.det-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
.det-foot .d-hint { margin: 0; }

@media (max-width: 560px) {
  /* телефон: шапка уезжает вместе со страницей, фильтры — в две колонки */
  body.view-dash { height: auto; min-height: 100%; }
  body.view-dash .dash { overflow: visible; }
  .dash-filters { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .dash-filters select, .dash-filters .ms { max-width: none; min-width: 0; }
  .dash-filters .d-custom { grid-column: 1 / -1; }
  .dash-top h1 { flex: 1 1 100%; }
  .d-table th.dopt, .d-table td.dopt { display: none; }
  .bar .avatar { display: none; }  /* место для «Чат / Дашборд» и кнопок в одной строке */
  .space-switch .label-long { display: none; }
  .d-table td, .d-table th { padding: 6px 6px; }
  dialog.det { width: 100%; height: auto; max-height: 88vh; margin: auto 0 0; border-left: none; border-radius: 16px 16px 0 0; }
  .det-body { max-height: 88vh; padding: 0 14px 18px; }
}
.space-switch { font-size: 13px; font-weight: 500; padding: 3px 10px; border: 1px solid var(--accent); border-radius: 999px; white-space: nowrap; color: var(--accent); text-decoration: none; }
.space-switch:hover { background: var(--accent-soft); }
