* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow-x: hidden; }
body { font-family: 'Lexend', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--fg); }
button, input, textarea, select { font-family: inherit; }
.root { display: grid; grid-template-rows: 1fr auto auto; height: 100%; position: relative; overflow-x: hidden; max-width: 100%; }
.landing-hero { display: none; text-align: center; font-weight: 700; font-size: clamp(22px, 4vw, 30px); color: var(--fg); opacity: 0.95; letter-spacing: -0.01em; }
.landing-hero .landing-subtext { margin-top: 8px; font-weight: 400; font-size: clamp(14px, 2.4vw, 16px); color: rgba(17, 24, 39, 0.6); opacity: 0.9; }
.root.is-landing .landing-hero { display: block; margin-bottom: 12px; }
.messages { overflow-y: auto; overflow-x: hidden; padding: 12px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
/* Auto-hide scrollbar for messages by default; reveal via .show-scrollbar */
.messages { scrollbar-width: none; -ms-overflow-style: none; }
.messages::-webkit-scrollbar { width: 0; height: 0; }
.messages.show-scrollbar { scrollbar-width: thin; }
.messages.show-scrollbar::-webkit-scrollbar { width: 8px; height: 8px; }
.messages.show-scrollbar::-webkit-scrollbar-track { background: transparent; }
.messages.show-scrollbar::-webkit-scrollbar-thumb { background: rgba(123,111,243,0.35); border-radius: 6px; }
.msg { display: inline-flex; flex-direction: column; align-items: flex-start; max-width: 80%; padding: 10px 12px; border-radius: 14px; background: var(--bubble); color: var(--bubbleFg); line-height: 1.4; word-wrap: break-word; overflow-wrap: break-word; }
.msg p { margin: 0; }
.msg p + p { margin-top: 6px; }
.msg ul,
.msg ol { margin: 6px 0; padding-left: 20px; }
.msg li + li { margin-top: 4px; }
.msg h1, .msg h2, .msg h3, .msg h4, .msg h5, .msg h6 { margin: 8px 0 4px; font-weight: 600; line-height: 1.3; }
.msg h1 { font-size: 1.5em; }
.msg h2 { font-size: 1.3em; }
.msg h3 { font-size: 1.1em; }
.msg h4, .msg h5, .msg h6 { font-size: 1em; }
.msg blockquote { margin: 6px 0; padding-left: 12px; border-left: 3px solid rgba(123,111,243,0.3); opacity: 0.9; }
.msg pre { margin: 6px 0; padding: 8px 10px; background: rgba(0,0,0,0.05); border-radius: 6px; overflow-x: auto; }
.msg code { padding: 2px 5px; background: rgba(0,0,0,0.05); border-radius: 3px; font-size: 0.9em; font-family: 'Courier New', Courier, monospace; }
.msg pre code { padding: 0; background: transparent; }
body.dark .msg pre,
body.dark .msg code { background: rgba(255,255,255,0.08); }
.msg.user { margin-left: auto; background: var(--bubbleUser); color: var(--bubbleUserFg); }
.composer { display: grid; grid-template-columns: auto 1fr; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: var(--panel); align-items: center; }
/* Landing mode: center hero + composer until first message */
.root.is-landing { 
  display: flex; 
  flex-direction: column; 
  justify-content: center; 
  align-items: center; 
  padding: 0 16px; 
  min-height: 100%;
}
.root.is-landing .messages { display: none; }
.root.is-landing .composer { 
  grid-template-columns: auto 1fr auto; 
  border-top: none; 
  background: transparent; 
  padding: 0; 
}
/* remove ::after spacer; we will place a real send button */
.root.is-landing #composer { 
  max-width: 760px; 
  margin: 8px auto 0; 
  background: var(--inputBg); 
  border: 1px solid var(--border); 
  border-radius: 999px; 
  padding: 5px 12px; 
  box-shadow: 0 12px 28px rgba(0,0,0,0.08);
}
.root.is-landing .input { 
  border: 0; 
  background: transparent; 
  min-height: 30px; 
  padding: 5px 4px; 
  line-height: 18px; 
  text-align: center; 
}
.root.is-landing .input::placeholder { text-align: center; }
.root.is-landing .icon-btn { border: 0; background: transparent; }
.root.is-landing .footer { display: flex; margin-top: 12px; }
/* Chat mode: use the same pill composer for consistency */
.root:not(.is-landing) .composer {
  grid-template-columns: auto 1fr auto;
  border-top: none;
  background: transparent;
  padding: 8px 12px 12px;
}
/* remove ::after spacer; we will place a real send button */
.root:not(.is-landing) #composer {
  width: calc(100% - 24px);
  margin: 8px 12px;
  background: var(--inputBg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.08);
}
.root:not(.is-landing) .input {
  border: 0;
  background: transparent;
  min-height: 30px;
  padding: 5px 4px;
  line-height: 18px;
  text-align: left;
}
.root:not(.is-landing) .input::placeholder { text-align: left; }
.root:not(.is-landing) .icon-btn { border: 0; background: transparent; }
.input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; outline: none; background: var(--inputBg); color: var(--fg); min-height: 40px; resize: none; line-height: 1.3; font-family: inherit; }
.input:hover { border-color: rgba(123,111,243,0.5); }
.input:focus-visible { outline: 3px solid #7B6FF3; outline-offset: 2px; box-shadow: 0 0 0 4px rgba(123,111,243,0.2); border-color: #7B6FF3; }

/* WCAG 2.2: Enhanced focus indicators for all interactive elements */
button:focus-visible, .icon-btn:focus-visible, .btn:focus-visible {
  outline: 3px solid #7B6FF3;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(123,111,243,0.2);
}

img.generated:focus-visible {
  outline: 3px solid #7B6FF3;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(123,111,243,0.2);
  border-radius: 12px;
}
.btn { padding: 10px 16px; border-radius: 12px; border: 0; cursor: pointer; font-weight: 700; background: linear-gradient(135deg,#6C5CE7,#A66CFF); color: #fff; box-shadow: 0 6px 16px rgba(108,92,231,0.35); font-family: inherit; }
.btn:hover { filter: brightness(1.03); }
.icon-btn { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; border: 1px solid var(--border); background: var(--inputBg); color: var(--fg); cursor: pointer; font-family: inherit; padding: 8px; }
.icon-btn:hover { background: rgba(123,111,243,0.08); border-color: #7B6FF3; color: #7B6FF3; }
.icon-btn:active { transform: scale(0.95); }
.send-btn { min-width: 44px; min-height: 44px; border-radius: 12px; }
.send-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.send-btn:active:not(:disabled) { transform: scale(0.95); }
/* Group for left-side controls inside the composer (stays within first grid column) */
.composer-left { display: inline-flex; align-items: center; gap: 6px; }
/* Composer attachment preview */
.attachment-preview { width: 48px; height: 48px; border-radius: 10px; border: 1px solid var(--border); background: var(--inputBg); overflow: hidden; display: none; align-items: center; justify-content: center; }
.attachment-preview.show { display: inline-flex; }
.attachment-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Image message bubble sizing - CLS prevention with aspect-ratio */
.msg.image { display: block; padding: 0; background: transparent; max-width: min(320px, 80%); border-radius: 12px; line-height: 0; }
.msg.image img { display: block; width: 100%; height: auto; max-height: 320px; object-fit: cover; border-radius: 12px; aspect-ratio: attr(width) / attr(height); }
img.block { max-width: 100%; border-radius: 12px; display: block; height: auto; }

/* Core Web Vitals: Prevent layout shift from images */
img { content-visibility: auto; }

.footer { display:flex; align-items:center; justify-content:flex-end; gap:4px; padding:6px 12px; border-top: none; background: transparent; font-size: 11px; opacity: 0.75; }
@media (max-width: 640px) {
  .footer { justify-content: center; }
}
.logo { width: 16px; height: 16px; display:inline-block; }

/* Layout: chat is full-width (gallery removed) */
.root:not(.is-landing) { grid-template-columns: 1fr; }
.root:not(.is-landing) .messages,
.root:not(.is-landing) .composer,
.root:not(.is-landing) .footer { grid-column: 1; }

/* Gallery removed - images now inline */

/* Gallery controls removed */

/* Touch-action for better mobile interaction */
button, .icon-btn, .btn, .send-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
img.generated, .msg.image img { touch-action: manipulation; }

/* Mobile optimizations */
@media (max-width: 860px) {
  /* Ensure minimum touch targets on mobile */
  .icon-btn { min-width: 48px; min-height: 48px; }
  .send-btn { min-width: 48px; min-height: 48px; }
  
  /* Auto-hide scrollbar for messages; show on interaction */
  .messages { scrollbar-width: none; -ms-overflow-style: none; }
  .messages::-webkit-scrollbar { width: 0; height: 0; }
  .messages.show-scrollbar { scrollbar-width: thin; }
  .messages.show-scrollbar::-webkit-scrollbar { width: 8px; height: 8px; }
  .messages.show-scrollbar::-webkit-scrollbar-track { background: transparent; }
  .messages.show-scrollbar::-webkit-scrollbar-thumb { background: rgba(123,111,243,0.35); border-radius: 6px; }
  
  /* Improve tap targets for contact CTA on mobile */
  .contact-cta { min-height: 48px; padding: 12px 16px; }
}

/* Status bar (sticky inside messages) */
.status-bar { position: sticky; bottom: 0; margin: 8px 0 0 0; padding: 8px 10px; border: 1px solid var(--border); background: var(--panel); border-radius: 10px; display: none; align-items: center; gap: 8px; backdrop-filter: blur(2px); }
.status-bar.show { display: flex; }
.status-bar .spinner { width: 14px; height: 14px; border: 2px solid rgba(123,111,243,0.35); border-top-color: #7B6FF3; border-radius: 50%; animation: spin 1s linear infinite; flex: 0 0 auto; }
.status-bar .label { font-size: 12px; opacity: 0.9; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Contact capture (sticky CTA/form inside messages) */
.contact-bar { position: sticky; bottom: 0; margin: 8px 0 0 0; padding: 10px; border: 1px solid var(--border); background: var(--panel); border-radius: 12px; }
.contact-bar .cta-btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--inputBg); color: var(--fg); cursor: pointer; font-weight: 600; }
.contact-bar .cta-btn:hover { background: rgba(123,111,243,0.08); border-color: #7B6FF3; color: #7B6FF3; }
.contact-bar .form { display: none; gap: 8px; }
.contact-bar.expanded .form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.contact-bar .row { display: contents; }
.contact-bar label { font-size: 12px; opacity: 0.9; margin-bottom: 4px; display: block; }
.contact-bar input, .contact-bar select { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--inputBg); color: var(--fg); }
.contact-bar .consent { grid-column: 1 / -1; display: flex; align-items: flex-start; gap: 8px; font-size: 12px; }
.contact-bar .actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.contact-bar .error { color: #d14343; font-size: 12px; margin-top: 6px; grid-column: 1 / -1; }

/* Ensure sticky bars don't overlap; leave space between them */
.contact-bar + .status-bar { margin-top: 8px; }
.status-bar + .contact-bar { margin-top: 8px; }

/* Typing indicator bubble in chat area */
.msg.typing { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; }
.msg.typing .dots { display: inline-flex; gap: 4px; }
.msg.typing .dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(123,111,243,0.8); display:inline-block; animation: dots-bounce 1.2s infinite ease-in-out; }
.msg.typing .dots i:nth-child(2){ animation-delay: 0.15s; }
.msg.typing .dots i:nth-child(3){ animation-delay: 0.3s; }
@keyframes dots-bounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.6; } 40% { transform: scale(1); opacity: 1; } }

/* Simplified lightbox dialog for inline image zoom */
dialog.lightbox { border: 0; padding: 0; background: transparent; max-width: 95vw; max-height: 95vh; overflow: auto; }
dialog.lightbox::backdrop { background: rgba(0,0,0,0.75); backdrop-filter: blur(3px); }
.lightbox-content { position: relative; display:flex; align-items:center; justify-content:center; width: 100%; height: 100%; min-height: 100%; }
.lightbox-img { 
  max-width: 92vw; 
  max-height: 88vh; 
  display:block; 
  border-radius: 8px; 
  background: #000; 
  object-fit: contain; 
  cursor: zoom-in;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1), max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.lightbox-img.zoomed {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  cursor: zoom-out;
  transform: scale(1);
}
.lb-close { position:absolute; top: 12px; right: 12px; min-width: 48px; min-height: 48px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.4); background: rgba(0,0,0,0.6); color:#fff; cursor:pointer; display:flex; align-items:center; justify-content:center; transition: all 0.2s ease; z-index: 1; }
.lb-close:hover { background: rgba(0,0,0,0.8); transform: scale(1.05); }
.lb-close:active { transform: scale(0.95); }

/* Floating purple contact CTA - wrapper for centering */
.contact-cta-wrapper {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  z-index: 10;
  display: none;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}
.contact-cta-wrapper.show { display: flex; }

.contact-cta { 
  display: inline-flex;
  align-items: center; 
  justify-content: center; 
  gap: 10px; 
  padding: 12px 24px; 
  min-height: 52px; 
  border-radius: 999px; 
  border: 0; 
  cursor: pointer; 
  font-weight: 700; 
  color: #fff; 
  background: linear-gradient(135deg,#6C5CE7,#A66CFF); 
  box-shadow: 0 10px 24px rgba(108,92,231,0.35); 
  font-size: 15px; 
  line-height: 1.25; 
  text-align: center; 
  width: auto;
  max-width: calc(100% - 32px);
  pointer-events: auto;
  flex-shrink: 0;
}
.contact-cta span { white-space: nowrap; }
.contact-cta svg { flex-shrink: 0; opacity: 0.9; }
.contact-cta::after { content: ''; position: absolute; inset: -8px -12px; }
.contact-cta-enabled { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
@media (max-width: 860px) {
  .contact-cta { padding: 14px 24px; font-size: 16px; }
  .contact-cta-enabled { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
}
@media (max-width: 480px) {
  .contact-cta-wrapper { bottom: 14px; }
  .contact-cta { padding: 13px 20px; }
  .contact-cta-enabled { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
}
.root.is-landing .contact-cta-wrapper { display: none !important; }
.contact-cta:hover { filter: brightness(1.04); }
.contact-cta.pulse { animation: cta-pulse 1.4s ease-in-out 2; }
@keyframes cta-pulse { 
  0% { transform: scale(1); box-shadow: 0 10px 24px rgba(108,92,231,0.35); } 
  50% { transform: scale(1.06); box-shadow: 0 16px 34px rgba(108,92,231,0.45); } 
  100% { transform: scale(1); box-shadow: 0 10px 24px rgba(108,92,231,0.35); } 
}

/* Contact dialog */
.contact-dialog { border: 0; padding: 0; background: transparent; }
.contact-dialog::backdrop { background: rgba(0,0,0,0.45); backdrop-filter: blur(2px); }
.contact-panel { width: min(560px, 92vw); min-height: 360px; background: var(--panel); color: var(--fg); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: 0 20px 48px rgba(0,0,0,0.28); display: flex; flex-direction: column; }
.contact-panel h3 { margin: 6px 0 12px; font-size: 16px; }
.contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex: 1 1 auto; align-content: start; }
.contact-grid .full { grid-column: 1 / -1; }
.contact-grid .msg-wrap { display: flex; flex-direction: column; min-height: 0; }
.contact-panel label { font-size: 12px; opacity: 0.9; display:block; margin-bottom: 4px; }
.contact-panel input, .contact-panel select, .contact-panel textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--inputBg); color: var(--fg); }
.contact-grid .msg-wrap textarea { flex: 1 1 auto; min-height: 160px; resize: vertical; }
.contact-panel .consent { display:flex; align-items:flex-start; gap:8px; font-size:12px; }
.contact-panel .actions { display:flex; justify-content:flex-end; gap:8px; margin-top: 12px; }
.contact-panel .error { color:#d14343; font-size:12px; margin-top:6px; }
.contact-close { position:absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 999px; border: 1px solid var(--border); background: var(--inputBg); color: var(--fg); display:flex; align-items:center; justify-content:center; cursor: pointer; }
.contact-close:hover { background: rgba(123,111,243,0.08); border-color: #7B6FF3; color:#7B6FF3; }

/* Mobile positioning for CTA (stay above composer) */
@media (max-width: 860px) {
  .contact-cta { right: 12px; left: auto; }
}

/* WCAG 2.2: Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  /* Keep essential animations but make them instant */
  .icon-btn:active, .send-btn:active, .btn:active, .lb-close:active {
    transition: none;
  }
}

/* light */
body.light { --bg:#ffffff; --fg:#0a0a0a; --panel:#fafafa; --border:#e5e5e5; --inputBg:#ffffff; --bubble:#f6f7fb; --bubbleFg:#0a0a0a; --bubbleUser:#6C5CE7; --bubbleUserFg:#ffffff; }
/* dark */
body.dark { --bg:#0b0b10; --fg:#f1f3f5; --panel:#0f1016; --border:#21222c; --inputBg:#0f1016; --bubble:#161824; --bubbleFg:#f1f3f5; --bubbleUser:#7B6FF3; --bubbleUserFg:#ffffff; }
