.agent-editor { width: min(1440px, 96vw); height: 94dvh; max-height: 94dvh; padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); overflow: hidden; }
.agent-editor[open] { display: flex; flex-direction: column; }
.agent-editor.editor-maximized { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; inset: 0; border: 0; border-radius: 0; }
.editor-window-actions { display: flex; flex-shrink: 0; gap: 10px; }
.model-card-editing { border-color: var(--primary); }
.model-card-editing > .model-form { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.model-form .model-form-grid > .model-form-grid { grid-column: 1 / -1; }
.agent-editor::backdrop { background: var(--overlay); }
.agent-editor header { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex: 0 0 auto; padding: 22px 28px 8px; }
.agent-editor h2 { margin: 0; font-size: 1.4rem; }
.agent-editor fieldset { margin: 0; padding: 20px; border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.editor-layout { display: flex; flex: 1; min-height: 0; border-top: 1px solid var(--line); }
.editor-nav { width: 190px; flex-shrink: 0; padding: 20px 12px; display: flex; flex-direction: column; gap: 6px; overflow: auto; border-right: 1px solid var(--line); }
.editor-nav button { border: 0; padding: 12px; text-align: left; background: transparent; color: var(--muted); border-radius: 8px; font: inherit; cursor: pointer; }
.editor-nav button[aria-current] { background: var(--primary-soft); color: var(--text); font-weight: 700; }
.editor-layout > form { display: flex; flex: 1; min-width: 0; flex-direction: column; }
.editor-sections { flex: 1; min-height: 0; overflow: auto; padding: 24px; overscroll-behavior: contain; }
.agent-editor legend { padding: 0 10px; font-weight: 600; }
.agent-editor .field { margin: 12px 0; }
.agent-editor textarea, .agent-editor input, .agent-editor select { color: var(--text); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; padding: 10px; max-width: 100%; }
.agent-editor textarea { width: 100%; resize: vertical; line-height: 1.6; }
.agent-editor input[type=checkbox] { width: auto; }
.agent-editor footer { flex: 0 0 auto; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--surface); }
.agent-editor fieldset > button { margin: 8px 8px 0 0; }
.agent-editor pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 400px; overflow: auto; font-size: .85rem; }
.editor-notice { min-height: 1.5em; flex: 0 0 auto; margin: 0; padding: 8px 28px 16px; color: var(--muted); }
.editor-errors { flex: 0 0 auto; max-height: 24dvh; overflow: auto; padding: 10px 24px; border-bottom: 1px solid var(--line); }
.editor-errors p { margin: 4px 0; overflow-wrap: anywhere; }
.editor-errors button { display: block; width: 100%; padding: 6px 0; border: 0; background: transparent; color: var(--danger, #b42318); text-align: left; text-decoration: underline; font: inherit; cursor: pointer; overflow-wrap: anywhere; }
.agent-editor [aria-invalid=true] { border: 2px solid var(--danger, #b42318); }
.editor-field-error { display: block; color: var(--danger, #b42318); margin-top: 6px; font-size: .85rem; }
.editor-errors[hidden], .editor-field-error[hidden] { display: none; }
@media (max-width: 700px) {
    .agent-editor { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
    .agent-editor header { padding: 16px 16px 8px; gap: 10px; }
    .agent-editor h2 { font-size: 1.05rem; overflow-wrap: anywhere; }
    .editor-notice { padding: 6px 16px 12px; font-size: .75rem; }
    .editor-layout { flex-direction: column; }
    .editor-nav { width: auto; flex-direction: row; flex: 0 0 auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
    .editor-nav button { white-space: nowrap; padding: 10px; font-size: .8125rem; }
    .editor-layout > form { min-height: 0; }
    .editor-sections { padding: 16px; }
    .agent-editor fieldset { padding: 14px; }
    .agent-editor footer { padding: 12px 16px max(12px, env(safe-area-inset-bottom)); }
}
.run-status-banner { margin: 12px auto; padding: 12px; max-width: 760px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: var(--surface); font-size: .85rem; }
/* The crop dialog is shared by creation and independent agent editing. */
.agent-avatar-crop { max-width: min(440px, 92vw); border-radius: 18px; padding: 24px; color: var(--text-primary); background: var(--surface, #fff); }
.agent-avatar-crop canvas { width: 100%; max-width: 320px; display: block; margin: 12px auto; border-radius: 50%; touch-action: none; cursor: move; background: #eee; }
.agent-avatar-crop label { display: flex; gap: 12px; align-items: center; margin: 10px 0; }
.agent-avatar-crop input { flex: 1; }
.agent-avatar-crop footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.agent-avatar-field { display: grid; gap: 12px; padding: 12px 0; }
.agent-avatar-field img { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; }
.knowledge-source-dialog { width: min(840px, 94vw); height: min(760px, 88dvh); max-height: 88dvh; padding: 20px; border: 1px solid var(--line, #ddd); border-radius: 18px; background: var(--surface, #fff); color: var(--text, #222); box-sizing: border-box; }
.knowledge-source-dialog[open] { display: flex; flex-direction: column; gap: 12px; overflow: hidden; }
.source-reader-header { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.source-reader-header h3 { margin: 0; overflow-wrap: anywhere; font-size: 1.1rem; }
.source-reader-header button { flex-shrink: 0; min-height: 40px; }
.source-reader-status { margin: 0; color: var(--muted, #666); font-size: .85rem; }
.source-reader-content { flex: 1; min-height: 120px; overflow: auto; line-height: 1.85; }
.knowledge-source-dialog .source-reader-content pre { margin: 0; padding: 0; max-height: none; overflow: visible; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
.source-reader-navigation { display: flex; justify-content: space-between; gap: 12px; }
.knowledge-source-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.knowledge-source-summary span { overflow-wrap: anywhere; }
.knowledge-source-summary button { flex-shrink: 0; }
.knowledge-source-dialog img { max-width: 100%; height: auto; }
.knowledge-source-dialog pre, .knowledge-answer-sources pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 45vh; overflow: auto; padding: 12px; }
.knowledge-answer-sources { margin: 12px 0; font-size: .9rem; }
.knowledge-answer-sources details { padding: 8px; border: 1px solid var(--border-color, #ddd); border-radius: 8px; margin: 8px 0; }
.memory-manager.agent-editor { width: min(800px, 94vw); height: auto; max-height: 90dvh; padding: 24px; overflow: auto; }
.memory-manager.agent-editor[open] { display: block; }
.memory-manager.agent-editor header { padding: 0 0 16px; }
.memory-manager.agent-editor .field:has(input[type=checkbox]) { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 20px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.memory-manager.agent-editor input[type=checkbox] { width: 20px; height: 20px; min-height: 20px; padding: 0; flex: 0 0 20px; }
.memory-manager.agent-editor section { margin: 20px 0; }
.memory-manager.agent-editor fieldset { margin: 12px 0; }
.memory-manager.agent-editor select { width: 100%; }
