.ai-assistant-panel {
  display: flex;
  height: clamp(20rem, 45svh, 30rem);
  min-height: 20rem;
  max-height: 30rem;
  flex-direction: column;
  gap: 0.7rem;
  overflow: hidden;
  border: 1px solid var(--border);
}

.ai-assistant-panel[data-ai-state="unavailable"] {
  height: auto;
  min-height: 0;
  max-height: none;
  gap: 0;
}

.ai-assistant-panel[data-ai-state="unavailable"] .ai-chat-empty {
  display: none;
}

.ai-expand-chat-button {
  align-self: center;
  margin: -0.12rem 0;
  padding: 0.08rem 0.55rem;
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
}

.ai-expand-chat-button:hover,
.ai-expand-chat-button:focus-visible {
  color: var(--primary-strong);
  text-decoration: underline;
}

.ai-assistant-panel.is-expanded {
  height: min(80svh, 52rem);
  min-height: min(32rem, 80svh);
  max-height: 80svh;
}

.ai-assistant-panel.is-expanded .ai-chat-preview {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

.ai-assistant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex: 0 0 auto;
}

.ai-assistant-title {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 0.5rem;
}

.ai-assistant-title h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.ai-assistant-mark {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--secondary);
  color: var(--primary);
}

.ai-assistant-mark svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

.ai-model-badge {
  flex: 0 0 auto;
  padding: 0.33rem 0.52rem;
  border-radius: 8px;
  background: #ddebff;
  color: var(--primary-strong);
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

.ai-assistant-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.ai-clear-chat-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border: 1px solid #c4d0df;
  border-radius: 8px;
  background: #f3f6fa;
  color: #607086;
  cursor: pointer;
}

.ai-clear-chat-button svg {
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.ai-clear-chat-button:hover:not(:disabled) {
  border-color: rgba(11, 117, 255, 0.42);
  background: var(--secondary);
  color: var(--primary-strong);
}

.ai-clear-chat-button:disabled {
  border-color: #c4d0df;
  background: #eef2f7;
  color: #8996a7;
  opacity: 0.9;
}

.ai-clear-chat-button[hidden] {
  display: none;
}

.ai-chat-empty {
  display: grid;
  min-height: 0;
  flex: 1 1 0;
  place-content: center;
  justify-items: center;
  gap: 0.5rem;
  padding: 0.7rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--background);
  color: var(--muted-foreground);
  text-align: center;
}

.ai-chat-empty-icon {
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  place-items: center;
  border-radius: 8px;
  background: var(--secondary);
  color: var(--primary);
}

.ai-chat-empty-icon svg {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
}

.ai-chat-empty p {
  max-width: 19rem;
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.4;
}

.ai-chat-preview {
  display: grid;
  min-height: 0;
  flex: 1 1 0;
  align-content: start;
  gap: 0.45rem;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.ai-chat-preview:empty {
  display: none;
}

.ai-message {
  display: grid;
  width: fit-content;
  max-width: 88%;
  gap: 0.35rem;
  padding: 0.55rem 0.65rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--background);
}

.ai-message-assistant {
  justify-self: start;
}

.ai-message-user {
  justify-self: end;
  border-color: #c9ddff;
  background: #eef5ff;
}

.ai-message p {
  margin: 0;
  font-size: 0.79rem;
  line-height: 1.35;
}

.ai-message-content {
  overflow-wrap: anywhere;
  font-size: 0.84rem;
  line-height: 1.48;
}

.ai-message-content > :first-child {
  margin-top: 0;
}

.ai-message-content > :last-child {
  margin-bottom: 0;
}

.ai-message-content h1,
.ai-message-content h2,
.ai-message-content h3 {
  margin: 0.45rem 0 0.28rem;
  color: var(--foreground);
  font-family: var(--font-headings);
  line-height: 1.3;
}

.ai-message-content h1 {
  font-size: 1.05em;
}

.ai-message-content h2 {
  font-size: 1em;
}

.ai-message-content h3 {
  font-size: 0.96em;
}

.ai-message-content p,
.ai-message-content ul,
.ai-message-content ol,
.ai-message-content li,
.ai-message-content blockquote,
.ai-message-content pre,
.ai-message-content table {
  margin: 0.35rem 0;
  font-size: inherit;
  line-height: inherit;
}

.ai-message-content ul,
.ai-message-content ol {
  padding-left: 1.1rem;
}

.ai-message-content li {
  margin: 0;
}

.ai-message-content li + li {
  margin-top: 0.16rem;
}

.ai-message-content blockquote {
  padding-left: 0.55rem;
  border-left: 2px solid rgba(11, 117, 255, 0.35);
  color: var(--muted-foreground);
}

.ai-message-content code {
  padding: 0.08rem 0.24rem;
  border-radius: 4px;
  background: rgba(16, 24, 39, 0.08);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.86em;
}

.ai-message-content pre {
  overflow-x: auto;
  padding: 0.45rem;
  border-radius: 6px;
  background: rgba(16, 24, 39, 0.08);
}

.ai-message-content pre code {
  padding: 0;
  background: transparent;
}

.ai-message-content a {
  color: var(--primary-strong);
  text-decoration: underline;
}

.ai-message-content table {
  width: 100%;
  margin: 0.55rem 0;
  border-collapse: collapse;
  font-size: 0.94em;
}

.ai-message-content th,
.ai-message-content td {
  padding: 0.35rem 0.45rem;
  border: 1px solid rgba(16, 24, 39, 0.14);
  text-align: left;
  vertical-align: top;
}

.ai-message-content th {
  background: rgba(11, 117, 255, 0.08);
  font-weight: 700;
}

.ai-message-content table {
  display: block;
  overflow-x: auto;
}

.ai-message footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  color: var(--muted-foreground);
}

.ai-message time {
  font-size: 0.64rem;
}

.ai-message-copy {
  display: grid;
  width: 1.2rem;
  height: 1.2rem;
  padding: 0;
  place-items: center;
  border-radius: 5px;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
}

.ai-message-copy:hover {
  background: rgba(11, 117, 255, 0.1);
  color: var(--primary);
}

.ai-message-copy svg {
  width: 0.82rem;
  height: 0.82rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.ai-message-thinking {
  grid-template-columns: repeat(3, 0.3rem);
  align-items: center;
  min-height: 1.1rem;
}

.ai-message-thinking i {
  width: 0.3rem;
  height: 0.3rem;
  border-radius: 50%;
  background: var(--primary);
  animation: ai-thinking 1s ease-in-out infinite;
}

.ai-message-thinking i:nth-child(2) { animation-delay: 0.14s; }
.ai-message-thinking i:nth-child(3) { animation-delay: 0.28s; }

@keyframes ai-thinking {
  0%, 100% { opacity: 0.35; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-0.16rem); }
}

.ai-chat-actions {
  display: grid;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.ai-quick-prompts {
  display: flex;
  width: calc(100% - 2.25rem);
  gap: 0.38rem;
  flex: 0 0 auto;
  overflow-x: auto;
  padding-bottom: 0.1rem;
  scrollbar-width: thin;
}

.ai-quick-prompts button {
  display: inline-flex;
  align-items: center;
  min-width: max-content;
  min-height: 1.75rem;
  padding: 0.3rem 0.42rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--foreground);
  cursor: pointer;
  flex: 1 0 auto;
  font: inherit;
  font-size: 0.66rem;
  font-weight: 750;
  text-align: left;
  white-space: nowrap;
}

.ai-quick-prompts button svg {
  width: 0.78rem;
  height: 0.78rem;
  margin-right: 0.28rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.ai-quick-prompts button:hover {
  border-color: rgba(11, 117, 255, 0.42);
  background: var(--secondary);
  color: var(--primary-strong);
}

.ai-quick-prompts button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ai-composer {
  display: flex;
  height: 1.85rem;
  flex: 0 0 1.85rem;
  align-items: stretch;
  gap: 0.4rem;
}

.ai-composer textarea {
  height: 100%;
  width: 100%;
  min-height: 0;
  min-width: 0;
  resize: none;
  padding: 0.36rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--foreground);
  font: inherit;
  font-size: 0.7rem;
  line-height: 1.25;
}

.ai-composer textarea::placeholder {
  color: var(--muted-foreground);
}

.ai-composer button {
  display: grid;
  width: 1.85rem;
  padding: 0;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

.ai-composer button:hover {
  background: var(--primary-strong);
}

.ai-composer button:disabled,
.ai-composer textarea:disabled {
  cursor: wait;
  opacity: 0.62;
}

.ai-composer button svg {
  width: 0.82rem;
  height: 0.82rem;
  fill: currentColor;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .ai-message {
    max-width: 94%;
  }

  .ai-model-badge {
    font-size: 0.64rem;
  }
}
