.ai-page {
  padding: 4rem 0 5.5rem;
}

.ai-shell {
  max-width: 900px;
  margin: 0 auto;
  min-width: 0;
}

.ai-heading {
  text-align: center;
  margin-bottom: 2rem;
}

.ai-heading .eyebrow {
  justify-content: center;
}

.ai-heading h1 {
  font-size: clamp(2.25rem, 6vw, 4rem);
  margin-bottom: 1rem;
}

.ai-heading p {
  max-width: 700px;
  margin: 0 auto;
  color: var(--text-muted);
  font-size: 1.04rem;
}

.ai-notice {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: 1rem 1.1rem;
  margin-bottom: 1.15rem;
  border: 1px solid rgba(241, 197, 14, .24);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text-muted);
  font-size: .92rem;
}

.ai-notice strong { color: var(--text-main); }
.ai-notice svg { width: 20px; height: 20px; flex: 0 0 auto; margin-top: .1rem; color: var(--accent); }

.ai-panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(22, 24, 28, .88);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.ai-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .018);
}

.ai-status { display: flex; align-items: center; gap: .5rem; min-width: 0; color: var(--text-muted); font-size: .85rem; }
.ai-status-dot { width: 8px; height: 8px; border-radius: 999px; background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, .1); flex: 0 0 auto; }
.ai-status-dot.busy { background: var(--accent); box-shadow: 0 0 0 4px rgba(241, 197, 14, .1); }
.ai-status-dot.paused { background: var(--accent); box-shadow: 0 0 0 4px rgba(241, 197, 14, .1); }
.ai-status-dot.problem { background: #ef4444; box-shadow: 0 0 0 4px rgba(239, 68, 68, .1); }

.ai-clear {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
  padding: .35rem .45rem;
  border-radius: 8px;
}

.ai-clear:hover,
.ai-clear:focus-visible { color: var(--accent); outline: none; background: rgba(255,255,255,.035); }
.ai-clear:disabled { opacity: .45; cursor: not-allowed; color: var(--text-dim); background: transparent; }

.ai-messages {
  min-width: 0;
  min-height: 370px;
  max-height: min(62vh, 650px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  padding: 1.25rem;
}

.ai-empty { max-width: 590px; margin: 4rem auto; text-align: center; color: var(--text-muted); }
.ai-empty h2 { color: var(--text-main); font-size: 1.35rem; margin-bottom: .65rem; }

.ai-examples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin-top: 1.35rem; }
.ai-example {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .8rem .9rem;
  background: rgba(255,255,255,.02);
  color: var(--text-muted);
  font: inherit;
  font-size: .84rem;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: border-color .2s var(--ease), color .2s var(--ease), transform .2s var(--ease);
}
.ai-example:hover,
.ai-example:focus-visible { border-color: var(--accent); color: var(--text-main); outline: none; transform: translateY(-2px); }
.ai-example:disabled,
.ai-quick-question:disabled { opacity: .5; cursor: wait; transform: none; }

.ai-message { display: flex; flex-direction: column; min-width: 0; max-width: 100%; margin-bottom: 1.15rem; }
.ai-message.user { align-items: flex-end; }
.ai-message.assistant { align-items: flex-start; }
.ai-message-label { margin-bottom: .35rem; color: var(--text-dim); font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }

.ai-bubble {
  box-sizing: border-box;
  min-width: 0;
  max-width: min(720px, 90%);
  padding: .9rem 1rem;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ai-message.user .ai-bubble { color: #201d05; background: linear-gradient(92deg, var(--accent), var(--accent-2)); border-bottom-right-radius: 5px; }
.ai-message.assistant .ai-bubble {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  color: var(--text-main);
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.ai-answer-paragraph { max-width: 100%; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-answer-paragraph + .ai-answer-paragraph,
.ai-code-block + .ai-answer-paragraph,
.ai-table-wrap + .ai-answer-paragraph,
.ai-answer-list + .ai-answer-paragraph { margin-top: .75rem; }

.ai-answer-heading {
  max-width: 100%;
  margin: 1.25rem 0 .7rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.ai-answer-heading:first-child { margin-top: 0; }
.ai-answer-heading + .ai-answer-heading { margin-top: 1rem; }

.ai-answer-rule {
  box-sizing: border-box;
  width: 100%;
  height: 0;
  margin: 1.15rem 0;
  border: 0;
  border-top: 1px solid var(--border-strong);
}
.ai-answer-rule:first-child { margin-top: 0; }
.ai-answer-rule:last-child { margin-bottom: 0; }

.ai-answer-quote {
  max-width: 100%;
  margin: 1rem 0 .15rem;
  padding: .2rem 0 .2rem .8rem;
  border-left: 3px solid var(--border-strong);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-answer-list {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  margin: .75rem 0 0;
  padding-inline-start: 0;
  list-style-position: inside;
  white-space: normal;
}
.ai-answer-list:first-child { margin-top: 0; }
.ai-answer-paragraph + .ai-answer-list,
.ai-code-block + .ai-answer-list,
.ai-table-wrap + .ai-answer-list { margin-top: .75rem; }
.ai-answer-list li { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.ai-answer-list li + li { margin-top: .35rem; }

.ai-inline-code {
  display: inline;
  max-width: 100%;
  padding: .12em .36em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(0, 0, 0, .28);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: .92em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ai-code-block {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: .75rem 0 0;
  padding: .8rem .9rem;
  overflow-x: auto;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: rgba(0, 0, 0, .34);
  white-space: pre;
  overflow-wrap: normal;
}
.ai-code-block:first-child { margin-top: 0; }
.ai-code-block code { display: block; min-width: max-content; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; font-size: .82rem; line-height: 1.55; white-space: pre; }

.ai-table-wrap {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: .75rem 0 0;
  overflow-x: auto;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: rgba(0, 0, 0, .18);
}
.ai-table-wrap:first-child { margin-top: 0; }
.ai-markdown-table { width: 100%; min-width: 420px; border-collapse: collapse; white-space: normal; font-size: .8rem; line-height: 1.5; }
.ai-markdown-table th,
.ai-markdown-table td { padding: .62rem .7rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.ai-markdown-table th:last-child,
.ai-markdown-table td:last-child { border-right: 0; }
.ai-markdown-table tbody tr:last-child td { border-bottom: 0; }
.ai-markdown-table th { color: var(--text-main); background: rgba(255,255,255,.055); font-weight: 700; }
.ai-markdown-table td { color: var(--text-muted); background: rgba(255,255,255,.015); }
.ai-markdown-table .ai-inline-code { color: var(--text-main); }

.ai-response-warning {
  box-sizing: border-box;
  min-width: 0;
  max-width: min(720px, 90%);
  margin-top: .6rem;
  padding: .72rem .82rem;
  border: 1px solid rgba(241, 197, 14, .32);
  border-radius: 10px;
  background: rgba(241, 197, 14, .075);
  color: var(--text-muted);
  font-size: .78rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.ai-response-warning strong { color: var(--accent); }
.ai-response-warning .ai-inline-code { color: var(--text-main); }

.ai-sources { display: flex; flex-wrap: wrap; min-width: 0; max-width: min(720px, 90%); margin-top: .5rem; gap: .45rem; }
.ai-source {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 100%;
  gap: .35rem;
  padding: .35rem .55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font-size: .74rem;
  overflow-wrap: anywhere;
  word-break: break-word;
  transition: color .2s var(--ease), border-color .2s var(--ease);
}
.ai-source:hover,
.ai-source:focus-visible { color: var(--accent); border-color: rgba(241,197,14,.5); outline: none; }
.ai-source svg { width: 12px; height: 12px; }

.ai-support-actions { display: flex; flex-wrap: wrap; min-width: 0; max-width: min(720px, 90%); margin-top: .65rem; gap: .55rem; }
.ai-support-actions .btn { --pad-y: 9px; --pad-x: 13px; font-size: .8rem; }

.ai-manual-context { display: none; box-sizing: border-box; min-width: 0; width: min(720px, 90%); max-width: 100%; margin-top: .65rem; }
.ai-manual-context.open { display: block; }
.ai-manual-context label { display: block; color: var(--text-muted); font-size: .8rem; margin-bottom: .35rem; }
.ai-manual-context textarea {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 145px;
  resize: vertical;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0d0e10;
  color: var(--text-main);
  font: inherit;
  font-size: .78rem;
  line-height: 1.45;
}

.ai-quick-suggestions { padding: .75rem 1rem .8rem; border-top: 1px solid var(--border); background: rgba(255, 255, 255, .012); }
.ai-quick-suggestions[hidden] { display: none; }
.ai-quick-label { display: block; margin-bottom: .5rem; color: var(--text-dim); font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.ai-quick-list { display: flex; flex-wrap: wrap; min-width: 0; gap: .45rem; }
.ai-quick-question {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: .42rem .65rem;
  background: rgba(255,255,255,.025);
  color: var(--text-muted);
  font: inherit;
  font-size: .74rem;
  line-height: 1.3;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: border-color .2s var(--ease), color .2s var(--ease), background .2s var(--ease);
}
.ai-quick-question:hover,
.ai-quick-question:focus-visible { border-color: rgba(241,197,14,.55); background: rgba(241,197,14,.055); color: var(--text-main); outline: none; }

.ai-composer { min-width: 0; padding: 1rem; border-top: 1px solid var(--border); background: rgba(14, 15, 17, .72); }
.ai-input-wrap { position: relative; min-width: 0; }
.ai-input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 88px;
  max-height: 210px;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  background: rgba(255,255,255,.025);
  color: var(--text-main);
  font: inherit;
  line-height: 1.5;
  padding: .9rem 1rem 2rem;
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.ai-input:focus { border-color: rgba(241,197,14,.7); box-shadow: 0 0 0 3px rgba(241,197,14,.08); }
.ai-input:disabled { opacity: .65; cursor: wait; }
.ai-counter { position: absolute; right: .75rem; bottom: .55rem; color: var(--text-dim); font-size: .72rem; pointer-events: none; }
.ai-composer-row { display: flex; align-items: center; justify-content: space-between; min-width: 0; gap: 1rem; margin-top: .7rem; }
.ai-composer-hint { color: var(--text-dim); font-size: .74rem; }
.ai-send[disabled] { opacity: .55; cursor: not-allowed; transform: none !important; }

.ai-footnote { margin-top: 1rem; color: var(--text-dim); font-size: .78rem; text-align: center; }
.ai-footnote a { color: var(--text-muted); text-decoration: underline; text-underline-offset: 2px; }

@media (max-width: 680px) {
  .ai-page { padding-top: 2.5rem; }
  .ai-messages { min-height: 330px; padding: .9rem; overscroll-behavior-y: auto; -webkit-overflow-scrolling: touch; }
  .ai-examples { grid-template-columns: 1fr; }
  .ai-bubble, .ai-response-warning, .ai-sources, .ai-support-actions, .ai-manual-context { max-width: 96%; }
  .ai-toolbar { align-items: flex-start; }
  .ai-quick-list { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .15rem; }
  .ai-quick-question { flex: 0 0 auto; max-width: 82%; }
  .ai-composer-row { align-items: flex-end; }
  .ai-composer-hint { max-width: 58%; }
  .ai-markdown-table { min-width: 520px; }
}