/* Конструктор клієнта: чат збоку, решта — полотно, яке будує ШІ. Основа — жетони сторінки власника (cab/admin.css).
   Групування — відступами й лініями, без карток; колір — лише там, де він щось означає. */
.cab.is-build .app { height: 100dvh; min-height: 0; grid-template-rows: auto minmax(0, 1fr); }
.cab.is-build .main { max-width: none; margin: 0; padding: 0; gap: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; min-height: 0; overflow: hidden; }

/* Шапка: довга назва компанії обрізається, а не розсуває сторінку */
.cab.is-build .top { min-width: 0; }
.cab.is-build .top-mark { flex: none; }
.cab.is-build #who { flex: 0 1 auto; min-width: 0; }
.cab.is-build #who span { min-width: 0; white-space: nowrap; }
.cab.is-build #out { flex: none; }

/* Кожна сітка має стовпець minmax(0, 1fr): широка таблиця чи довге слово прокручуються у своїй рамці, а не розсувають екран */
.b-canvas, .b-nav, .b-blocks, .b-block, .b-chat, .b-log, .b-msg, .b-compose, .b-text, .b-free, .b-metric, .b-empty { grid-template-columns: minmax(0, 1fr); }

/* ---------- полотно ---------- */
.b-canvas { min-height: 0; overflow: auto; overscroll-behavior: contain; display: grid; grid-template-rows: auto minmax(0, 1fr); align-content: start; }
.b-nav { position: sticky; top: 0; z-index: 3; display: grid; gap: var(--s2); padding: var(--s3) var(--s4); background: var(--bg); border-bottom: 1px solid var(--line); }
.b-nav:empty { display: none; }
.b-nav-row { display: flex; gap: var(--s2); overflow-x: auto; scrollbar-width: none; }
.b-nav-row::-webkit-scrollbar { display: none; }
.b-page-btn, .b-tab-btn { flex: none; min-height: 40px; padding: 0 var(--s4); border: 1px solid transparent; border-radius: 999px; background: none; color: var(--text-2); font: 600 var(--t-md)/1 var(--font-tight); letter-spacing: 0.01em; cursor: pointer; white-space: nowrap; }
.b-page-btn:hover, .b-tab-btn:hover { color: var(--text); background: var(--surface); }
.b-page-btn[aria-current="page"] { background: var(--text); color: var(--bg); }
.b-tab-btn { min-height: 34px; padding: 0 var(--s3); font-size: var(--t-sm); }
.b-tab-btn[aria-selected="true"] { background: var(--raised); border-color: var(--line-strong); color: var(--text); }
.b-blocks { display: grid; gap: var(--s7); align-content: start; padding: var(--s5) var(--s4) var(--s8); min-width: 0; }
.b-empty { align-self: center; justify-self: center; max-width: 34rem; padding: var(--s7) var(--s4); display: grid; gap: var(--s3); }
.b-empty h1 { font: 700 var(--t-xl)/1.15 var(--font-tight); }
.b-empty p { color: var(--text-2); line-height: 1.55; max-width: 52ch; }
.b-empty ul { margin: var(--s2) 0 0; padding: 0; list-style: none; display: grid; gap: var(--s2); color: var(--text-2); }
.b-empty li { display: grid; grid-template-columns: 1.4rem 1fr; align-items: baseline; }
.b-empty li::before { content: counter(step); counter-increment: step; font: 700 var(--t-sm)/1 var(--font-tight); color: var(--ok); }
.b-empty ul { counter-reset: step; }

.b-block { display: grid; gap: var(--s3); min-width: 0; }
.b-block > h2 { font: 700 var(--t-lg)/1.2 var(--font-tight); }
.b-block .b-sub { color: var(--text-3); font-size: var(--t-xs); }
.b-block.is-new { animation: b-in 0.5s var(--ease) both; }
@keyframes b-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* показники: кілька поспіль стають у ряд */
.b-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr)); gap: var(--s5) var(--s6); }
.b-metric { display: grid; gap: var(--s1); align-content: start; min-width: 0; }
.b-metric .label { color: var(--text-2); }
.b-metric-value { font: 700 var(--t-2xl)/1.05 var(--font-tight); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.b-metric-value small { font: 600 var(--t-md)/1 var(--font-tight); color: var(--text-2); margin-left: 0.3em; }
.b-metric-note { color: var(--text-3); font-size: var(--t-xs); line-height: 1.4; max-width: 34ch; }

/* таблиці */
.b-table-wrap { overflow-x: auto; max-width: 100%; border-top: 1px solid var(--line-strong); }
.b-table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.b-table th { position: sticky; top: 0; padding: var(--s2) var(--s3); text-align: left; font: 600 var(--t-xs)/1.25 var(--font-tight); letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); background: var(--bg); border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
/* слово не рветься посередині: вузький екран прокручує таблицю вбік у її рамці, а дати й числа лишаються цілими */
.b-table td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; max-width: 28rem; overflow-wrap: break-word; }
.b-table .is-num, .b-table .is-date { white-space: nowrap; }
.b-table .is-num { text-align: right; }
.b-table tr:hover td { background: var(--surface); }
.b-table td.is-edit { cursor: text; }
.b-table td.is-edit:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
.b-table .b-cell-input { width: 100%; min-width: 6rem; min-height: 32px; padding: 0 var(--s2); border: 1px solid var(--focus); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; }
.b-table .b-row-del { width: 32px; height: 32px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--text-3); cursor: pointer; }
.b-table .b-row-del:hover { color: var(--alarm); background: var(--alarm-bg); }
.b-table .b-row-del svg { width: 16px; height: 16px; }
.b-table td.is-tool { width: 1%; padding: 0 var(--s1); vertical-align: middle; }
.b-null { color: var(--text-3); }
.b-warn { color: var(--warn); font-size: var(--t-sm); }

/* графіки */
.b-bars { display: grid; grid-template-columns: minmax(6rem, 14rem) minmax(0, 1fr) auto; gap: var(--s2) var(--s3); align-items: center; font-size: var(--t-sm); }
.b-bars .b-bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.b-bars .b-bar-track { height: 14px; border-radius: 3px; background: var(--surface); overflow: hidden; }
.b-bars .b-bar-fill { height: 100%; min-width: 2px; border-radius: 3px; background: var(--ok); transform-origin: left; animation: b-grow 0.6s var(--ease) both; }
.b-bars .b-bar-fill.is-neg { background: var(--alarm); }
.b-bars .b-bar-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
@keyframes b-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.b-series { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); font-size: var(--t-xs); color: var(--text-2); }
.b-series i { display: inline-block; width: 10px; height: 10px; margin-right: var(--s1); border-radius: 2px; background: currentColor; }
.b-line { display: block; width: 100%; height: auto; overflow: visible; }
.b-line .axis { stroke: var(--line-strong); stroke-width: 1; }
.b-line .grid { stroke: var(--line); stroke-width: 1; }
.b-line text { fill: var(--text-3); font: 400 11px var(--font); }
.b-line path { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c0 { color: var(--ok); } .c1 { color: var(--calm); } .c2 { color: var(--warn); } .c3 { color: var(--alarm); } .c4 { color: var(--text-2); } .c5 { color: var(--text-3); }
.b-line path.c0, .b-line circle.c0 { stroke: var(--ok); } .b-line path.c1, .b-line circle.c1 { stroke: var(--calm); } .b-line path.c2, .b-line circle.c2 { stroke: var(--warn); }
.b-line path.c3, .b-line circle.c3 { stroke: var(--alarm); } .b-line path.c4, .b-line circle.c4 { stroke: var(--text-2); } .b-line path.c5, .b-line circle.c5 { stroke: var(--text-3); }
.b-line circle { fill: var(--bg); stroke-width: 2; }

/* текст і форма */
.b-text { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s3); max-width: 68ch; line-height: 1.6; color: var(--text); }
.b-text ul, .b-text ol { margin: 0; padding-left: 1.2em; display: grid; gap: var(--s1); list-style: disc outside; }
.b-text ol { padding-left: 1.7em; list-style: decimal outside; }
.b-text li > ul, .b-text li > ol { margin-top: var(--s1); }

/* таблиця у відповіді ШІ й у тексті: своя прокрутка вбік, сторінку не розтягує */
.b-mtable-wrap { min-width: 0; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.b-mtable { border-collapse: collapse; font-size: var(--t-sm); line-height: 1.4; overflow-wrap: normal; }
.b-mtable th, .b-mtable td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.b-mtable th { font: 600 var(--t-xs)/1.3 var(--font-tight); letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); border-bottom-color: var(--line-strong); white-space: nowrap; }
.b-mtable .is-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.b-mtable tbody tr:last-child td { border-bottom: 0; }
.b-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr)); gap: var(--s4); align-items: end; max-width: 60rem; }
.b-form .field, .b-form .input { min-width: 0; }
.b-form .b-form-act { display: flex; align-items: center; gap: var(--s3); }
.b-free { display: grid; gap: var(--s2); }
.b-free-mark { font: 600 var(--t-xs)/1 var(--font-tight); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.b-free iframe { width: 100%; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); }

/* ---------- чат ---------- */
.b-chat { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto auto; background: var(--bg); }
.b-log { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--s5) var(--s4) var(--s4); display: grid; gap: var(--s5); align-content: start; }
.b-msg { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s2); min-width: 0; line-height: 1.55; overflow-wrap: anywhere; }
.b-msg p + p { margin-top: var(--s3); }
.b-msg ul, .b-msg ol { margin: var(--s2) 0 0; padding-left: 1.2em; list-style: disc outside; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s2); }
.b-msg ol { padding-left: 1.7em; list-style: decimal outside; }
.b-msg li > ul, .b-msg li > ol { margin-top: var(--s2); }
.b-msg p + ul, .b-msg ul + p, .b-msg p + ol, .b-msg ol + p, .b-msg p + .b-mtable-wrap, .b-msg .b-mtable-wrap + p { margin-top: var(--s3); }
.b-msg.is-client { justify-self: end; max-width: 88%; padding: var(--s3) var(--s4); border-radius: var(--radius) var(--radius) 3px var(--radius); background: var(--raised); }
.b-msg.is-client.is-wait { opacity: 0.65; }
.b-msg.is-ai { max-width: 62ch; }
.b-msg.is-client.is-blocked { background: var(--alarm-bg); }
.b-mark { font: 600 var(--t-xs)/1.3 var(--font-tight); letter-spacing: 0.05em; text-transform: uppercase; color: var(--alarm); }
.b-msg.is-service { color: var(--text-2); font-size: var(--t-sm); padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--warn-bg); }
.b-files { display: flex; flex-wrap: wrap; gap: var(--s2); }
.b-file { display: inline-flex; align-items: center; gap: var(--s2); max-width: 100%; min-height: 32px; padding: 0 var(--s3); border: 1px solid var(--line-strong); border-radius: 999px; font-size: var(--t-xs); color: var(--text-2); }
.b-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-file svg { flex: none; width: 14px; height: 14px; }
.b-file.is-bad { border-color: var(--alarm); color: var(--alarm); border-radius: var(--radius); padding: var(--s2) var(--s3); white-space: normal; }
.b-file.is-bad span { white-space: normal; }
.b-file button { flex: none; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer; }
.b-file button:hover { background: var(--surface); }
.b-status { display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s4) var(--s2); min-height: 28px; color: var(--text-2); font-size: var(--t-sm); }
.b-status[hidden] { display: none; }
.b-status .lamp { width: 10px; height: 10px; color: var(--ok); animation: b-pulse 1.4s ease-in-out infinite; }
@keyframes b-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
.b-compose { display: grid; gap: var(--s2); padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
.b-compose.is-drop { background: var(--ok-bg); }
.b-compose-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s2); align-items: end; }
.b-compose textarea { width: 100%; min-height: 44px; max-height: 40dvh; padding: 10px var(--s3); border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); font: 400 var(--t-md)/1.45 var(--font); resize: none; }
.b-compose textarea:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.b-compose textarea::placeholder { color: var(--text-3); }
.b-icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius); background: none; color: var(--text); cursor: pointer; }
.b-icon-btn:hover { background: var(--raised); }
.b-icon-btn[disabled] { opacity: 0.45; cursor: default; }
.b-icon-btn.is-go { background: var(--text); border-color: var(--text); color: var(--bg); }
.b-icon-btn svg { width: 20px; height: 20px; }
.b-hint { color: var(--text-3); font-size: var(--t-xs); }

/* ---------- телефон: чат і полотно перемикаються ---------- */
.b-switch { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); background: var(--bg); padding-bottom: env(safe-area-inset-bottom, 0px); }
.b-switch button { position: relative; min-height: 52px; border: 0; background: none; color: var(--text-3); font: 600 var(--t-sm)/1 var(--font-tight); letter-spacing: 0.04em; text-transform: uppercase; cursor: pointer; }
.b-switch button[aria-pressed="true"] { color: var(--text); background: var(--surface); }
.b-switch .b-dot { position: absolute; top: 14px; margin-left: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.b-switch .b-dot[hidden] { display: none; }
.cab.is-build .main[data-pane="chat"] .b-canvas, .cab.is-build .main[data-pane="canvas"] .b-chat { display: none; }
.cab.is-build .main[data-pane="chat"] .b-compose { padding-bottom: var(--s3); }

@media (min-width: 960px) {
  .cab.is-build .main { grid-template-columns: minmax(0, 1fr) clamp(22rem, 30vw, 28rem); grid-template-rows: minmax(0, 1fr); padding: 0; }
  .cab.is-build .main[data-pane] .b-canvas, .cab.is-build .main[data-pane] .b-chat { display: grid; }
  .b-switch { display: none; }
  .b-chat { border-left: 1px solid var(--line); }
  .b-nav { padding: var(--s3) var(--s6); }
  .b-blocks { padding: var(--s6) var(--s6) var(--s8); }
}
@media (max-width: 520px) {
  /* вузький екран: підпис стовпця стає над ним на всю ширину, щоб назва читалась цілою */
  .b-bars { grid-template-columns: minmax(0, 1fr) auto; }
  .b-bars .b-bar-label { grid-column: 1 / -1; white-space: normal; overflow-wrap: anywhere; margin-top: var(--s2); }
  .b-bars .b-bar-label:empty { display: none; }
  .b-metric-value { font-size: var(--t-xl); }
}
@media (prefers-reduced-motion: reduce) {
  .b-block.is-new, .b-bars .b-bar-fill, .b-status .lamp { animation: none; }
}
