/* AI Canvas Assistant (Fase B): toolbar button, modal, preview. */

#btn-ai-assistant .btn-icon {
  filter: none;
}
#btn-ai-assistant.is-disabled {
  opacity: 0.55;
}

.ai-overlay {
  position: fixed;
  inset: 0;
  z-index: 4200;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 9vh;
}

.ai-panel {
  width: 600px;
  max-width: 94vw;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  overflow: hidden;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
.ai-body {
  overflow-y: auto;
}

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(135deg, #f0fdfa, #ecfeff);
}
.ai-title {
  font-size: 15px;
  font-weight: 700;
  color: #134e4a;
}
.ai-close {
  border: none;
  background: transparent;
  font-size: 15px;
  cursor: pointer;
  color: #6b7280;
  padding: 4px 6px;
  border-radius: 6px;
}
.ai-close:hover {
  background: rgba(0, 0, 0, 0.06);
}

.ai-body {
  padding: 18px 20px 20px;
}
.ai-lede {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.55;
  color: #4b5563;
  text-align: justify;
}

.ai-input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 13px;
  font: 14px/1.5 inherit;
  font-family: inherit;
  color: #111827;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  resize: vertical;
}
.ai-input:focus {
  outline: none;
  border-color: #0891b2;
  box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.14);
}
.ai-input:disabled {
  background: #f9fafb;
  color: #9ca3af;
}

.ai-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 16px;
}
.ai-chip {
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  color: #4b5563;
  font: 500 11px/1.3 inherit;
  font-family: inherit;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-chip:hover {
  border-color: #0891b2;
  color: #0e7490;
}

.ai-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}
.ai-btn {
  font: 600 13px/1 inherit;
  font-family: inherit;
  padding: 11px 20px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #1b3a5c;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.ai-btn--primary {
  background: linear-gradient(180deg, #0e7490, #0891b2);
  border-color: #0e7490;
  color: #fff;
}
.ai-btn--primary:hover {
  filter: brightness(1.06);
}
.ai-btn--primary:disabled {
  opacity: 0.7;
  cursor: default;
}
.ai-btn--ghost {
  border-color: transparent;
  color: #6b7280;
}
.ai-note {
  font-size: 11.5px;
  color: #9ca3af;
}

.ai-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: ai-spin 0.8s linear infinite;
}
.ai-spinner--dark {
  border-color: rgba(27, 58, 92, 0.3);
  border-top-color: #1b3a5c;
}

.ai-review-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed #e5e7eb;
}
.ai-review-or {
  font-size: 12px;
  color: #6b7280;
  flex: 1;
}
[data-theme="dark"] .ai-review-row { border-color: #374151; }

.ai-review-section {
  margin: 0 0 12px;
  text-align: left;
}
.ai-review-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #1b3a5c;
  margin-bottom: 5px;
}
.ai-review-section ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
  color: #4b5563;
}
.ai-review-section li { margin-bottom: 4px; text-align: justify; }
[data-theme="dark"] .ai-review-section-title { color: #93c5fd; }
[data-theme="dark"] .ai-review-section ul { color: #d1d5db; }
@keyframes ai-spin {
  to {
    transform: rotate(360deg);
  }
}

.ai-preview-name {
  font-size: 17px;
  font-weight: 700;
  color: #1b3a5c;
  margin-bottom: 8px;
}
.ai-preview-summary {
  margin: 0 0 10px;
  font-size: 13.5px;
  line-height: 1.6;
  color: #4b5563;
  text-align: justify;
  white-space: pre-wrap;
}
.ai-preview-rationale {
  margin: 0 0 12px;
  padding: 12px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
}
.ai-preview-rationale-title {
  font-size: 12px;
  font-weight: 700;
  color: #92400e;
  margin-bottom: 6px;
}
.ai-preview-rationale-body {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: #78350f;
  text-align: justify;
  white-space: pre-wrap;
}
[data-theme="dark"] .ai-preview-rationale {
  background: #2a2310;
  border-color: #92400e;
}
[data-theme="dark"] .ai-preview-rationale-title {
  color: #fcd34d;
}
[data-theme="dark"] .ai-preview-rationale-body {
  color: #fde68a;
}

.ai-preview-meta {
  font-size: 12px;
  color: #0e7490;
  font-weight: 600;
  margin-bottom: 18px;
}
.ai-preview-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---- AI entry points elsewhere (validator findings, detail panel) ---- */
.validator-issue-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.validator-aifix-btn {
  font: 600 12px/1 "Inter", system-ui, sans-serif;
  padding: 7px 13px;
  border-radius: 6px;
  border: 1px solid #99f6e4;
  background: #f0fdfa;
  color: #0e7490;
  cursor: pointer;
}
.validator-aifix-btn:hover {
  background: #ccfbf1;
}
[data-theme="dark"] .validator-aifix-btn {
  background: #134e4a;
  border-color: #0f766e;
  color: #5eead4;
}

/* ---- AI chat panel (iterative refinement) ---- */
.ai-chat {
  position: fixed;
  right: 18px;
  bottom: 52px;
  width: 400px;
  max-width: 92vw;
  height: min(580px, 72vh);
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  z-index: 4100;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
.ai-chat.hidden { display: none; }
.ai-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(135deg, #f0fdfa, #ecfeff);
  border-radius: 14px 14px 0 0;
}
.ai-chat-title { font-size: 13.5px; font-weight: 700; color: #134e4a; }
.ai-chat-close {
  border: none; background: transparent; cursor: pointer;
  color: #6b7280; font-size: 14px; padding: 3px 6px; border-radius: 6px;
}
.ai-chat-close:hover { background: rgba(0,0,0,0.06); }
.ai-chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-chat-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.ai-chat-msg--user {
  align-self: flex-end;
  background: #0e7490;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-chat-msg--assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-left-radius: 4px;
  text-align: justify;
}
.ai-chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed #d1d5db;
}
.ai-chat-actions .ai-btn { padding: 7px 14px; font-size: 12px; }
.ai-chat-actions-meta { font-size: 11.5px; font-weight: 600; color: #0e7490; }
.ai-chat-error { color: #b91c1c; }
.ai-chat-inputrow {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
}
.ai-chat-input {
  flex: 1;
  resize: none;
  padding: 9px 11px;
  font: 13px/1.45 inherit;
  font-family: inherit;
  color: #111827;
  border: 1px solid #d1d5db;
  border-radius: 8px;
}
.ai-chat-input:focus { outline: none; border-color: #0891b2; box-shadow: 0 0 0 3px rgba(8,145,178,0.14); }
.ai-chat-send { align-self: flex-end; padding: 10px 14px; }

[data-theme="dark"] .ai-chat { background: #1f2937; border-color: #374151; }
[data-theme="dark"] .ai-chat-head { background: #111827; border-color: #374151; }
[data-theme="dark"] .ai-chat-title { color: #5eead4; }
[data-theme="dark"] .ai-chat-msg--assistant { background: #111827; color: #e5e7eb; }
[data-theme="dark"] .ai-chat-inputrow { border-color: #374151; }
[data-theme="dark"] .ai-chat-input { background: #111827; color: #f1f5f9; border-color: #374151; }
[data-theme="dark"] .ai-chat-actions { border-color: #374151; }

/* Dark theme */
[data-theme="dark"] .ai-panel {
  background: #1f2937;
  border-color: #374151;
}
[data-theme="dark"] .ai-head {
  background: #111827;
  border-color: #374151;
}
[data-theme="dark"] .ai-title {
  color: #5eead4;
}
[data-theme="dark"] .ai-lede,
[data-theme="dark"] .ai-preview-summary {
  color: #d1d5db;
}
[data-theme="dark"] .ai-input {
  background: #111827;
  color: #f1f5f9;
  border-color: #374151;
}
[data-theme="dark"] .ai-chip {
  background: #111827;
  border-color: #374151;
  color: #9ca3af;
}
[data-theme="dark"] .ai-btn {
  background: #111827;
  border-color: #374151;
  color: #e5e7eb;
}
[data-theme="dark"] .ai-btn--primary {
  background: linear-gradient(180deg, #0e7490, #0891b2);
  color: #fff;
}
[data-theme="dark"] .ai-preview-name {
  color: #93c5fd;
}
