/* Оболочка панели: компактная плотность поверх Pico, боковое меню, компоненты. */
:root {
  --pico-font-size: 14px;
  --pico-line-height: 1.4;
  --pico-spacing: .5rem;
  --pico-typography-spacing-vertical: .75rem;
  --pico-block-spacing-vertical: 1rem;
  --pico-block-spacing-horizontal: 1rem;
  --pico-form-element-spacing-vertical: .4rem;
  --pico-form-element-spacing-horizontal: .6rem;
  --pico-border-radius: 6px;
  --pico-card-box-shadow: none;
  --line: #dfe3e8;
  --bg-soft: #f6f8fa;
  --ink-muted: #6b7280;
  --ok-bg: #e6f4ea; --ok-fg: #1e7e34;
  --err-bg: #fdecea; --err-fg: #b42318;
  --warn-bg: #fff4e5; --warn-fg: #9a5b00;
  --muted-bg: #eef0f3; --muted-fg: #4b5563;
  --accent-soft: #e8f0fe;
}
html { font-size: 14px; }
body { margin: 0; background: #fff; }
h1 { font-size: 1.43rem; margin: 0; }
h2 { font-size: 1.14rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
button, [role=button], input[type=submit], button[type=submit] { width: auto; margin-bottom: 0; font-size: .93rem; padding: .4rem .8rem; }
input, select, textarea { margin-bottom: 0; }
label { margin-bottom: .2rem; font-size: .93rem; }
article { box-shadow: none; border: 1px solid var(--line); margin: 0; padding: 1rem; }
hr { margin: .75rem 0; }

/* Раскладка */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: var(--bg-soft); display: flex; flex-direction: column; padding: 14px 10px; gap: 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 1.05rem; padding: 4px 10px 8px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); padding: 8px 10px 2px; }
.nav-group a { display: block; padding: 6px 10px; border-radius: 6px; color: inherit; text-decoration: none; font-size: .95rem; }
.nav-group a:hover { background: #eceff3; }
.nav-group a.active { background: var(--accent-soft); font-weight: 600; color: var(--pico-primary); }
.sidebar-user { margin-top: auto; padding: 8px 10px; font-size: .9rem; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line); }
.main { padding: 18px 22px 40px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.page-head .sub { color: var(--ink-muted); font-size: .93rem; margin: .2rem 0 0; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }
.section { margin-top: 20px; }

/* Компоненты */
.muted { color: var(--ink-muted); }
.mono { font-family: var(--pico-font-family-monospace); font-size: .86rem; }
.truncate { display: inline-block; max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; line-height: 1.5; background: var(--muted-bg); color: var(--muted-fg); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.err { background: var(--err-bg); color: var(--err-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.ok { color: var(--ok-fg); } .err { color: var(--err-fg); }
.btn-sm { font-size: .82rem; padding: .2rem .55rem; line-height: 1.4; }
.field-sm { font-size: .86rem; padding: .2rem .45rem; height: auto; width: auto; min-width: 6rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.toolbar select, .toolbar input:not([type=checkbox]) { width: auto; min-width: 9rem; font-size: .9rem; padding: .3rem .5rem; height: auto; }
.toolbar label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: .9rem; white-space: nowrap; }
.toolbar .spacer { flex: 1; }
.meta { color: var(--ink-muted); font-size: .86rem; margin-top: 8px; display: flex; gap: 14px; flex-wrap: wrap; }
.table-wrap { border: 1px solid var(--line); border-radius: 6px; overflow: auto; max-height: 75vh; }
.table-wrap table { margin: 0; font-size: .93rem; }
.table-wrap th { position: sticky; top: 0; background: var(--bg-soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-wrap td { padding: 6px 10px; vertical-align: middle; border-bottom: 1px solid var(--line); }
.table-wrap tbody tr:hover td { background: #fafbfc; }
.table-wrap tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.id { color: var(--ink-muted); font-size: .86rem; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions > * { display: inline-block; vertical-align: middle; margin-left: 6px; }
div.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
div.row-actions > * { margin-left: 0; }
.row-actions a { font-size: .9rem; }
.empty { padding: 28px; text-align: center; color: var(--ink-muted); }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.kpi { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.kpi .label { font-size: .8rem; color: var(--ink-muted); }
.kpi .value { font-size: 1.55rem; font-weight: 600; line-height: 1.2; margin: 2px 0; }
.kpi .hint { font-size: .8rem; color: var(--ink-muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.help { font-size: .82rem; color: var(--ink-muted); margin-top: 2px; }
.form-error { color: var(--err-fg); font-size: .9rem; margin: 0 0 8px; }
dialog.panel article { width: min(760px, 92vw); max-height: 90vh; overflow: auto; padding: 18px 20px; }
dialog.panel header { margin: -18px -20px 14px; padding: 12px 20px; border-bottom: 1px solid var(--line); font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .93rem; }
.kv dt { color: var(--ink-muted); margin: 0; }
.kv dd { margin: 0; }
.tree ul { list-style: none; padding-left: 1rem; margin: 0; border-left: 1px solid var(--line); }
.tree > ul { border-left: 0; padding-left: 0; }
.tree li { margin: 4px 0; }
.span-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .93rem; }
.span-bar { height: 4px; background: #e4e7eb; border-radius: 2px; position: relative; margin: 3px 0 2px; }
.span-bar i { position: absolute; top: 0; height: 100%; background: var(--pico-primary); border-radius: 2px; }
details.span summary { cursor: pointer; font-size: .86rem; color: var(--ink-muted); }
pre.small { font-size: .8rem; max-height: 22rem; overflow: auto; margin: 6px 0 0; padding: 8px 10px; }
.updated-at { font-size: .8rem; color: var(--ink-muted); }
.chat { display: flex; flex-direction: column; gap: 8px; }
.bubble { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; white-space: pre-wrap; }
.bubble.user { background: var(--bg-soft); }
.bubble.bot { background: #fff; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-group { flex-direction: row; flex-wrap: wrap; gap: 2px; }
  .nav-title { display: none; }
  .sidebar-user { margin: 0 0 0 auto; border: 0; flex-direction: row; align-items: center; padding: 0 4px; }
  .brand { padding: 4px 8px; }
  .main { padding: 14px 12px 30px; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}
.kpi-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .kpi-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.toolbar input[type=search] { padding-left: 2.1rem; min-width: 13rem; }

/* Дерево, консоль, вход: общие классы, перенесены из временных head-блоков */
.tree li { list-style: none; }
.tree .kv { margin: 4px 0; }
.tree .kv dd { white-space: pre-wrap; overflow-wrap: anywhere; }
.tree .kv pre.small { margin: 0; }
.tree details.span[open] > summary { margin-bottom: 4px; }
.kv-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 28px; margin-bottom: 16px; }
.span-bar.err i { background: var(--err-fg); }
.chat .bubble.user, .turn .bubble.user { align-self: flex-end; max-width: 80%; }
.chat .bubble.bot, .turn .bubble.bot { align-self: flex-start; max-width: 90%; }
td.mono, td.status, td.nowrap { white-space: nowrap; }
.toolbar select[name=all] { min-width: 11rem; }
.console-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.console-grid article { position: sticky; top: 18px; }
#console-chat { flex-direction: column-reverse; max-height: calc(100vh - 120px); min-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
#console-chat:has(.turn) .empty { display: none; }
.turn { display: flex; flex-direction: column; gap: 6px; }
.turn .buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.turn .buttons form { margin: 0; }
#console-busy { white-space: nowrap; }
@media (max-width: 900px) {
  .kv-cols { grid-template-columns: 1fr; }
  .console-grid { grid-template-columns: 1fr; }
  .console-grid article { position: static; }
}

/* Разделы управления: строчное редактирование, узкие обрезки, submit в диалогах */
.form-actions button[type=submit] { width: auto; }
input.field-sm { width: auto; }
select.field-sm { max-width: 11rem; }
.access { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.truncate.w-16 { max-width: 16ch; } .truncate.w-20 { max-width: 20ch; } .truncate.w-22 { max-width: 22ch; }
#users-q { min-width: 20rem; }

/* Каталог функций: обрезка описания, бейджи статуса в две строки, диалог правки внутри строки */
.truncate.w-30 { max-width: 30ch; }
/* Запросы на доработку: раскрытое видение читается строками, а не столбиком в узкой ячейке */
details.vision .bubble { min-width: 30ch; max-width: 48ch; }
td.status.wrap { white-space: normal; }
td dialog.panel { text-align: left; white-space: normal; }
dialog.panel header .mono { font-weight: 400; }
