.list-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-top: 20px;
}

.telegram-jump { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 28px; }
.telegram-section-heading { margin: 28px 0 16px; }
.telegram-section-heading h2 { margin: 4px 0 6px; }
.telegram-section-heading p:last-child { margin: 0; color: var(--muted); }
.telegram-personal { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--line); scroll-margin-top: 92px; }
#telegram-bot-setup { scroll-margin-top: 92px; }
.model-picker input[type="search"] { width: 100%; margin: 8px 0 14px; }
.model-picker select[aria-label="Фільтр за призначенням моделі"] { width: 100%; margin: 0 0 14px; }
.model-choice-guide { margin: 4px 0 16px; padding: 13px 15px; border: 1px solid #d7e6f5; border-radius: 10px; background: #f0f7ff; font-size: 13px; }
.model-choice-guide p { margin: 5px 0 0; line-height: 1.5; }
.model-choice-guide a { font-weight: 700; }
.model-section { margin: 0 0 16px; }
.model-section h3 { margin: 0 0 9px; font-size: 14px; }
.model-section-help { margin: -2px 0 12px; color: var(--muted); font-size: 13px; }
.model-other { margin: 8px 0 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.model-other summary { cursor: pointer; font-weight: 700; }
.model-other .model-grid { margin-top: 14px; }
.model-empty { margin: 8px 0; color: var(--muted); }
.provider-archived-models { margin-top: 12px; color: var(--muted); overflow-wrap: anywhere; }
.provider-archived-models p { margin: 8px 0 0; }

#notice.notice-banner { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#notice.notice-banner[hidden] { display: none; }
#notice.notice-banner #notice-text { flex: 1; }
.notice-close { flex: none; margin: -3px -5px 0 0; padding: 0 6px; border: 0; background: transparent; color: #7b5b16; font-size: 22px; line-height: 1.1; }
.notice-close:hover { background: #f8e7b0; color: #624708; transform: none; }

.action-confirm { width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 24px 70px #11182755; }
.action-confirm form { padding: clamp(20px, 5vw, 30px); }
.action-confirm h2 { margin-bottom: 12px; }
.action-confirm #action-confirm-message { white-space: pre-line; overflow-wrap: anywhere; }
.action-confirm .dialog-actions { justify-content: flex-end; margin-top: 24px; }
.action-confirm .danger-action { color: #fff; background: #bf3d42; }
.action-confirm .danger-action:hover { background: #a52e33; }
@media (max-width: 600px) { .action-confirm .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; } }

.list-toolbar label {
  width: min(420px, 100%);
  margin: 0;
}

.list-toolbar span {
  color: var(--muted);
  font-size: 14px;
  padding-bottom: 11px;
}

.test-data-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 7px 10px;
  border-radius: 9px;
  background: #fff7dd;
  color: #7b5b16;
  font-size: 12px;
  white-space: nowrap;
}

.test-data-control input {
  width: auto;
  margin: 0;
}

.agent-card small {
  width: fit-content;
  padding: 5px 9px;
  border-radius: 999px;
  background: #eef0f7;
  color: #525c70;
  font-weight: 650;
}

.agent-card button {
  font-size: 14px;
  width: 100%;
  margin: 8px 0 0;
}

.danger-action {
  background: transparent;
  border: 1px solid #e5b6b6;
  color: var(--danger);
}

.danger-action:hover {
  background: #fdeaea;
  color: #9d3030;
}

.agent-flow-help ol { margin: 12px 0; padding-left: 22px; color: #4e5669; line-height: 1.65; }
.field-hint { display: block; margin-top: 6px; font-size: 12.5px; line-height: 1.55; color: var(--muted); font-weight: 500; }
.form-grid p.field-hint { margin: 4px 0 10px; font-weight: 400; }
.detail-card { scroll-margin-top: 92px; }
.detail-card-open { animation: detail-card-open .35s ease; border-color: #8b83ef; box-shadow: 0 0 0 4px #eceafd, var(--shadow); }
@keyframes detail-card-open { from { opacity: .45; transform: translateY(12px); } to { opacity: 1; transform: none; } }
#knowledge-access-status[data-state="allowed"] { background: #e6f6ed; color: #18794e; }
#knowledge-access-status[data-state="denied"] { background: #fff4d6; color: #8a5a00; }
.setup-step { transition: border-color .18s ease, background .18s ease, box-shadow .18s ease; }
.setup-step[data-state="missing"] { border-color: #e4b64e; background: #fffaf0; box-shadow: 0 0 0 3px #fff0c2; }
.setup-step[data-state="ready"] { border-color: #8bcaaa; background: #f8fffb; }
.setup-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setup-state-badge { padding: 5px 9px; border-radius: 999px; background: #eef0f4; color: #5f6675; font-size: 12px; font-weight: 750; white-space: nowrap; }
.setup-step[data-state="missing"] .setup-state-badge { background: #fff0c2; color: #805500; }
.setup-step[data-state="ready"] .setup-state-badge { background: #e1f4e9; color: #18794e; }
.setup-status[data-state="missing"] { background: #fff0c2; color: #704b00; }
.setup-status[data-state="ready"] { background: #e1f4e9; color: #146b43; }
.agent-state { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.agent-state::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 4px #fff2db; }
.agent-state.ready::before { background: var(--success); box-shadow: 0 0 0 4px #e2f5ec; }
.agent-state.error::before { background: var(--danger); box-shadow: 0 0 0 4px #fde8e8; }
.agent-advanced { margin-top: 14px; padding-top: 4px; border-top: 1px solid var(--line); }
.agent-advanced summary { color: var(--muted); font-size: 14px; }
.agent-advanced button { margin-top: 8px; }
.agent-knowledge { margin-top: 18px; padding: 18px; border-color: #d9d5ff; background: #faf9ff; }
.agent-knowledge > p:first-of-type { margin: 4px 0 14px; color: #4e5669; line-height: 1.5; }
.knowledge-mode { display: flex; align-items: flex-start; gap: 11px; margin: 9px 0; padding: 13px; border: 1px solid var(--line); border-radius: 11px; background: #fff; cursor: pointer; }
.knowledge-mode:has(input:checked) { border-color: #756bef; background: #efedff; box-shadow: inset 0 0 0 1px #756bef; }
.knowledge-mode input { width: auto; margin: 3px 0 0; }
.knowledge-mode span,.knowledge-mode small { display: block; }
.knowledge-mode small { margin-top: 4px; color: var(--muted); font-weight: 500; line-height: 1.4; }
#agent-knowledge-bases { margin-top: 14px; padding: 14px; border: 1px solid #d9dce7; border-radius: 11px; background: #fff; }
.knowledge-base-picker { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.knowledge-base-picker .check { margin: 0; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: #f8f9fc; }
#agent-knowledge-status[data-state="ready"] { background: #e6f6ed; color: #18794e; }
#agent-knowledge-status[data-state="plain"] { background: #eef0f4; color: #525c70; }
#agent-knowledge-status[data-state="warning"] { background: #fff4d6; color: #8a5a00; }

.agent-start-guide {
  margin: 0 0 24px;
  padding: 20px 24px;
  border: 1px solid #d9d5ff;
  border-radius: 14px;
  background: #f4f2ff;
}
.agent-start-guide h2 { margin-bottom: 10px; font-size: 18px; }
.agent-start-guide ol { display: grid; gap: 8px; margin: 0 0 10px; padding-left: 22px; }
.agent-start-guide li { line-height: 1.5; }
.agent-start-guide p { margin-bottom: 0; font-size: 14px; }
.agent-instruction-examples { margin: -4px 0 18px; color: var(--muted); font-size: 14px; }
.agent-instruction-examples .button-row { margin-top: 9px; flex-wrap: wrap; }
.agent-instruction-examples button { padding: 8px 12px; font-size: 14px; }
#editor > form > details.form-card { margin-top: 16px; }
#editor > form > details.form-card > summary { font-size: 16px; }
#editor > form > details.form-card > p { margin: 12px 0 8px; }
#editor .dialog-actions { position: sticky; bottom: 0; z-index: 5; padding: 14px 0 4px; background: #fff; border-top: 1px solid var(--line); }

dialog {
  max-height: calc(100dvh - 24px);
  overscroll-behavior: contain;
}

.document-list-heading { margin: 24px 0 4px; }
.document-viewer { width: min(960px, 95vw); }
.document-viewer-body { padding: 28px; }
.document-viewer .dialog-heading { align-items: flex-start; gap: 16px; }
.document-viewer .dialog-heading p { margin-bottom: 0; }
#document-viewer-content {
  min-height: min(60vh, 640px);
  max-height: 65vh;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.dialog-heading {
  position: sticky;
  top: 0;
  z-index: 4;
  padding-bottom: 12px;
  background: #fff;
}

.model-picker {
  margin: 18px 0;
  padding: 18px;
  background: #f8f8fc;
}

.model-picker legend {
  font-size: 14px;
}

.model-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.model-choice {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  cursor: pointer;
  min-height: 72px;
}

.model-choice:has(input:checked) {
  border-color: #756bef;
  background: #efedff;
  box-shadow: inset 0 0 0 1px #756bef;
}

.model-choice:has(input:disabled) { cursor: not-allowed; opacity: .72; }

.model-choice input {
  width: auto;
  margin: 3px 0 0;
}

.model-choice span,
.model-choice small {
  display: block;
}
.model-guide-badge { display: inline-block; margin: 5px 0 0; padding: 2px 7px; border-radius: 999px; background: #e8f0fc; color: #28527d; font-size: 11px; font-style: normal; font-weight: 750; }

.model-choice small {
  margin-top: 4px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}

.model-choice-heading {
  align-items: center;
  display: flex !important;
  flex-flow: row wrap;
  gap: 6px;
}

.model-budget-badge {
  background: #e8f7ef;
  border: 1px solid #bce8cf;
  border-radius: 999px;
  color: #176b43;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: .04em;
  padding: 2px 6px;
  text-transform: uppercase;
}

.custom-model {
  margin-top: 16px;
}

.model-help {
  margin: 10px 0 0;
  font-size: 13px;
}

.model-picker.invalid {
  border-color: var(--danger);
}

.provider-grid {
  display: block;
}

.provider-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 22px 0 14px;
}

.provider-tab {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  color: #2d3547;
  text-align: left;
}

.provider-tab:hover {
  border-color: #bbb6f7;
  background: #f8f7ff;
  transform: none;
}

.provider-tab.active {
  border-color: #756bef;
  background: #f0efff;
  box-shadow: inset 0 0 0 1px #756bef;
}

.provider-tab strong {
  align-self: center;
  font-size: 16px;
}

.provider-tab small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}

.provider-tab-status {
  align-self: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef0f4;
  color: #5f6675;
  font-size: 11px;
  white-space: nowrap;
}

.provider-tab-status[data-status="available"] { background: #e6f6ed; color: #18794e; }
.provider-tab-status[data-status="not_checked"] { background: #fff4d6; color: #8a5a00; }
.provider-tab-status[data-status="failed"] { background: #fdeaea; color: #b42318; }

.provider-form {
  margin: 0;
  padding: 26px;
  animation: fade .16s ease;
}

.provider-form > label:not([hidden]) {
  max-width: 620px;
}

.provider-form .model-picker {
  margin-top: 22px;
  border-color: #d9dce7;
  background: #f8f9fc;
}

.provider-form .button-row {
  align-items: center;
  margin-top: 20px;
}

.provider-form .provider-status {
  margin: 14px 0 0;
}

.model-preview-badge {
  background: #fff4df;
  border: 1px solid #f0d49b;
  border-radius: 999px;
  color: #8a5a00;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: .04em;
  padding: 2px 6px;
  text-transform: uppercase;
}

.provider-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 6px;
}

.provider-heading strong,.provider-heading small { display: block; }
.provider-heading small { margin-top: 4px; color: var(--muted); }
.provider-badge { padding: 5px 9px; border-radius: 999px; background: #eef0f4; color: #5f6675; font-size: 12px; white-space: nowrap; }
.provider-badge[data-status="available"] { background: #e6f6ed; color: #18794e; }
.provider-badge[data-status="not_checked"] { background: #fff4d6; color: #8a5a00; }
.provider-badge[data-status="failed"] { background: #fdeaea; color: #b42318; }

.chat-messages article.user {
  margin-left: auto;
  background: #eceafd;
  border-color: #d8d4ff;
}

/* The id outranks style.css's ".chat-messages article:has(strong:first-child)"
   rule, which right-aligned every message. */
#chat-messages article.assistant {
  margin-left: 0;
  margin-right: auto;
}

/* "…" while the agent works, then the reply appears word by word. The
   typing bubble is only as wide as its label and dots. */
#chat-messages article.typing { width: fit-content; min-width: 0; padding: 10px 14px; }
.chat-messages article.typing p { display: flex; gap: 4px; align-items: center; min-height: 1.55em; }
.chat-messages article.typing p span { width: 7px; height: 7px; border-radius: 50%; background: #9aa1b2; animation: chat-typing-dot 1.2s infinite ease-in-out; }
.chat-messages article.typing p span:nth-child(2) { animation-delay: .15s; }
.chat-messages article.typing p span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-typing-dot { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.chat-messages .word { display: inline-block; max-width: 100%; animation: chat-word-in .28s ease-out both; }
@keyframes chat-word-in { from { opacity: 0; clip-path: inset(0 100% 0 0); transform: translateY(2px); } to { opacity: 1; clip-path: inset(0 0 0 0); transform: none; } }
@media (prefers-reduced-motion: reduce) { .chat-messages article.typing p span, .chat-messages .word { animation: none; } }

.widget-format-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.widget-format-picker label {
  display: flex;
  gap: 10px;
  margin: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
}

.widget-format-picker label:has(input:checked) {
  border-color: var(--primary);
  background: #efedff;
}

.widget-format-picker input { width: auto; margin: 3px 0 0; }
.widget-format-picker b,.widget-format-picker small { display: block; }
.widget-format-picker small { margin-top: 4px; color: var(--muted); font-weight: 500; }

.widget-preview {
  --widget-color: #5146e5;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 18px;
  border: 1px dashed #cbd0dc;
  border-radius: 14px;
  background: #f7f8fb;
}

.widget-preview > span {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--widget-color);
  color: #fff;
  font-size: 20px;
}

.widget-preview strong,.widget-preview small { display: block; }
.widget-preview small { margin-top: 4px; color: var(--muted); }
.widget-preview.inline { border-style: solid; background: #fff; }
.widget-preview.banner { border-style: solid; border-left: 7px solid var(--widget-color); }
.widget-card-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.widget-card-heading h3 { margin-bottom: 0; }
.widget-card-heading small { margin: 0; padding: 5px 9px; border-radius: 999px; }
.widget-active { color: #18794e; background: #e6f6ed; }
.widget-disabled { color: #6b7280; background: #eef0f4; }
#widgets-list textarea { font: 12px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace; resize: none; }

@media (min-width: 701px) and (max-width: 900px) {
  main { padding: 0 20px 40px; }
  .app-shell { grid-template-columns: 205px minmax(0, 1fr); gap: 24px; }
  .sidebar { position: sticky; top: 92px; height: calc(100vh - 115px); z-index: auto; background: transparent; border-right: 1px solid var(--line); border-bottom: 0; padding: 24px 8px 20px 0; display: flex; flex-direction: column; overflow: visible; }
  .nav-item { width: 100%; white-space: normal; }
  .nav-label { display: block; }
  #authoring-nav { display: block; }
  .account-link { margin-top: auto; }
  .content { padding-top: 34px; }
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .model-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.mobile-section-picker { display: none; }
@media (min-width: 701px) and (max-width: 900px) {
  .sidebar { display: block; width: 100%; overflow: visible; }
  .mobile-section-picker { display: grid; gap: 4px; max-width: 440px; margin: 0; color: var(--muted); font-size: 12px; font-weight: 750; }
  .mobile-section-picker select { margin: 0; background: #fff; color: #273047; font-size: 15px; font-weight: 700; }
  .sidebar .nav-item { display: none; }
}
@media (max-width: 700px) {
  :root { font-size: 15px; }
  html,body { max-width: 100%; overflow-x: hidden; }
  body { padding-bottom: env(safe-area-inset-bottom); }
  button,input,textarea,select { min-height: 44px; }
  button { touch-action: manipulation; }
  .setup-summary { align-items: flex-start; flex-direction: column; gap: 7px; }
  .knowledge-base-picker { grid-template-columns: 1fr; }

  .topbar {
    height: 60px;
    padding: 0 max(12px, env(safe-area-inset-left));
    gap: 10px;
  }
  .brand { min-width: 0; gap: 8px; }
  .brand-mark { width: 30px; height: 30px; flex: none; }
  .organization,.test-data-control { display: none !important; }
  #logout { margin-left: auto; padding: 9px 12px; }

  main { padding: 0 12px 32px; }
  #notice { top: 68px; margin: 8px 0 0; }
  #notice:not(:empty) { padding: 11px 13px; }
  .auth-card { width: 100%; margin: 24px 0; padding: 22px; border-radius: 16px; }
  .auth-card button { width: 100%; }

  .app-shell { display: block; }
  .sidebar {
    position: sticky;
    top: 60px;
    z-index: 18;
    width: calc(100% + 24px);
    height: auto;
    margin: 0 -12px;
    padding: 8px 12px;
    display: block;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(246,247,251,.96);
    backdrop-filter: blur(12px);
  }
  .mobile-section-picker { display: grid; gap: 4px; width: 100%; margin: 0; color: var(--muted); font-size: 12px; font-weight: 750; }
  .mobile-section-picker select { margin: 0; background: #fff; color: #273047; font-size: 15px; font-weight: 700; }
  .sidebar .nav-item { display: none; }
  .nav-label { display: none; }
  .nav-item {
    width: auto;
    min-height: 40px;
    flex: none;
    gap: 7px;
    padding: 9px 11px;
    border-radius: 9px;
    font-size: 14px;
    white-space: nowrap;
  }
  .nav-item span { width: auto; }
  .account-link { margin: 0; }

  .content { padding-top: 20px; }
  .panel { max-width: none; }
  h1 { font-size: clamp(28px,9vw,34px); line-height: 1.08; letter-spacing: -.8px; }
  h2 { font-size: 20px; }
  .page-heading { display: grid; gap: 15px; margin-bottom: 20px; }
  .page-heading > button { width: 100%; }

  .status-grid,.grid,.form-grid,.split-forms,.chat-toolbar { grid-template-columns: 1fr; }
  .status-grid,.grid { gap: 10px; }
  .status-card { padding: 15px; }
  .next-step { grid-template-columns: auto minmax(0,1fr); gap: 13px; padding: 18px; border-radius: 15px; }
  .next-step button { grid-column: 1 / -1; width: 100%; }
  .step-number { width: 40px; height: 40px; }
  .help-card,.settings-section,.detail-card { padding: 16px; border-radius: 14px; }
  .flow { display: grid; gap: 7px; }
  .flow span { width: 100%; padding: 10px; }
  .flow b { display: none; }

  article { padding: 16px; }
  article button { width: 100%; margin: 8px 0 0; }
  .explain { margin-bottom: 14px; }
  .form-card { padding: 16px; margin: 12px 0; }
  .form-card > button,.detail-card > button { width: 100%; }
  .form-title { display: grid; gap: 4px; }
  label { margin: 11px 0; }
  input,textarea,select { padding: 11px; }
  fieldset { min-width: 0; padding: 8px 11px; }
  .check { display: flex; margin: 10px 0; }
  .button-row { display: grid; grid-template-columns: 1fr; gap: 9px; }
  .button-row button { width: 100%; margin: 0; }

  .chat-toolbar { gap: 8px; }
  .chat-messages { min-height: 280px; max-height: 52dvh; margin: 12px 0; padding: 8px; }
  .chat-messages article { max-width: 92%; padding: 11px 12px; }
  .composer { padding: 14px; }
  .composer textarea { min-height: 100px; }
  .composer > button { width: 100%; }
  .composer-options { display: grid; }

  .list { gap: 8px; }
  .list > p { align-items: stretch; flex-direction: column; padding: 12px; }
  .list > p button { width: 100%; }
  .secret-card { padding: 16px; }
  .inline-status { padding: 11px 12px; }
  summary { min-height: 44px; display: flex; align-items: center; }

  .table-scroll {
    width: 100%;
    margin: 14px 0;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
  }
  .table-scroll table { min-width: 680px; }
  th,td { padding: 10px; }

  .list-toolbar { align-items: stretch; flex-direction: column; gap: 7px; }
  .list-toolbar label { width: 100%; }
  .list-toolbar span { padding: 0; }
  .agent-card button { min-height: 44px; }

  .provider-tabs {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 8px;
    margin: 18px 0 12px;
    padding: 0;
    overflow: visible;
  }
  .provider-tab { width: 100%; min-width: 0; min-height: 70px; grid-template-columns: 1fr; padding: 10px; overflow-wrap: anywhere; }
  .provider-tab small { display: none; }
  .provider-tab-status { white-space: normal; }
  .provider-form { padding: 16px; }
  .provider-form > label:not([hidden]) { max-width: none; }
  .provider-form .model-picker { margin: 18px -4px 0; padding: 13px; }
  .model-grid,.widget-format-picker { grid-template-columns: 1fr; }
  .model-choice { min-height: 0; padding: 12px; }
  .model-choice-heading { gap: 5px; }

  .widget-preview { align-items: flex-start; padding: 14px; }
  .widget-preview > span { width: 42px; height: 42px; }
  #widgets-list textarea { min-height: 92px; }

  dialog {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 8px);
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
  }
  dialog form { padding: 20px 16px 16px; }
  .dialog-heading { top: 0; padding-bottom: 10px; }
  .icon-button { width: 44px; min-width: 44px; padding: 0; }
  .dialog-actions {
    position: sticky;
    bottom: -16px;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 16px -16px -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(12px);
  }
  .dialog-actions button { width: 100%; padding-inline: 10px; }
  .dialog-actions #activate-agent { grid-column: 1 / -1; grid-row: 1; }
}

.setup-flow {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
  padding: 18px;
  background: #f7f6ff;
  border-color: #dcdaff;
}

.setup-flow > div {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.setup-flow b {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
}

.setup-flow span {
  color: #4e5669;
  line-height: 1.5;
}

.setup-flow code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #e7e5ff;
  color: #3f36bd;
}

#channel-next-step {
  background: #e8f7ef;
  color: #176d43;
}

.fallback-replies { margin-top: 14px; display: grid; gap: 10px; }
.fallback-replies h4 { margin: 0; font-size: 15px; }
#fallback-list { display: grid; gap: 10px; }
.fallback-reply { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #f8f9fc; }
.fallback-reply textarea { min-height: 0; }
.fallback-reply-actions { display: flex; justify-content: flex-end; }
.knowledge-inspector{display:grid;gap:.75rem;margin-top:1rem}.knowledge-inspector article{border:1px solid #dfe3ee;border-radius:12px;padding:.8rem;background:#fff}.knowledge-inspector h4{margin:0 0 .4rem}.knowledge-inspector p{margin:.3rem 0}.knowledge-inspector ul{margin:.5rem 0 0;padding-left:1.3rem}.document-provenance{margin:.5rem 0 1rem}.document-viewer .document-provenance{border-top:1px solid #dfe3ee;padding-top:1rem}
.hub-grid,.agent-detail-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:1rem}
.hub-grid>article,.agent-detail-section,.agent-version-card{border:1px solid var(--border,#d9dfeb);border-radius:14px;padding:1rem;margin:1rem 0;background:var(--surface,#fff)}
.agent-detail-guide{padding:1.2rem 1.35rem;margin:1rem 0;border:1px solid #dcd8fc;border-radius:16px;background:#f3f1ff}
.agent-detail-guide h2{margin:0 0 .5rem;font-size:1.3rem}
.agent-detail-guide p{margin:0 0 .75rem}
.agent-detail-guide ol{margin:.4rem 0 1rem;padding-left:1.3rem;line-height:1.6}
.agent-detail-guide li+li{margin-top:.25rem}
.agent-detail-guide-actions{display:flex;flex-wrap:wrap;gap:.55rem}
.agent-detail-guide ol{list-style:none;padding:0;display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:.55rem}
.agent-detail-guide ol li{min-width:0;margin:0;padding:.7rem;background:#fff;border:1px solid #dedbf7;border-radius:10px}
.agent-detail-guide ol li button{width:100%;text-align:left;margin:0}
.agent-detail-guide ol li small{display:block;margin:.45rem 0 0;color:#596174;line-height:1.4}
.agent-detail-guide.compact-guide{padding:.75rem 1rem;margin:.65rem 0}
.agent-detail-guide.compact-guide h2{font-size:1rem}
.agent-detail-guide.compact-guide p{font-size:.85rem;margin-bottom:.4rem}
.agent-detail-guide.compact-guide ol{display:none}
.agent-detail-guide.compact-guide .agent-detail-guide-actions button{padding:.45rem .7rem;font-size:.85rem}
.publishing-deployment-states{margin-top:1rem;padding:.8rem 1rem;border:1px solid #d9e1e8;border-radius:10px;background:#f8fafc}
.publishing-deployment-states h3{margin:0 0 .5rem;font-size:1rem}
.publishing-deployment-states p{margin:.4rem 0;overflow-wrap:anywhere}
.publishing-launch-step{border-color:#dcd8fc;background:#f3f1ff}
.publishing-launch-step p{margin-bottom:.5rem}
.publishing-validation,.publishing-deployment{scroll-margin-top:6rem}
.agent-detail-mobile-nav{display:none}
.detail-tabs{display:flex;flex-wrap:wrap;gap:.45rem;padding:.4rem 0 1rem}
.detail-tabs button{background:#fff;color:#354059;border:1px solid #dfe3ee;padding:.6rem .85rem;font-size:.9rem}
.detail-tabs button:hover{background:#eeecff;color:#4036bd;transform:none}
.detail-tabs button.active{background:#5146e5;border-color:#5146e5;color:#fff;font-weight:700}
.agent-detail-overview{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem}
.agent-detail-overview>.agent-detail-section{margin:0}
.agent-detail-overview>.agent-detail-section:first-child,.agent-detail-overview>.agent-detail-section:nth-child(4),.agent-detail-overview>.agent-detail-section:nth-child(7),.agent-detail-overview>.inline-status{grid-column:1/-1}
.agent-detail-item{display:flex;flex-direction:column;gap:.3rem;min-width:0;overflow-wrap:anywhere}
.agent-detail-item small{opacity:.7}
.agent-card-facts{font-size:.9rem;overflow-wrap:anywhere}
.agent-version-card pre,#agent-detail-body pre{white-space:pre-wrap;overflow-wrap:anywhere;max-height:25rem;overflow:auto}
@media(max-width:700px){.hub-grid,.agent-detail-grid,.agent-detail-overview{grid-template-columns:1fr}.detail-tabs{display:none}.agent-detail-mobile-nav{display:block;margin:1rem 0}.agent-detail-mobile-nav label{display:grid;gap:.4rem;font-weight:700}.agent-detail-mobile-nav select{width:100%}.agent-detail-guide-actions button{width:100%}}
@media(max-width:900px){#admin-navigation{display:contents}}

/* Phase 3 channel and presentation editor. */
.channel-presentation-section { margin: 16px 0; }
.channel-presentation-section > h2 { margin-top: 0; }
.channel-presentation-section > .detail-card { margin: 12px 0; }
.channel-setup { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.channel-setup .form-grid { align-items: start; }
.channel-capabilities { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px 16px; border: 1px solid var(--line); border-radius: 10px; }
.channel-capabilities legend { font-weight: 700; padding: 0 6px; }
.channel-capabilities .check { margin: 0; }
@media (max-width: 700px) { .channel-capabilities { grid-template-columns: 1fr; } .channel-presentation-section .button-row { display: flex; flex-wrap: wrap; } }

/* Phase 4 publication review. */
.publishing-header,.publishing-card{margin:16px 0}
.publishing-diff-group{border-top:1px solid var(--line);padding:12px 0}
.publishing-diff-row{display:grid;grid-template-columns:minmax(130px,1fr) minmax(0,2fr);gap:4px 16px;margin:8px 0;overflow-wrap:anywhere}
.publishing-diff-row small{grid-column:2;opacity:.75}
.publishing-version{padding:10px 0;border-top:1px solid var(--line)}
@media(max-width:700px){.publishing-diff-row{grid-template-columns:1fr}.publishing-diff-row small{grid-column:1}}

@media (max-width: 700px) {
  #editor .dialog-actions { bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); margin-bottom: 0; }
}

/* Selection controls keep dark labels on light surfaces in every state. */
:is(.conv-open,.nav-item,.provider-tab,.detail-tabs button,.org-primary-nav button,.org-settings-links>button,.cm-template-list button):is(:hover,:active,.active,[aria-current="true"],[aria-current="page"],[aria-selected="true"]){background:#ecebff;color:#172033;transform:none}
.conv-open:is(:hover,:active,:focus-visible,[aria-current="true"]){background:#ecebff;color:#172033;transform:none}
.conv-open:is(:hover,:active,:focus-visible,[aria-current="true"]) :is(.conv-agent,.conv-presence,.conv-last){color:#536078}
.conv-open:is(:hover,:active,:focus-visible,[aria-current="true"]) .conv-unread-count{color:#b42318}
