/**
 * AI Modal Styles
 *
 * Modal interface for streaming AI interactions.
 * Provides a focused space for viewing AI-generated content
 * with actions to apply, copy, or discard.
 */

.ai-modal {
  --modal-width: min(600px, 90vw);
  --modal-height: min(500px, 80vh);
  --modal-padding: 1.5rem;
  --modal-radius: 12px;
  --modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

  border: none;
  border-radius: var(--modal-radius);
  box-shadow: var(--modal-shadow);
  padding: 0;
  width: var(--modal-width);
  max-height: var(--modal-height);
  overflow: hidden;
  background: white;
}

.ai-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

/* Entry animation */
.ai-modal[open] {
  animation: ai-modal-enter 200ms ease-out;
}

@keyframes ai-modal-enter {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */
.ai-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem var(--modal-padding);
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.ai-modal__title {
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-modal__title svg {
  width: 20px;
  height: 20px;
  color: #22c55e;
}

.ai-modal__close {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: #6b7280;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 150ms, color 150ms;
}

.ai-modal__close:hover {
  background: #e5e7eb;
  color: #111827;
}

.ai-modal__close svg {
  width: 20px;
  height: 20px;
}

/* Status indicator */
.ai-modal__status {
  font-size: 0.875rem;
  color: #6b7280;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-modal__status--loading::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid #e5e7eb;
  border-top-color: #22c55e;
  border-radius: 50%;
  animation: ai-modal-spin 0.8s linear infinite;
}

@keyframes ai-modal-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Content area */
.ai-modal__body {
  padding: var(--modal-padding);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 200px;
  max-height: calc(var(--modal-height) - 140px);
}

.ai-modal__content {
  flex: 1;
  overflow-y: auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  color: #374151;
  white-space: pre-wrap;
  word-wrap: break-word;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem;
  min-height: 150px;
  text-align: left;
}

.ai-modal__content[contenteditable="true"] {
  outline: none;
  cursor: text;
}

.ai-modal__content[contenteditable="true"]:focus {
  border-color: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

/* Markdown-like styling for content */
.ai-modal__content h1,
.ai-modal__content h2,
.ai-modal__content h3 {
  font-weight: 600;
  margin: 0.5em 0;
  line-height: 1.3;
}

.ai-modal__content h1 { font-size: 1.5em; }
.ai-modal__content h2 { font-size: 1.25em; }
.ai-modal__content h3 { font-size: 1.1em; }

.ai-modal__content p {
  margin: 0.75em 0;
}

.ai-modal__content code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: #f3f4f6;
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

.ai-modal__content pre {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875em;
  background: #f3f4f6;
  padding: 0.75em;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.75em 0;
}

.ai-modal__content ul,
.ai-modal__content ol {
  margin: 0.75em 0;
  padding-left: 1.5em;
}

.ai-modal__content li {
  margin: 0.25em 0;
}

.ai-modal__content strong {
  font-weight: 600;
}

.ai-modal__content em {
  font-style: italic;
}

.ai-modal__content blockquote {
  border-left: 3px solid #d1d5db;
  margin: 0.75em 0;
  padding-left: 1em;
  color: #6b7280;
}

.ai-modal__content:empty::before {
  content: 'Waiting for response...';
  color: #9ca3af;
  font-style: italic;
}

.ai-modal__error {
  color: #dc2626;
  font-family: inherit;
}

/* Streaming cursor effect */
.ai-modal__content--streaming::after {
  content: '|';
  animation: ai-modal-cursor 0.8s steps(1) infinite;
  color: #22c55e;
}

@keyframes ai-modal-cursor {
  0%, 50% {
    opacity: 1;
  }
  51%, 100% {
    opacity: 0;
  }
}

/* Footer with actions */
.ai-modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem var(--modal-padding);
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

.ai-modal__btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 150ms, opacity 150ms;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.ai-modal__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-modal__btn svg {
  width: 16px;
  height: 16px;
}

.ai-modal__btn--primary {
  background: #22c55e;
  color: white;
  border: none;
}

.ai-modal__btn--primary:hover:not(:disabled) {
  background: #16a34a;
}

.ai-modal__btn--secondary {
  background: white;
  color: #374151;
  border: 1px solid #d1d5db;
}

.ai-modal__btn--secondary:hover:not(:disabled) {
  background: #f3f4f6;
}

.ai-modal__btn--ghost {
  background: none;
  color: #6b7280;
  border: none;
}

.ai-modal__btn--ghost:hover:not(:disabled) {
  background: #f3f4f6;
  color: #374151;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .ai-modal {
    --modal-width: 95vw;
    --modal-height: 85vh;
    --modal-padding: 1rem;
  }

  .ai-modal__footer {
    flex-wrap: wrap;
  }

  .ai-modal__btn {
    flex: 1;
    justify-content: center;
  }
}
