/* ==========================================================================
   AI Card Feature - SaaS Studio UI/UX CSS (Canva/Notion AI Style 2026)
   ========================================================================== */

:root {
  --ai-bg: #151824;
  --ai-surface: #1F2233;
  --ai-card: #262A40;
  --ai-primary: #8B7BFF;
  --ai-primary-hover: #7868F7;
  --ai-accent: #C6BCFF;
  --ai-text: #FFFFFF;
  --ai-text-secondary: #B6BDD3;
  --ai-border: rgba(255,255,255,0.08);
  --ai-success: #22C55E;
  --ai-danger: #EF4444;
}

/* ========== Modal Backdrop ========== */
.ai-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 16, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: none;
  z-index: 99999998 !important;
  animation: ai-fade-in 0.3s ease-out forwards;
}

.ai-modal-backdrop.active {
  display: block;
}

/* ========== Modal Container ========== */
.ai-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999999999 !important;
  padding: 24px;
  overflow-y: auto;
  animation: ai-slide-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.ai-modal.active {
  display: flex;
}

/* ========== Card Container ========== */
.ai-card {
  width: min(1160px, 96vw);
  background: var(--ai-bg);
  border: 1px solid var(--ai-border);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ========== Header ========== */
.ai-head {
  border-bottom: 1px solid var(--ai-border);
  padding: 24px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.ai-head-left h3 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--ai-text);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-head-left p {
  margin: 4px 0 0 0;
  font-size: 14px;
  color: var(--ai-text-secondary);
}

/* Close button */
.ai-close {
  width: 40px;
  height: 40px;
  border: 1px solid var(--ai-border);
  background: var(--ai-surface);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: var(--ai-text);
  
  &:hover {
    background: var(--ai-card);
    border-color: var(--ai-accent);
    transform: scale(1.08) rotate(90deg);
  }
}

/* ========== Grid Layout (40% / 60%) ========== */
.ai-grid {
  display: grid;
  grid-template-columns: 4.2fr 5.8fr;
  align-items: stretch;
  min-height: 560px;
  box-sizing: border-box;
}

@media (max-width: 1024px) {
  .ai-grid {
    grid-template-columns: 1fr;
  }
}

/* ========== Form Column (40%) ========== */
.ai-form-container {
  padding: 24px 32px;
  border-right: 1px solid var(--ai-border);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  max-height: calc(85vh - 90px);
}

.ai-form-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--ai-accent);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 2px;
}

/* ========== Theme Card Grid ========== */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.theme-card {
  position: relative;
  overflow: hidden;
}

.theme-card:hover {
  transform: translateY(-4px);
  border-color: rgba(139, 123, 255, 0.4) !important;
}

.theme-card.active {
  animation: pulse-border 1.5s infinite alternate;
}

/* ========== Inputs & Forms ========== */
.ai-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ai-text-secondary);
}

.ai-field input,
.ai-field select {
  padding: 0 16px;
  height: 52px;
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
  color: var(--ai-text);
  font-family: inherit;
  transition: all 0.25s ease;
  box-sizing: border-box;
  
  &:focus {
    outline: none;
    border-color: var(--ai-primary);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 4px rgba(139, 123, 255, 0.15);
  }
  
  &::placeholder {
    color: rgba(255, 255, 255, 0.25);
  }
}

.ai-field textarea {
  padding: 14px 16px;
  height: 140px;
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
  color: var(--ai-text);
  font-family: inherit;
  transition: all 0.25s ease;
  box-sizing: border-box;
  line-height: 1.5;
  
  &:focus {
    outline: none;
    border-color: var(--ai-primary);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 4px rgba(139, 123, 255, 0.15);
  }
  
  &::placeholder {
    color: rgba(255, 255, 255, 0.25);
  }
}

.ai-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Textarea small actions */
.ai-textarea-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.ai-btn-text {
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--ai-accent);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
  
  &:hover {
    color: var(--ai-text);
    background: rgba(255, 255, 255, 0.05);
    transform: scale(1.02);
  }
}

/* ========== Live Preview Column (60%) ========== */
.ai-preview-container {
  padding: 24px 32px;
  background: var(--ai-surface);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
}

.ai-canvas-wrap {
  flex: 1;
  border: 1px solid var(--ai-border);
  border-radius: 24px;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  position: relative;
  overflow: hidden;
  padding: 24px;
  box-sizing: border-box;
}

canvas.ai-canvas {
  max-width: 100%;
  max-height: 420px;
  height: auto;
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
  display: block;
  animation: canvas-reveal 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ========== Shimmer Loader Overlay ========== */
.ai-canvas-loader {
  position: absolute;
  inset: 0;
  background: rgba(31, 34, 51, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 10;
}

.ai-shimmer-card {
  width: 280px;
  height: 180px;
  background: var(--ai-card);
  border: 1px solid var(--ai-border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-sizing: border-box;
  box-shadow: 0 12px 32px rgba(0,0,0,0.15);
}

.ai-shimmer-flower {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  align-self: center;
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.03) 75%);
  background-size: 200% 100%;
  animation: shimmer-anim 1.5s infinite linear;
}

.ai-shimmer-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.03) 75%);
  background-size: 200% 100%;
  animation: shimmer-anim 1.5s infinite linear;
}

.ai-shimmer-line.short { width: 35%; align-self: center; }
.ai-shimmer-line.medium { width: 65%; }
.ai-shimmer-line.long { width: 90%; }

.ai-loader-progress {
  width: 240px;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.ai-loader-bar {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, var(--ai-primary), var(--ai-accent));
  border-radius: 2px;
  animation: loading-bar-anim 1.8s infinite ease-in-out;
}

.ai-loader-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--ai-accent);
  letter-spacing: 0.5px;
}

/* ========== Footer CTAs ========== */
.ai-footer-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.ai-btn-footer {
  height: 52px;
  padding: 0 24px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-sizing: border-box;
}

.ai-btn-footer:hover {
  transform: translateY(-2px) scale(1.02);
}

.ai-btn-footer.primary {
  background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-accent) 100%);
  color: #FFFFFF;
  border: none;
  box-shadow: 0 12px 32px rgba(139, 123, 255, 0.35);
  flex: 1.5;
}

.ai-btn-footer.primary:hover {
  box-shadow: 0 16px 40px rgba(139, 123, 255, 0.45);
}

.ai-btn-footer.secondary {
  background: var(--ai-card);
  color: #FFFFFF;
  border: 1px solid var(--ai-border);
  flex: 1;
  
  &:hover {
    background: #323754;
    border-color: rgba(255, 255, 255, 0.15);
  }
}

/* ========== Animations ========== */
@keyframes ai-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ai-slide-in {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes shimmer-anim {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes loading-bar-anim {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(150%); }
  100% { transform: translateX(-100%); }
}

@keyframes canvas-reveal {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulse-border {
  from { box-shadow: 0 0 12px rgba(139,123,255,0.2); }
  to { box-shadow: 0 0 28px rgba(139,123,255,0.45); }
}

/* ========== Responsive Breakpoints ========== */
@media (max-width: 768px) {
  .ai-modal {
    padding: 12px;
  }
  .ai-card {
    border-radius: 12px;
    max-height: 95vh;
  }
  .ai-head {
    padding: 16px 20px;
  }
  .ai-head-left h3 {
    font-size: 18px;
  }
  .ai-form-container {
    padding: 16px 20px;
    max-height: none;
  }
  .ai-preview-container {
    padding: 16px 20px;
  }
  .ai-canvas-wrap {
    min-height: 300px;
    padding: 16px;
  }
}
