/* Zidos · W2D: агенты, настройка агента, проекты, обзор проекта.
   Только токены из tokens.css. Один акцент --action на экран: «+ Новый агент» / «Сохранить». Движение 220–300 мс, --ease. */

[hidden]:not(dialog):not(#w2d-hidden) { display: none; }

/* ---------- общие части ---------- */
.w2d-cap { flex: none; }
.w2d-icon { flex: none; background: var(--panel); color: var(--ink); }
.w2d-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.w2d-icon:hover { background: var(--raised); }
.cap.w2d-cap > svg { display: block; }
.w2d-cap svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.w2d-cap:hover { background: var(--raised); }
.btn--primary.w2d-cap:hover { background: var(--action); color: var(--action-ink); }

.w2d-seg { display: inline-flex; align-items: center; gap: 2px; padding: var(--sp-4); border-radius: var(--radius-pill); background: var(--panel); max-width: 100%; }
.w2d-seg > button {
  flex: 1 1 auto; min-height: 40px; padding: 0 var(--sp-12); border-radius: var(--radius-pill); background: transparent; color: var(--muted);
  font-size: var(--fs-small); font-weight: 550; line-height: 1; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.w2d-seg > button[aria-pressed="true"] { background: var(--ink-button); color: var(--ink-button-text); }
.w2d-seg > button:not([aria-pressed="true"]):hover { color: var(--ink); }
body.section-screen-agent:not(.w2d-editing) .w2d-seg[data-w2d-field] > button { cursor: default; }

.w2d-field { display: flex; flex-direction: column; gap: var(--sp-8); font-size: var(--fs-small); color: var(--muted); font-weight: 550; }
.w2d-field > span:first-child { color: var(--ink); }
.w2d-field small { color: var(--muted); font-weight: 400; }
/* поля берут единый облик из w2b.css (44, --raised, радиус --radius-field); здесь только многострочные и подложки */
body.section-screen :is(.w2d-sheet, .w2d-instr, .w2d-block) textarea:not(.r29-host *) { height: auto; min-height: 96px; max-height: none; padding: var(--sp-12) var(--sp-16); line-height: 1.5; font: inherit; font-size: var(--fs-body); resize: vertical; cursor: text; }
body.section-screen :is(.w2d-sheet, .w2d-instr, .w2d-block, .w2d-people, .w2d-add-panel) input:not([type=checkbox]):not(.r29-host *) { cursor: text; }
:is(.w2d-field, .w2d-sheet, .w2d-perms, .w2d-block, .w2d-people, .w2d-instr, .w2d-fb-new, .w2d-host-new, .w2d-rule-new, .w2d-inline-add, .w2d-add-panel) :is(input, select, textarea):focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
:is(.w2d-block, .w2d-sheet) :is(input, select, textarea)::placeholder { color: var(--faint); }
.w2d-block :is(select, input):disabled { opacity: 1; color: var(--ink); }
.w2d-error { color: var(--bad); font-size: var(--fs-small); }

.w2d-chips-row, .w2d-chips { display: flex; flex-wrap: wrap; gap: var(--sp-8); margin: 0; padding: 0; list-style: none; }
.w2d-chip, .w2d-chips li { display: inline-flex; align-items: center; min-height: 36px; padding: 0 var(--sp-12); border-radius: var(--radius-pill); background: var(--raised); color: var(--ink); font-size: var(--fs-small); font-weight: 550; }
.w2d-chip { min-height: var(--h-pill); background: var(--panel); transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.w2d-chip[aria-pressed="true"] { background: var(--ink-button); color: var(--ink-button-text); }
.w2d-chips code { font-family: var(--z-font-code); font-size: var(--fs-small); }

/* ---------- меню-поповер ---------- */
.w2d-menu {
  position: fixed; z-index: 2000; min-width: 200px; padding: var(--sp-8); border-radius: var(--radius-inner); background: var(--raised); color: var(--ink); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px; opacity: 0; transform: translateY(-4px);
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.w2d-menu.is-open { opacity: 1; transform: none; }
.w2d-menu-item { display: flex; align-items: center; min-height: var(--h-pill); padding: 0 var(--sp-12); border-radius: var(--radius-sm); text-align: left; font-size: var(--fs-body); color: var(--ink); }
.w2d-menu-item:hover, .w2d-menu-item:focus-visible { background: var(--panel); outline: none; }
.w2d-menu-item.is-current { font-weight: 650; }
.w2d-menu-item.is-danger { color: var(--bad); }

/* ---------- листы ---------- */
dialog.w2d-sheet { position: fixed; inset: 0; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; color: var(--ink); display: none; place-items: center; z-index: 1000; }
dialog.w2d-sheet[open] { display: grid; }
dialog.w2d-sheet::backdrop { background: var(--scrim); }
.w2d-sheet-box {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); display: flex; flex-direction: column; border-radius: var(--radius-card); background: var(--panel); box-shadow: var(--shadow);
  animation: w2d-rise var(--dur-base) var(--ease);
}
.w2d-sheet .w2d-seg { background: var(--raised); }
.w2d-sheet .w2d-seg > button[aria-pressed="true"] { background: var(--ink-button); }
.w2d-sheet .w2d-chip { background: var(--raised); }
.w2d-sheet .w2d-chip[aria-pressed="true"] { background: var(--ink-button); }
.w2d-sheet .w2d-icon { background: var(--raised); }
.w2d-sheet .w2d-table--compact .w2d-class, .w2d-sheet .w2d-member { background: var(--raised); }
.w2d-sheet .w2d-class .w2d-seg { background: var(--panel); }
.w2d-sheet .w2d-log { background: var(--raised); }
.w2d-sheet--wide .w2d-sheet-box { width: min(680px, calc(100vw - 32px)); }
.w2d-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-12); padding: var(--pad-card) var(--pad-card) var(--sp-8); }
.w2d-sheet-head h2 { font-size: var(--fs-h2); font-weight: var(--fw-h2); }
.w2d-sheet-body { display: flex; flex-direction: column; gap: var(--sp-16); padding: var(--sp-8) var(--pad-card) var(--sp-16); overflow-y: auto; min-height: 0; }
.w2d-sheet-actions { display: flex; justify-content: flex-end; gap: var(--sp-8); padding: var(--sp-12) var(--pad-card) var(--pad-card); flex-wrap: wrap; }
@keyframes w2d-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes w2d-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Агенты ---------- */
.section-agents .section-heading, .section-project .section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-16); flex-wrap: wrap; }
.w2d-agent-list { display: flex; flex-direction: column; }
.w2d-agent-line { display: flex; align-items: center; gap: var(--sp-8); }
.w2d-agent-line:has(> [hidden]) { display: none; }
.w2d-agent-line > .w2d-agent-row { flex: 1 1 0; min-width: 0; }
.w2d-agent-line .agent-row-model { flex: 0 1 auto; padding-left: 0; text-align: right; }
.w2d-agent-line .agent-row-model small { display: block; }
.w2d-row-actions { display: inline-flex; align-items: center; gap: var(--sp-8); flex: none; margin-bottom: var(--sp-8); }
.w2d-agent-line.is-disabled .w2d-agent-row { opacity: .55; }
.w2d-state { color: var(--muted); }
.w2d-state:empty { display: none; }

/* ---------- Настройка агента ---------- */
.w2d-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-16); flex-wrap: wrap; margin: 0 0 var(--sp-16); padding: var(--sp-12) var(--pad-card); border-radius: var(--radius-card); background: var(--panel); }
.w2d-switch { display: inline-flex; align-items: center; gap: var(--sp-12); text-align: left; min-height: var(--h-pill); color: var(--ink); }
.w2d-switch-track { position: relative; flex: none; width: 48px; height: 28px; border-radius: var(--radius-pill); background: var(--faint); transition: background var(--dur-fast) var(--ease); }
.w2d-switch-thumb { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--frame); transition: transform var(--dur-fast) var(--ease); }
.w2d-switch[aria-checked="true"] .w2d-switch-track { background: var(--ink-button); }
.w2d-switch[aria-checked="true"] .w2d-switch-thumb { transform: translateX(20px); background: var(--raised); }
.w2d-switch-label { display: flex; flex-direction: column; gap: 2px; }
.w2d-switch-label strong { font-size: var(--fs-body); font-weight: 600; }
.w2d-switch-label small { color: var(--muted); font-size: var(--fs-small); }
.w2d-bar-actions { display: flex; align-items: center; gap: var(--sp-8); flex-wrap: wrap; margin-left: auto; }
.w2d-status { font-size: var(--fs-small); min-height: 1em; }

/* в режиме правки текстом управляют «Сохранить» и «Отменить» шапки: сегмента «Читать/Править» и кнопок редакторов нет в разметке (hidden), акцент на экране один */
body.w2d-editing .agent-model .agent-editor-actions { display: none; }
body.w2d-editing .agent-editor-tools:not([hidden]) { animation: w2d-fade var(--dur-base) var(--ease); }
body.w2d-editing .agent-panel[data-agent-panel="soul"] .agent-content, body.w2d-editing .agent-panel[data-agent-panel="instructions"] .agent-content { display: none; }

.w2d-block { display: flex; flex-direction: column; gap: var(--sp-12); margin: 0 0 var(--sp-12); }
.w2d-block > p { font-size: var(--fs-small); }
.w2d-perms { display: flex; flex-direction: column; }
.w2d-table { display: flex; flex-direction: column; gap: var(--sp-8); }
.w2d-class { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-12); padding: var(--sp-8) var(--sp-12); border-radius: var(--radius-inner); background: var(--panel); }
.w2d-class-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.w2d-class-name strong { font-size: var(--fs-body); font-weight: 600; }
.w2d-class-name small { color: var(--muted); font-size: var(--fs-small); }
.w2d-list { display: flex; flex-direction: column; gap: var(--sp-8); }
.w2d-rule, .w2d-host { display: flex; align-items: center; gap: var(--sp-12); padding: var(--sp-8) var(--sp-12); border-radius: var(--radius-inner); background: var(--panel); min-width: 0; }
.w2d-rule code, .w2d-host code { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; font-family: var(--z-font-code); font-size: var(--fs-small); }
.w2d-kind { flex: none; min-width: 72px; color: var(--muted); font-size: var(--fs-small); font-weight: 550; }
.w2d-rule-new { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: var(--sp-8); align-items: center; padding: var(--sp-12); border-radius: var(--radius-inner); background: var(--panel); }
.w2d-rule-new > .w2d-seg { justify-self: start; }
.w2d-edit-only, [data-w2d-edit-only] { display: none; }
.w2d-icon[data-w2d-edit-only] { display: inline-grid; visibility: hidden; }
body.w2d-editing .w2d-icon[data-w2d-edit-only] { visibility: visible; }
body.w2d-editing .w2d-edit-only { display: flex; animation: w2d-fade var(--dur-base) var(--ease); }
.w2d-host-new, .w2d-fb-new { gap: var(--sp-8); align-items: center; }
.w2d-host-new input, .w2d-fb-new select { flex: 1 1 0; min-width: 0; }
.w2d-add-line { display: flex; }
.w2d-stepper { display: inline-flex; align-items: center; gap: var(--sp-12); }
.w2d-stepper output { min-width: 32px; text-align: center; font-size: var(--fs-h2); font-weight: var(--fw-h2); font-variant-numeric: tabular-nums; }
.w2d-grant { display: flex; align-items: center; gap: var(--sp-8); flex-wrap: wrap; }
.w2d-grant > span { display: flex; flex-direction: column; gap: 2px; flex: 1 1 200px; }
.w2d-grant small { color: var(--muted); font-size: var(--fs-small); }
.w2d-fallback-list { display: flex; flex-direction: column; gap: var(--sp-8); margin: 0; padding: 0; list-style: none; }
.w2d-fallback { display: flex; align-items: center; gap: var(--sp-12); padding: var(--sp-8) var(--sp-12); border-radius: var(--radius-inner); background: var(--panel); }
.w2d-order { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--panel); color: var(--muted); font-size: var(--fs-small); font-weight: 600; font-variant-numeric: tabular-nums; }
.w2d-fallback-name { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.w2d-fallback-name small { color: var(--muted); font-size: var(--fs-small); }

/* ---------- Проекты и обзор проекта ---------- */
.w2d-project-line { display: flex; align-items: center; gap: var(--sp-8); }
.w2d-project-line > .project-row { flex: 1 1 0; min-width: 0; }
.w2d-project-line:has(> [hidden]) { display: none; }
.w2d-project-settings { align-self: center; }
.w2d-project-settings span { display: inline; }
.w2d-people { display: flex; flex-direction: column; gap: var(--sp-8); }
.w2d-people > h4 { margin-top: var(--sp-8); color: var(--muted); }
.w2d-member-list { display: flex; flex-direction: column; gap: var(--sp-8); }
.w2d-member { display: flex; align-items: center; gap: var(--sp-12); padding: var(--sp-8) var(--sp-12); border-radius: var(--radius-inner); background: var(--raised); min-width: 0; }
.w2d-member .avatar { flex: none; width: var(--icon-row); height: var(--icon-row); display: grid; place-items: center; border-radius: 50%; background: var(--panel); color: var(--ink); font-weight: 600; }
.w2d-member-copy { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.w2d-member-copy strong { font-size: var(--fs-body); font-weight: 600; color: var(--ink); }
.w2d-member-copy small { color: var(--muted); font-size: var(--fs-small); }
.w2d-role-btn::after { content: ''; width: 7px; height: 7px; margin-left: var(--sp-8); border-right: 1.8px solid currentColor; border-bottom: 1.8px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.w2d-add-panel { display: flex; flex-direction: column; gap: var(--sp-12); padding: var(--sp-12); border-radius: var(--radius-inner); background: var(--panel); animation: w2d-fade var(--dur-base) var(--ease); }
.w2d-add-panel > div[data-w2d-add-person] { display: grid; grid-template-columns: minmax(0, 1fr) 160px; gap: var(--sp-8); }
.w2d-add-actions { display: flex; justify-content: flex-end; gap: var(--sp-8); flex-wrap: wrap; }
.w2d-inline-add { display: flex; gap: var(--sp-8); align-items: center; flex-wrap: wrap; }
.w2d-inline-add input, .w2d-inline-add select { flex: 1 1 140px; width: auto; min-width: 0; }
.w2d-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-12); }
.w2d-instr { display: flex; flex-direction: column; gap: var(--sp-12); }
.w2d-instr-read { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; color: var(--ink); }
.w2d-instr-edit { display: flex; flex-direction: column; gap: var(--sp-12); animation: w2d-fade var(--dur-base) var(--ease); }
.w2d-log { padding: var(--sp-12) var(--sp-16); border-radius: var(--radius-inner); background: var(--panel); }
.w2d-log summary { min-height: 32px; display: flex; align-items: center; font-weight: 600; font-size: var(--fs-small); cursor: pointer; }
.w2d-log ul { margin: var(--sp-8) 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--sp-8); }
.w2d-log li { display: flex; flex-direction: column; font-size: var(--fs-small); }

/* ---------- телефон ---------- */
@media (max-width: 760px) {
  .w2d-agent-line { flex-wrap: wrap; }
  .w2d-agent-row { flex-wrap: wrap; }
  .w2d-agent-row > .row-text { flex: 1 1 calc(100% - 64px); }
  .w2d-agent-row > .agent-row-model { flex: 1 1 100%; text-align: left; padding-left: calc(var(--icon-row) + var(--sp-12)); }
  .w2d-agent-row > span[aria-hidden]:last-child { display: none; }
  .w2d-agent-line > .w2d-agent-row { flex: 1 1 100%; margin-bottom: var(--sp-4); }
  .w2d-row-actions { margin-left: auto; margin-bottom: var(--sp-12); }
  .w2d-class { flex-direction: column; align-items: stretch; }
  .w2d-class .w2d-seg { display: flex; }
  .w2d-class .w2d-seg > button { padding: 0 var(--sp-8); }
  .w2d-rule { flex-wrap: wrap; }
  .w2d-rule .w2d-seg { order: 5; flex: 1 1 100%; }
  .w2d-rule-new { grid-template-columns: minmax(0, 1fr); }
  .w2d-project-settings span { display: none; }
  .w2d-project-settings { width: var(--h-icon); padding: 0; }
  .w2d-add-panel > div[data-w2d-add-person] { grid-template-columns: minmax(0, 1fr); }
  .w2d-bar { padding: var(--sp-12); }
  .w2d-bar-actions { margin-left: 0; width: 100%; }
  .w2d-sheet-actions .w2d-cap { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .w2d-sheet-box, .w2d-edit-only, .w2d-add-panel, .w2d-instr-edit { animation: none; }
  .w2d-menu, .w2d-switch-track, .w2d-switch-thumb, .w2d-seg > button { transition: none; }
}

/* строки внутри карточек: тон панели, управляющее внутри них — приподнятое */
.w2d-block :is(.w2d-class, .w2d-rule, .w2d-fallback) .w2d-seg, .w2d-block .w2d-icon, .w2d-people .w2d-icon, .w2d-member .w2d-cap, .w2d-bar .w2d-cap:not(.btn--primary) { background: var(--raised); }
.w2d-block .w2d-order { background: var(--raised); }
.w2d-block .w2d-cap:not(.btn--primary), .w2d-people .w2d-cap:not(.btn--primary), .w2d-instr .w2d-cap:not(.btn--primary) { background: var(--panel); }
.w2d-block :is(.w2d-class, .w2d-rule, .w2d-fallback) .w2d-seg > button[aria-pressed="true"] { background: var(--ink-button); }
.w2d-sheet .w2d-member .w2d-cap { background: var(--panel); }
.w2d-sheet .w2d-cap:not(.btn--primary):not(.cap--quiet) { background: var(--raised); }
.w2d-sheet .w2d-cap.cap--quiet { background: transparent; }

/* ---------- строка агента и проекта: карточка — сама линия, действия внутри (W2H) ---------- */
.section-screen :is(.w2d-agent-line, .w2d-project-line) { gap: var(--sp-12); }
.section-screen :is(.w2d-agent-row, .w2d-project-row) { display: flex; align-items: center; gap: var(--sp-12); flex: 1 1 0; min-width: 0; color: inherit; text-decoration: none; }
.section-screen :is(.w2d-agent-row, .w2d-project-row):hover strong { color: var(--action); }
.section-screen .w2d-agent-line .w2d-row-actions { margin: 0; }
.section-screen .w2d-agent-line .w2d-row-actions .w2d-cap, .section-screen .w2d-project-line .w2d-project-settings { min-height: 44px; white-space: nowrap; }
.section-screen .w2d-agent-line .w2d-row-actions :is(.w2d-cap, .w2d-icon), .section-screen .w2d-project-line .w2d-project-settings { background: var(--panel); }
.section-screen .w2d-agent-line .w2d-row-actions :is(.w2d-cap, .w2d-icon):hover, .section-screen .w2d-project-line .w2d-project-settings:hover { background: var(--raised); }
@media (max-width: 760px) {
  .section-screen :is(.w2d-agent-line, .w2d-project-line) { flex-wrap: wrap; gap: var(--sp-8); }
  .section-screen :is(.w2d-agent-line, .w2d-project-line) > :is(.w2d-agent-row, .w2d-project-row) { flex: 1 1 100%; margin: 0; }
  .section-screen .w2d-agent-line .w2d-row-actions, .section-screen .w2d-project-line .w2d-project-settings { margin-left: auto; }
}

/* выбор файла — капсула с русской подписью; системное «Choose File / No file chosen» не показываем (поле остаётся рабочим) */
.section-screen .agent-import { position: relative; display: inline-flex; width: auto; min-height: 44px; padding: 0 var(--sp-16); margin: var(--sp-8) 0; border-radius: var(--radius-pill); background: var(--panel); color: var(--ink); font-size: var(--fs-small); font-weight: 600; cursor: pointer; }
.section-screen .agent-import:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.section-screen .agent-import input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.section-screen .agent-skills input[type=checkbox] { accent-color: var(--ink); width: 18px; height: 18px; }
