/*
 * Creative Templates CSS
 * Styles for browser-based ad creative rendering
 * Used by creative_preview_controller.js for live HTML previews
 */

/* =============================================================================
   CSS Custom Properties (Design Tokens)
   These are set dynamically by JavaScript when rendering templates
   ============================================================================= */
.creative-preview {
  /* Colors */
  --primary-color: #6366f1;
  --secondary-color: #4f46e5;
  --tertiary-color: #818cf8;
  --accent-color: #fbbf24;
  --accent-color-30: #fbbf244d;
  --accent-color-50: #fbbf2480;
  --text-color: #ffffff;
  --cta-text-color: #1a1a1a;

  /* Typography */
  --heading-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --body-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-weight-heading: 700;
  --font-weight-body: 400;

  /* Spacing & Sizing - base values for 1080px square */
  --padding: 48px;
  --spacing: 24px;
  --headline-size: 48px;
  --description-size: 20px;
  --cta-size: 14px;
  --cta-padding-x: 32px;
  --cta-padding-y: 16px;
  --logo-size: 60px;
  --accent-height: 4px;

  /* Border & Radius */
  --border-radius: 12px;
  --button-radius: 8px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);

  /* Spacing multiplier (compact: 0.75, normal: 1, spacious: 1.25) */
  --spacing-multiplier: 1;

  /* Letter spacing */
  --letter-spacing-heading: 0em;
  --letter-spacing-body: 0em;
  --letter-spacing-cta: 0.03em;
}

/* =============================================================================
   Base Styles
   ============================================================================= */
.creative-preview {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  font-family: var(--body-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.creative-preview * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.creative-preview .ad-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  border-radius: var(--border-radius);
}

/* =============================================================================
   Typography
   ============================================================================= */
.creative-preview .headline {
  font-family: var(--heading-font);
  font-size: var(--headline-size);
  font-weight: var(--font-weight-heading);
  letter-spacing: var(--letter-spacing-heading);
  line-height: 1.15;
  margin-bottom: calc(var(--spacing) * var(--spacing-multiplier));
  color: var(--text-color);
}

.creative-preview .description {
  font-size: var(--description-size);
  font-weight: var(--font-weight-body);
  letter-spacing: var(--letter-spacing-body);
  line-height: 1.5;
  opacity: 0.9;
  margin-bottom: calc(var(--spacing) * var(--spacing-multiplier) * 1.5);
  color: var(--text-color);
}

/* =============================================================================
   CTA Button
   ============================================================================= */
.creative-preview .cta-button {
  position: relative;
  z-index: 5;
  display: inline-block;
  padding: var(--cta-padding-y) var(--cta-padding-x);
  font-size: var(--cta-size);
  font-weight: 600;
  line-height: 1;
  vertical-align: middle;
  letter-spacing: var(--letter-spacing-cta);
  text-transform: uppercase;
  border-radius: var(--button-radius);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform 0.2s ease;
  background: white;
  color: var(--cta-text-color);
  border: none;
}

.creative-preview .cta-button--outline {
  background: transparent;
  color: var(--text-color);
  border: 2px solid var(--text-color);
}

.creative-preview .cta-button--gradient {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
  border: none;
}

.creative-preview .cta-button--inverted {
  background: var(--primary-color);
  color: var(--cta-text-color);
}

/* =============================================================================
   Logo
   ============================================================================= */
.creative-preview .logo {
  height: var(--logo-size);
  width: auto;
  max-width: calc(var(--logo-size) * 3);
  object-fit: contain;
  border-radius: calc(var(--border-radius) * 0.5);
}

.creative-preview .logo--with-bg {
  background: transparent;
  padding: calc(var(--logo-size) * 0.1);
  box-shadow: none;
}

.creative-preview .logo-wrapper {
  margin-bottom: calc(var(--spacing) * var(--spacing-multiplier));
}

/* =============================================================================
   Background Styles
   ============================================================================= */
.creative-preview .bg-solid {
  background: var(--primary-color);
}

.creative-preview .bg-gradient {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.creative-preview .bg-gradient-vertical {
  background: linear-gradient(180deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

/* =============================================================================
   Text Shadows (for overlays)
   ============================================================================= */
.creative-preview .text-shadow {
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.creative-preview .text-shadow-strong {
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

/* =============================================================================
   Accent Bar
   ============================================================================= */
.creative-preview .accent-bar {
  width: 60px;
  height: var(--accent-height);
  background: var(--primary-color);
  border-radius: calc(var(--accent-height) / 2);
}

.creative-preview .accent-bar--white {
  background: white;
}

/* =============================================================================
   Image Container
   ============================================================================= */
.creative-preview .image-container {
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background-color: transparent;
}

.creative-preview .image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* For templates with contain images, inherit the ad background */
.creative-preview.template-split .image-side {
  background-color: inherit;
}

.creative-preview .ai-generated-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* =============================================================================
   Headline Accents
   ============================================================================= */
.creative-preview .headline--underline::after {
  content: '';
  display: block;
  width: 60px;
  height: 4px;
  background: var(--accent-color);
  margin-top: 0.5em;
  border-radius: 2px;
}

.creative-preview .headline--underline {
  display: inline-block;
}

.creative-preview .headline--underline-thick {
  background: linear-gradient(transparent 60%, var(--accent-color-30) 60%);
  display: inline;
  padding: 0 0.1em;
}

.creative-preview .headline--highlight {
  background: linear-gradient(transparent 50%, var(--accent-color-50) 50%);
  display: inline;
  padding: 0 0.2em;
}

.creative-preview .headline--gradient-text {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* =============================================================================
   Ad Borders
   ============================================================================= */
.creative-preview .ad-border--thin {
  border: 1px solid rgba(0,0,0,0.1);
}

.creative-preview .ad-border--accent-top {
  border-top: 4px solid var(--primary-color);
}

.creative-preview .ad-border--accent-left {
  border-left: 4px solid var(--primary-color);
}

/* =============================================================================
   TEMPLATE: Split
   ============================================================================= */
.creative-preview.template-split .ad-container {
  display: flex;
  flex-direction: row;
}

.creative-preview.template-split.split-right .ad-container {
  flex-direction: row-reverse;
}

.creative-preview.template-split .image-side {
  width: 45%;
  height: 100%;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--padding) * 0.5);
}

.creative-preview.template-split.has-monitor .image-side {
  width: 50%;
  padding: calc(var(--padding) * 0.75);
}

.creative-preview.template-split .image-side img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--border-radius);
}

.creative-preview.template-split.has-monitor .image-side img {
  border-radius: 0;
}

.creative-preview.template-split .content-side {
  width: 55%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--padding);
  position: relative;
  z-index: 1;
}

.creative-preview.template-split.has-monitor .content-side {
  width: 50%;
}

/* Monitor frame composite styles */
.creative-preview.template-split .monitor-frame-container {
  position: relative;
  width: 90%;
  max-width: 100%;
  overflow: hidden;  /* Clip screenshot to frame bounds */
}

.creative-preview.template-split .monitor-frame {
  width: 100%;
  height: auto;
  position: relative;
  z-index: 2;  /* Frame on top */
}

.creative-preview.template-split .monitor-screenshot {
  position: absolute;
  top: 2.1%;
  left: 2.25%;
  width: 95.5%;
  height: 71.6%;
  object-fit: cover;
  object-position: top center;  /* Align screenshot to top */
  border-radius: 0;
  z-index: 1;  /* Screenshot behind frame */
}

/* =============================================================================
   TEMPLATE: Bold Statement
   ============================================================================= */
.creative-preview.template-bold-statement .ad-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--padding);
}

.creative-preview.template-bold-statement .headline-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 0 calc(var(--padding) * 0.5);
}

.creative-preview.template-bold-statement .headline {
  font-size: calc(var(--headline-size) * 1.3);
  line-height: 1.1;
  margin-bottom: 0;
  background: none;
}

.creative-preview.template-bold-statement .accent-word {
  color: var(--secondary-color);
}

.creative-preview.template-bold-statement .bottom-section {
  position: absolute;
  bottom: var(--padding);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--spacing) * 0.6);
}

.creative-preview.template-bold-statement .divider-line {
  width: calc(var(--padding) * 1.5);
  height: 2px;
  background: var(--text-color);
  opacity: 0.15;
}

.creative-preview.template-bold-statement .logo-brand-wrapper {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 0.35);
}

.creative-preview.template-bold-statement .logo-brand-wrapper .logo {
  height: calc(var(--logo-size) * 1.0);
  width: auto;
  max-width: calc(var(--logo-size) * 3);
  object-fit: contain;
}

.creative-preview.template-bold-statement .brand-name {
  font-size: calc(var(--description-size) * 1.3);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.creative-preview.template-bold-statement .brand-slogan {
  font-size: calc(var(--description-size) * 1.1);
  font-weight: 400;
  opacity: 0.8;
  margin-top: calc(var(--spacing) * 0.15);
}

/* =============================================================================
   TEMPLATE: Bold Stacked
   ============================================================================= */
.creative-preview.template-bold-stacked .ad-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--padding);
  position: relative;
  overflow: hidden;
}

.creative-preview.template-bold-stacked .headline-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 0 calc(var(--padding) * 0.5);
}

.creative-preview.template-bold-stacked .headline-stacked {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.85;
  gap: 0;
}

.creative-preview.template-bold-stacked .headline-word {
  display: block;
  font-size: calc(var(--headline-size) * 2.8);
  font-weight: 900;
  color: var(--text-color);
  text-transform: uppercase;
  letter-spacing: -0.04em;
  margin: 0;
  padding: 0;
  word-break: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  max-width: 100%;
}

.creative-preview.template-bold-stacked .headline-word.accent {
  color: var(--secondary-color);
}

.creative-preview.template-bold-stacked .bottom-section {
  position: absolute;
  bottom: var(--padding);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--spacing) * 0.6);
}

.creative-preview.template-bold-stacked .divider-line {
  width: calc(var(--padding) * 1.5);
  height: 2px;
  background: var(--text-color);
  opacity: 0.15;
}

.creative-preview.template-bold-stacked .logo-brand-wrapper {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 0.35);
}

.creative-preview.template-bold-stacked .logo-brand-wrapper .logo {
  height: calc(var(--logo-size) * 1.0);
  width: auto;
  max-width: calc(var(--logo-size) * 3);
  object-fit: contain;
}

.creative-preview.template-bold-stacked .brand-name {
  font-size: calc(var(--description-size) * 1.3);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.creative-preview.template-bold-stacked .brand-slogan {
  font-size: calc(var(--description-size) * 1.1);
  font-weight: 400;
  opacity: 0.8;
  margin-top: calc(var(--spacing) * 0.15);
}

/* =============================================================================
   TEMPLATE: Speech Bubble
   ============================================================================= */
.creative-preview.template-speech-bubble .ad-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--padding);
}

.creative-preview.template-speech-bubble .bubble-container {
  position: relative;
  max-width: 85%;
  margin-bottom: calc(var(--spacing) * 2);
  z-index: 1;
}

.creative-preview.template-speech-bubble .speech-bubble {
  background: white;
  border-radius: calc(var(--border-radius) * 2);
  padding: calc(var(--padding) * 1.2);
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  position: relative;
}

.creative-preview.template-speech-bubble .speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 24px solid white;
}

.creative-preview.template-speech-bubble .bubble-text {
  font-size: calc(var(--headline-size) * 0.9);
  line-height: 1.3;
  color: #1a1a1a;
  text-align: center;
}

.creative-preview.template-speech-bubble .text-normal {
  font-weight: 400;
}

.creative-preview.template-speech-bubble .text-bold {
  font-weight: 700;
  color: var(--primary-color);
}

.creative-preview.template-speech-bubble .quote-mark {
  position: absolute;
  top: calc(var(--padding) * 0.5);
  left: calc(var(--padding) * 0.5);
  font-size: calc(var(--headline-size) * 1.5);
  color: var(--primary-color);
  opacity: 0.2;
  font-family: Georgia, serif;
  line-height: 1;
}

.creative-preview.template-speech-bubble .bottom-section {
  position: absolute;
  bottom: var(--padding);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--spacing) * 0.6);
}

.creative-preview.template-speech-bubble .divider-line {
  width: calc(var(--padding) * 1.5);
  height: 2px;
  background: var(--primary-color);
  opacity: 0.3;
}

.creative-preview.template-speech-bubble .logo-brand-wrapper {
  display: flex;
  align-items: center;
  gap: calc(var(--spacing) * 0.35);
}

.creative-preview.template-speech-bubble .logo-brand-wrapper .logo {
  height: calc(var(--logo-size) * 1.0);
  width: auto;
  max-width: calc(var(--logo-size) * 3);
  object-fit: contain;
}

.creative-preview.template-speech-bubble .brand-name {
  font-size: calc(var(--description-size) * 1.3);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.creative-preview.template-speech-bubble .brand-slogan {
  font-size: calc(var(--description-size) * 1.1);
  font-weight: 400;
  opacity: 0.8;
  margin-top: calc(var(--spacing) * 0.15);
}

/* =============================================================================
   TEMPLATE: Stock Fullbleed
   ============================================================================= */
.creative-preview.template-stock-fullbleed .ad-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.creative-preview.template-stock-fullbleed .background-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.creative-preview.template-stock-fullbleed .image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: rgba(0, 0, 0, 0.45);
}

.creative-preview.template-stock-fullbleed .content-wrapper {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--padding);
  width: 100%;
  height: 100%;
  color: #ffffff;
}

.creative-preview.template-stock-fullbleed .logo-wrapper {
  margin-bottom: calc(var(--spacing) * var(--spacing-multiplier) * 1.5);
}

.creative-preview.template-stock-fullbleed .logo {
  padding: calc(var(--logo-size) * 0.15);
}

.creative-preview.template-stock-fullbleed .headline {
  max-width: 90%;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  color: #ffffff;
  background: none;
}

.creative-preview.template-stock-fullbleed .description {
  max-width: 85%;
  text-align: center;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
  color: rgba(255, 255, 255, 0.95);
}

.creative-preview.template-stock-fullbleed .cta-button {
  margin-top: calc(var(--spacing) * var(--spacing-multiplier) * 0.5);
  background: #ffffff;
  color: #1a1a1a;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* =============================================================================
   TEMPLATE: Stock Split
   ============================================================================= */
.creative-preview.template-stock-split .ad-container {
  display: flex;
  flex-direction: row;
}

.creative-preview.template-stock-split.split-right .ad-container {
  flex-direction: row-reverse;
}

.creative-preview.template-stock-split .image-side {
  width: 50%;
  height: 100%;
  position: relative;
  overflow: hidden;
  z-index: 0;  /* Establish stacking context below content-side */
}

.creative-preview.template-stock-split .image-side img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.creative-preview.template-stock-split .image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;  /* Contain overlay within image-side */
}

.creative-preview.template-stock-split .content-side {
  width: 50%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--padding);
  position: relative;
  z-index: 1;
}

.creative-preview.template-stock-split .headline {
  max-width: 100%;
  background: none;
}

.creative-preview.template-stock-split .description {
  max-width: 95%;
}

/* =============================================================================
   TEMPLATE: Stock Textbar
   ============================================================================= */
.creative-preview.template-stock-textbar .ad-container {
  display: flex;
  flex-direction: column;
}

.creative-preview.template-stock-textbar .image-section {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 60%;
}

.creative-preview.template-stock-textbar .image-section img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.creative-preview.template-stock-textbar .image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;  /* Contain overlay within image-section */
}

.creative-preview.template-stock-textbar .logo-badge {
  position: absolute;
  top: calc(var(--padding) * 0.75);
  left: calc(var(--padding) * 0.75);
  z-index: 10;
}

.creative-preview.template-stock-textbar .logo-badge .logo {
  padding: calc(var(--logo-size) * 0.12);
  height: calc(var(--logo-size) * 1.0);
}

.creative-preview.template-stock-textbar .text-bar {
  padding: calc(var(--padding) * 0.8) var(--padding);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.creative-preview.template-stock-textbar .text-bar .headline {
  font-size: calc(var(--headline-size) * 0.85);
  margin-bottom: calc(var(--spacing) * 0.5);
  background: none;
}

.creative-preview.template-stock-textbar .text-bar .description {
  font-size: calc(var(--description-size) * 0.9);
  margin-bottom: calc(var(--spacing) * 0.75);
  opacity: 0.9;
}

.creative-preview.template-stock-textbar .text-bar .cta-button {
  align-self: flex-start;
}

/* =============================================================================
   TEMPLATE: Stock Gradient
   ============================================================================= */
.creative-preview.template-stock-gradient .ad-container {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.creative-preview.template-stock-gradient .background-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.creative-preview.template-stock-gradient .gradient-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  /* Default gradient - can be overridden with inline style */
  background: linear-gradient(to bottom, transparent 0%, rgba(99, 102, 241, 0.3) 40%, rgba(99, 102, 241, 0.95) 70%, #6366f1 100%);
}

.creative-preview.template-stock-gradient .content-wrapper {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: var(--padding);
}

.creative-preview.template-stock-gradient .top-section {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

.creative-preview.template-stock-gradient .logo-wrapper .logo {
  padding: calc(var(--logo-size) * 0.12);
}

.creative-preview.template-stock-gradient .bottom-section {
  display: flex;
  flex-direction: column;
  padding-top: calc(var(--spacing) * 2);
}

.creative-preview.template-stock-gradient .headline {
  max-width: 95%;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  background: none;
}

.creative-preview.template-stock-gradient .description {
  max-width: 90%;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.creative-preview.template-stock-gradient .cta-button {
  align-self: flex-start;
}

/* =============================================================================
   Image Placeholder
   ============================================================================= */
.creative-preview .image-placeholder {
  width: 80%;
  aspect-ratio: 1;
  background: rgba(255,255,255,0.1);
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.creative-preview .image-placeholder svg {
  width: 40%;
  height: 40%;
  opacity: 0.3;
  fill: currentColor;
}

/* =============================================================================
   Patterns & Decorations (simplified for frontend)
   ============================================================================= */
.creative-preview .pattern-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: -1;
  opacity: 0.1;
}

.creative-preview .decorations {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
  isolation: isolate;
}
