/* ========================================
   CSS Variables & Root Configuration
   ======================================== */
:root {
  color-scheme: light dark;
}

/* ========================================
   Widget Isolation / Design Rules
   ======================================== */
#ailc-widget,
#ailc-widget * {
  box-sizing: border-box;
}

#ailc-widget,
#ailc-widget::before,
#ailc-widget::after,
#ailc-widget *::before,
#ailc-widget *::after,
#ailc-widget * {
  font: inherit;
  color: inherit;
}

#ailc-widget {
  isolation: isolate;
  contain: layout style paint;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

#ailc-widget button,
#ailc-widget input,
#ailc-widget select,
#ailc-widget textarea {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
}

#ailc-widget h1,
#ailc-widget h2,
#ailc-widget h3,
#ailc-widget h4,
#ailc-widget h5,
#ailc-widget h6 {
  font-family: inherit;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-rendering: optimizeLegibility;
  text-transform: none;
}

/* ========================================
   Widget Container
   ======================================== */
#ailc-widget {
  all: initial;
  /* Custom Properties */
  --ailc-primary-color: #4f46e5;
  --ailc-primary-hover: #4338ca;
  --ailc-shadow-main: 0 12px 30px rgba(0, 0, 0, 0.12);
  --ailc-shadow-hover: 0 16px 36px rgba(0, 0, 0, 0.14);
  --ailc-border-color: rgba(226, 232, 240, 0.8);
  --ailc-transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --ailc-radius-lg: 16px;
  --ailc-radius-md: 12px;
  --ailc-radius-sm: 10px;
  
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Inter", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #0f172a;
  background-clip: padding-box;
  text-size-adjust: 100%;

  /* Layout */
  position: fixed;
  z-index: 2147483646;
  display: flex;
  flex-direction: column;
  
  /* Dimensions */
  width: min(400px, 92vw);
  height: 600px;
  
  /* Visual Style */
  border: 1px solid var(--ailc-border-color);
  border-radius: var(--ailc-radius-lg);
  box-shadow: var(--ailc-shadow-main);
  backdrop-filter: blur(20px) saturate(180%);
  
  /* Typography */
  
  /* Effects */
  overflow: hidden;
  transition: var(--ailc-transition-smooth);
  transform: translateY(0);
  opacity: 1;
}

/* Widget States */
#ailc-widget.minimized {
  height: 68px;
  border-radius: var(--ailc-radius-lg) var(--ailc-radius-lg) 0 0;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
  cursor: pointer;
}

#ailc-widget.minimized:hover {
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.1);
}

#ailc-widget.minimized #ailc-body,
#ailc-widget.minimized #ailc-input {
  display: none;
}

#ailc-widget.minimized #ailc-header {
  border-bottom: none;
  padding: 1.125rem 1.5rem;
}

#ailc-widget.minimized #ailc-header h3 {
  font-size: 1rem;
}

#ailc-widget.minimized #ailc-header small {
  display: none;
}

#ailc-widget.minimized .ailc-actions button {
  padding: 0.4rem 0.85rem;
  font-size: 0.875rem;
}

/* Theme Variants */
#ailc-widget.dark {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.98));
  color: #f1f5f9;
  --ailc-border-color: rgba(71, 85, 105, 0.5);
}

#ailc-widget:not(.dark) {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98));
  color: #1e293b;
}

/* Position Variants */
#ailc-widget.pos-br {
  bottom: 24px;
  right: 24px;
}

#ailc-widget.pos-br.minimized {
  bottom: 0;
}

#ailc-widget.pos-bl {
  bottom: 24px;
  left: 24px;
}

#ailc-widget.pos-bl.minimized {
  bottom: 0;
}

#ailc-widget.pos-tr {
  top: 24px;
  right: 24px;
}

#ailc-widget.pos-tr.minimized {
  top: auto;
  bottom: 0;
  border-radius: var(--ailc-radius-lg) var(--ailc-radius-lg) 0 0;
}

#ailc-widget.pos-tl {
  top: 24px;
  left: 24px;
}

#ailc-widget.pos-tl.minimized {
  top: auto;
  bottom: 0;
  border-radius: var(--ailc-radius-lg) var(--ailc-radius-lg) 0 0;
}

/* Default: keep the FAB hidden. It will be shown only on small screens
   inside a minimized state (pos-br mobile). */
#ailc-fab {
  display: none;
}

/* ========================================
   Header Section
   ======================================== */
#ailc-widget #ailc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  background: rgba(255, 255, 255, 0.5);
}

#ailc-widget.dark #ailc-header {
  background: rgba(15, 23, 42, 0.3);
}

#ailc-widget #ailc-header > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#ailc-widget #ailc-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: inherit !important;
}

#ailc-widget #ailc-header small {
  font-size: 0.8125rem;
  color: rgba(100, 116, 139, 0.9);
  font-weight: 500;
}

#ailc-widget.dark #ailc-header small {
  color: rgba(203, 213, 225, 0.7);
}

#ailc-widget #ailc-header .ailc-actions {
  display: flex;
  gap: 0.5rem;
}

/* ========================================
   Buttons
   ======================================== */
#ailc-widget button {
  /* Layout */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  
  /* Style */
  border: none;
  border-radius: 8px;
  background: rgba(100, 116, 139, 0.1);
  color: inherit;
  
  /* Typography */
  font-size: 0.875rem;
  font-weight: 500;
  
  /* Interaction */
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#ailc-widget button:hover {
  background: rgba(100, 116, 139, 0.2);
  transform: translateY(-1px);
}

#ailc-widget button:active {
  transform: translateY(0);
}

#ailc-widget button:focus {
  outline: 2px solid var(--ailc-primary-color);
  outline-offset: 2px;
}

#ailc-widget button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

#ailc-widget button.primary {
  background: var(--ailc-primary-color);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.14);
}

#ailc-widget button.primary:hover {
  background: var(--ailc-primary-hover);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35);
  transform: translateY(-2px);
}

#ailc-widget button.primary:active {
  transform: translateY(0);
}

/* ========================================
   Body & Messages Container
   ======================================== */
#ailc-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  overflow: hidden;
}

#ailc-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  /* Increase vertical spacing between messages so chat bubbles don't look
     too close together (gives better readability) */
  gap: 2rem; /* stronger spacing for easier reading */
  padding-right: 0.5rem;
  /* Add bottom padding so the last message isn't flush against the input */
  padding-bottom: 1.25rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.4) transparent;
}

/* Scrollbar Styling */
#ailc-messages::-webkit-scrollbar {
  width: 8px;
}

#ailc-messages::-webkit-scrollbar-track {
  background: transparent;
}

#ailc-messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 4px;
  transition: background 0.2s;
}

#ailc-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.6);
}

/* ========================================
   Chat Messages
   ======================================== */
.ailc-chat-message {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  /* small top spacing applied to each message row */
  margin-top: 0.5rem;
  animation: messageSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.ailc-chat-message.ailc-user {
  justify-content: flex-end;
}

/* Message Avatars */
.ailc-chat-message .ailc-avatar {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
  font-size: 1rem;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid rgba(99, 102, 241, 0.2);
}

#ailc-widget.dark .ailc-chat-message .ailc-avatar {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
  border-color: rgba(99, 102, 241, 0.3);
}

.ailc-chat-message .ailc-avatar:hover {
  transform: scale(1.15);
}

/* Message Bubbles */
.ailc-bubble {
  position: relative;
  max-width: 80%;
  padding: 0.875rem 1.125rem;
  border-radius: var(--ailc-radius-md);
  line-height: 1.5;
  word-break: break-word;
  /* Preserve whitespace and newlines from AI messages or user input */
  white-space: pre-wrap;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  /* Give small bottom margin to create extra breathing room around
     stacked bubbles (especially useful for multi-line bubbles) */
  margin-bottom: 0.75rem;
}

/* Extra separation when speaker alternates to visually separate different speakers */
.ailc-chat-message.ailc-ai + .ailc-chat-message.ailc-user,
.ailc-chat-message.ailc-user + .ailc-chat-message.ailc-ai {
  margin-top: 1rem;
}

/* Compact spacing for small screens where full spacing might push content off-screen */
@media (max-width: 420px) {
  #ailc-messages { gap: 1rem; }
  .ailc-chat-message { margin-top: 0.35rem; }
  .ailc-bubble { margin-bottom: 0.5rem; }
}

.ailc-bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* Bubble Variants */
.ailc-chat-message.ailc-ai .ailc-bubble {
  background: rgba(241, 245, 249, 0.9);
  border: 1px solid rgba(226, 232, 240, 0.8);
  color: #1e293b;
}

#ailc-widget.dark .ailc-chat-message.ailc-ai .ailc-bubble {
  background: rgba(30, 41, 59, 0.6);
  border-color: rgba(51, 65, 85, 0.8);
  color: #f1f5f9;
}

.ailc-chat-message.ailc-user .ailc-bubble {
  background: linear-gradient(135deg, var(--ailc-primary-color), var(--ailc-primary-hover));
  border: 1px solid transparent;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* Bubble Content Formatting */
.ailc-bubble code {
  display: inline-block;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  background: rgba(100, 116, 139, 0.15);
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  font-size: 0.875em;
  border: 1px solid rgba(100, 116, 139, 0.2);
}

.ailc-chat-message.ailc-user .ailc-bubble code {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

/* Bubble Copied State */
.ailc-bubble.copied {
  animation: copiedPulse 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.ailc-bubble.copied::after {
  content: "Kopyalandı";
  position: absolute;
  top: -2rem;
  right: 0;
  padding: 0.375rem 0.75rem;
  border-radius: 8px;
  background: rgba(16, 185, 129, 0.95);
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
  animation: fadeInUp 0.3s ease;
}

/* ========================================
   Typing Indicator
   ======================================== */
#ailc-typing {
  display: none;
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: rgba(148, 163, 184, 0.9);
}

#ailc-typing .dots span {
  display: inline-block;
  margin-left: 0.15rem;
  animation: blink 1.2s infinite;
}

#ailc-typing .dots span:nth-child(2) {
  animation-delay: 0.2s;
}

#ailc-typing .dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ========================================
   Input Section
   ======================================== */
#ailc-input {
  display: flex;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--ailc-border-color);
  background: rgba(255, 255, 255, 0.3);
}

#ailc-widget.dark #ailc-input {
  background: rgba(15, 23, 42, 0.2);
}

#ailc-input input {
  flex: 1;
  padding: 0.875rem 1.125rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: var(--ailc-radius-sm);
  background: rgba(255, 255, 255, 0.8);
  color: inherit;
  font-size: 0.9375rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#ailc-widget.dark #ailc-input input {
  background: rgba(30, 41, 59, 0.5);
  border-color: rgba(71, 85, 105, 0.5);
}

#ailc-input input:focus {
  outline: none;
  border-color: var(--ailc-primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  background: rgba(255, 255, 255, 1);
}

#ailc-widget.dark #ailc-input input:focus {
  background: rgba(30, 41, 59, 0.8);
}

/* ========================================
   Intro Form
   ======================================== */
#ailc-intro {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#ailc-intro input,
#ailc-intro select {
  padding: 0.875rem 1rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: var(--ailc-radius-sm);
  background: rgba(255, 255, 255, 0.8);
  color: inherit;
  font-size: 0.9375rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#ailc-intro select {
  all: unset;
  box-sizing: border-box !important;
  display: block !important;
  width: 100% !important;
  height: auto !important;
  min-height: 48px !important;
  padding: 12px 16px !important;
  border-radius: var(--ailc-radius-sm) !important;
  border: 1px solid rgba(148, 163, 184, 0.3) !important;
  background-color: rgba(255, 255, 255, 0.8);
  color: inherit;
  font-family: inherit !important;
  font-size: 0.9375rem !important;
  line-height: 1.5 !important;
  letter-spacing: normal !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 0.5rem) calc(50% + 2px), calc(100% - 0.35rem) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.5rem !important;
  text-transform: none !important;
  margin: 0 !important;
}

#ailc-widget.dark #ailc-intro input,
#ailc-widget.dark #ailc-intro select {
  background: rgba(30, 41, 59, 0.5) !important;
  border-color: rgba(71, 85, 105, 0.5) !important;
}

#ailc-intro input:focus,
#ailc-intro select:focus {
  outline: none;
  border-color: var(--ailc-primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  background: rgba(255, 255, 255, 1);
}

#ailc-widget.dark #ailc-intro input:focus,
#ailc-widget.dark #ailc-intro select:focus {
  background: rgba(30, 41, 59, 0.8);
}

#ailc-intro .ailc-intro__notice {
  padding: 0.75rem 1rem;
  border-radius: var(--ailc-radius-sm);
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.15);
  color: #b91c1c;
  font-size: 0.85rem;
}

#ailc-widget.dark #ailc-intro .ailc-intro__notice {
  background: rgba(248, 113, 113, 0.25);
  color: #fee2e2;
  border-color: rgba(248, 113, 113, 0.6);
}

/* ========================================
   Animations
   ======================================== */
@keyframes blink {
  0%, 80%, 100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes copiedPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   Responsive Design
   ======================================== */

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 640px) {
  #ailc-widget {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    transform: none !important;
    margin: 0 !important;
  }

  #ailc-widget.minimized {
    top: auto !important;
    bottom: 0 !important;
    height: auto !important;
    min-height: 72px;
    border-radius: var(--ailc-radius-lg) var(--ailc-radius-lg) 0 0 !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15) !important;
  }

  #ailc-widget.minimized #ailc-header {
    padding: 1rem 1.25rem;
    border-bottom: none;
  }

  #ailc-widget #ailc-header {
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  #ailc-widget #ailc-input {
    padding: 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  #ailc-messages {
    padding: 1rem;
    padding-bottom: 1rem;
  }

  .ailc-bubble {
    max-width: 88%;
  }

  /* Prevent iOS zoom */
  #ailc-widget input,
  #ailc-widget select,
  #ailc-widget button {
    font-size: 16px !important;
  }

  /* Mobile Floating Action Button (FAB) - mobile-only minimized style */

  /* When minimized, show the circle in the lower-right for pos-br only */
  #ailc-widget.pos-br.minimized {
    width: 64px !important;
    height: 64px !important;
    min-height: 0 !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    bottom: max(12px, env(safe-area-inset-bottom)) !important;
    left: auto !important;
    top: auto !important;
    border-radius: 999px !important;
    padding: 0 !important;
    overflow: visible !important;
    box-shadow: 0 8px 28px rgba(0,0,0,0.2) !important;
    transition: transform 0.24s ease, width 0.24s ease, height 0.24s ease;
  }

  /* Keep controls visually hidden inside the FAB */
  #ailc-widget.pos-br.minimized #ailc-header,
  #ailc-widget.pos-br.minimized #ailc-body,
  #ailc-widget.pos-br.minimized #ailc-input {
    display: none !important;
  }

  #ailc-widget.pos-br.minimized #ailc-fab {
    display: flex;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 999px;
    background: var(--ailc-primary-color);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    box-shadow: inherit;
    -webkit-tap-highlight-color: transparent;
  }

  /* Hide the header action buttons when in the FAB state so it looks clean */
  #ailc-widget.pos-br.minimized .ailc-actions,
  #ailc-widget.pos-br.minimized #ailc-toggle {
    display: none !important;
  }

  /* Ani/hover for the FAB */
  #ailc-widget.pos-br.minimized #ailc-fab:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 34px rgba(0,0,0,0.2);
  }

  /* For non bottom-right positions, fallback to bottom full-width bar */
  #ailc-widget.pos-bl.minimized,
  #ailc-widget.pos-tl.minimized,
  #ailc-widget.pos-tr.minimized {
    width: 100% !important;
  }

}

/* Only show the FAB on small screens (mobile). If the widget is minimized on
   desktop, the icon should remain hidden. This helps ensure the floating
   action control is mobile-only. */
@media (min-width: 641px) {
  /* Explicitly keep the FAB hidden on desktop when minimized for any position */
  #ailc-widget.pos-br.minimized #ailc-fab,
  #ailc-widget.pos-bl.minimized #ailc-fab,
  #ailc-widget.pos-tl.minimized #ailc-fab,
  #ailc-widget.pos-tr.minimized #ailc-fab {
    display: none !important;
  }
}


/* ========================================
   Accessibility & Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  #ailc-widget,
  #ailc-widget button,
  .ailc-chat-message,
  .ailc-chat-message .ailc-avatar,
  .ailc-bubble {
    transition: none;
    animation: none;
  }
}
