.ai-settings {
  margin-bottom: 1rem;
}

.ai-settings .field-note {
  margin: 0.35rem 0 0;
}

.ai-settings input[type="submit"] {
  margin-top: 1rem;
}

.ai-workspace {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 560px;
  height: calc(100dvh - 114px);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.ai-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 20px 14px;
  background: #faf9fb;
  border-right: 1px solid var(--border);
}

.ai-sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 4px 22px;
}

.ai-sidebar-heading > a {
  color: var(--text);
  font-weight: 800;
  font-size: 16px;
}

.ai-sidebar .button {
  width: 100%;
}

.ai-caption {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .07em;
  margin: 26px 8px 12px;
}

.ai-conversation-links {
  overflow-y: auto;
  flex: 1;
}

.ai-conversation-link {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  margin-bottom: 5px;
  border-radius: 6px;
  color: var(--text);
}

.ai-conversation-link strong {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-conversation-link span {
  color: var(--muted);
  font-size: 11px;
}

.ai-conversation-link:hover {
  background: #f1edf1;
  text-decoration: none;
}

.ai-conversation-link.is-current {
  background: var(--brand-primary-soft);
  color: var(--brand-primary-dark);
}

.ai-sidebar-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 5px 0;
  margin-top: 15px;
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
}

.ai-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.ai-conversation-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 21px 28px;
  border-bottom: 1px solid var(--border-soft);
}

.ai-conversation-heading .ai-caption {
  margin: 0 0 7px;
}

.ai-conversation-heading h1 {
  font-size: 18px;
  line-height: 1.4;
  margin: 0;
  overflow-wrap: anywhere;
}

.ai-model-label {
  font-size: 12px;
  white-space: nowrap;
  color: var(--muted);
}

.ai-feed {
  flex: 1;
  min-height: 0;
}

.ai-feed-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 235px;
  height: 100%;
}

.ai-transcript {
  overflow-y: auto;
  padding: 28px 32px;
  overscroll-behavior: contain;
}

.ai-context {
  border-left: 1px solid var(--border-soft);
  padding: 24px 20px;
  overflow-y: auto;
  background: #fdfdfd;
}

.ai-context h2 {
  margin: 0 0 13px;
  font-size: 13px;
}

.ai-context p, .ai-context li {
  font-size: 12px;
  line-height: 1.65;
  color: var(--muted);
}

.ai-context ul {
  padding-left: 17px;
}

.ai-context hr {
  border: 0;
  border-top: 1px solid var(--border-soft);
  margin: 26px 0;
}

.ai-context .ai-saved-note {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  border-left: 3px solid var(--brand-primary);
  padding-left: 12px;
}

.ai-note-caption {
  font-size: 11px;
  color: var(--muted);
}

.ai-turn {
  max-width: 920px;
  margin: 0 auto 30px;
}

.ai-message {
  padding: 17px 20px;
  border-radius: 8px;
}

.ai-message--user {
  background: #f5f3f6;
  margin: 0 0 18px 40px;
}

.ai-message--assistant {
  padding-left: 0;
  padding-right: 0;
}

.ai-message-author {
  font-size: 12px;
  font-weight: 800;
  display: inline-block;
  color: var(--brand-primary-dark);
  margin-bottom: 10px;
}

.ai-message--user .ai-message-author {
  color: var(--muted);
}

.ai-message-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.ai-message-header .pill {
  font-size: 10px;
  padding: 3px 8px;
}

.ai-message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.7;
  font-size: 14px;
}

.ai-formatted-response {
  white-space: normal;
  line-height: 1.65;
}

.ai-formatted-response > :first-child { margin-top: 0; }
.ai-formatted-response > :last-child { margin-bottom: 0; }
.ai-formatted-response p { margin: 0 0 1em; }
.ai-formatted-response :is(h1, h2, h3, h4, h5, h6) {
  margin: 1.4em 0 0.6em;
  line-height: 1.3;
  color: var(--text);
  letter-spacing: 0;
}
.ai-formatted-response h1 { font-size: 1.35rem; }
.ai-formatted-response h2 { font-size: 1.2rem; }
.ai-formatted-response :is(h3, h4, h5, h6) { font-size: 1.05rem; }
.ai-formatted-response :is(ul, ol) { margin: 0 0 1em; padding-left: 1.6em; }
.ai-formatted-response li { margin: 0.3em 0; }
.ai-formatted-response li > p { margin-bottom: 0.4em; }
.ai-formatted-response blockquote {
  margin: 1em 0;
  padding: 0.2em 1em;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.ai-formatted-response code {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: var(--table-header);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.ai-formatted-response pre {
  margin: 1em 0;
  padding: 1em;
  overflow-x: auto;
  background: var(--table-header);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  white-space: pre;
}
.ai-formatted-response pre code { padding: 0; background: none; }
.ai-formatted-response table {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  margin: 1em 0;
  border-collapse: collapse;
}
.ai-formatted-response :is(th, td) { padding: 0.5em 0.8em; border: 1px solid var(--border); }
.ai-formatted-response th { background: var(--table-header); text-align: left; }
.ai-formatted-response hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.ai-formatted-response .katex-display { overflow-x: auto; overflow-y: hidden; padding: 0.3em 0; }
.ai-formatted-response .ai-math-source { white-space: pre-wrap; overflow-wrap: anywhere; }

.ai-action-receipt {
  background: var(--success-bg);
  color: var(--success-text);
  padding: 9px 12px;
  margin: 2px 0 14px;
  border-radius: 5px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.ai-action-receipt span {
  margin-right: 6px;
}

.ai-run-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

.ai-run-actions:empty {
  display: none;
}

.ai-run-actions .button {
  font-size: 12px;
  padding: 7px 12px;
}

.ai-run-actions > span {
  font-size: 11px;
}

.ai-run-error {
  border-left: 3px solid #bf8b22;
  background: var(--warning-bg);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
}

.ai-progress {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--muted);
}

.ai-working-dot {
  width: 7px;
  height: 7px;
  background: var(--brand-primary);
  border-radius: 50%;
  animation: ai-pulse 1.4s ease-in-out infinite;
}

@keyframes ai-pulse {
  50% {
    opacity: .3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-working-dot {
    animation: none;
  }
}

.ai-run-details {
  margin-top: 15px;
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.ai-run-details summary {
  cursor: pointer;
  line-height: 1.6;
}

.ai-run-details dl {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 6px 12px;
  padding: 12px;
  background: var(--page-bg);
}

.ai-run-details dt, .ai-run-details dd {
  margin: 0;
}

.ai-run-details p {
  line-height: 1.6;
}

.ai-composer {
  padding: 18px 28px 15px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.ai-composer form {
  margin: 0;
}

.ai-composer-label {
  font-size: 12px;
  font-weight: 700;
  display: block;
  margin-bottom: 8px;
}

.ai-composer textarea {
  display: block;
  width: 100%;
  resize: vertical;
  min-height: 76px;
  max-height: 180px;
  font: inherit;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
}

.ai-composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.ai-composer-actions span {
  color: var(--muted);
  font-size: 11px;
}

.ai-composer-actions input[type="submit"] {
  width: auto;
  margin: 0;
}

.ai-footnote {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
  margin: 12px 0 0;
}

.ai-configuration-notice {
  font-size: 13px;
  background: var(--warning-bg);
  padding: 12px;
  margin-top: 0;
}

.ai-client-error {
  color: var(--danger-text);
  background: var(--danger-bg);
  padding: 12px;
  font-size: 13px;
}

.ai-empty {
  max-width: 540px;
  margin: 40px auto;
  text-align: center;
  padding: 10px;
}

.ai-monogram {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  font-size: 14px;
  font-weight: 800;
}

.ai-empty h2 {
  font-size: 20px;
  line-height: 1.4;
  margin-top: 20px;
}

.ai-empty p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.ai-starters {
  display: grid;
  gap: 10px;
  margin: 26px auto;
  max-width: 430px;
}

.ai-starters button {
  display: flex;
  justify-content: space-between;
  text-align: left;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ai-starters button:hover {
  border-color: var(--brand-primary);
  background: var(--brand-primary-soft);
}

.ai-section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.ai-section-heading h2 {
  font-size: 17px;
}

.ai-conversation-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 20px 0;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}

.ai-conversation-row strong {
  overflow-wrap: anywhere;
}

.ai-conversation-row span {
  font-size: 12px;
  white-space: nowrap;
  color: var(--muted);
}

.ai-pagination {
  display: flex;
  justify-content: space-between;
  padding-top: 20px;
}

@media (max-width: 1200px) {
  .ai-workspace {
    grid-template-columns: 210px minmax(0, 1fr);
  }
  .ai-feed-layout {
    grid-template-columns: minmax(0, 1fr) 190px;
  }
  .ai-transcript {
    padding: 22px;
  }
  .ai-conversation-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 900px) {
  .ai-workspace {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }
  .ai-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 14px;
  }
  .ai-sidebar-heading {
    margin-bottom: 12px;
  }
  .ai-sidebar > .ai-caption, .ai-conversation-links {
    display: none;
  }
  .ai-sidebar-footer {
    margin-top: 10px;
    padding-top: 12px;
  }
  .ai-feed-layout {
    grid-template-columns: 1fr;
  }
  .ai-transcript {
    max-height: 60dvh;
    min-height: 220px;
  }
  .ai-context {
    border-left: 0;
    border-top: 1px solid var(--border-soft);
    max-height: 180px;
  }
  .ai-context hr, .ai-context h2:nth-of-type(2), .ai-context ul, .ai-context > p:last-child {
    display: none;
  }
  .ai-composer, .ai-conversation-heading {
    padding: 18px;
  }
  .ai-composer-actions {
    align-items: flex-end;
  }
  .ai-message--user {
    margin-left: 10px;
  }
  .ai-conversation-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
}
