/* =================== FINAL, STABLE chat-widget.css =================== */
:root {
  --font-primary: 'Inter', sans-serif;
  --border-radius-lg: 20px;
  --transition-med: all 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  --primary-color: #10B981;
  --bg-color: #1A1A1A;
  --header-bg: #222222;
  --border-color: rgba(255, 255, 255, 0.1);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.4);
  /* text color used for message bubbles (overridden in light theme) */
  --chat-text-color: #ffffff;
}

#orrya-chat-widget {
  position: fixed;
  z-index: 9999;
}

/* --- Toggle Button --- */
.chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background-color: var(--primary-color);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
#orrya-chat-widget.is-open .chat-toggle {
  transform: scale(0);
  opacity: 0;
}

/* --- Main Container --- */
.chat-widget-container {
  display: none; /* Hidden by default, shown by JS */
  flex-direction: column;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  overflow: hidden;
  transition: var(--transition-med);
}

/* Default Desktop Styles */
.chat-widget-container {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 400px;
  height: 600px;
  max-height: calc(100vh - 110px);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
}
#orrya-chat-widget.is-open .chat-widget-container {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Mobile-specific styles using the .mobile-layout class */
#orrya-chat-widget.mobile-layout .chat-widget-container {
  width: 100vw;
  /* Use the --vh variable calculated by JS for accurate height */
  height: calc(var(--vh, 1vh) * 100);
  max-height: calc(var(--vh, 1vh) * 100);
  bottom: 0;
  right: 0;
  border-radius: 0;
  transform: translateY(100%); /* Animate from bottom */
}
#orrya-chat-widget.mobile-layout.is-open .chat-widget-container {
  transform: translateY(0);
}


/* --- Shared child element styles --- */
.chat-header {
  padding: 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 16px;
}
.chat-input-container {
  padding: 12px;
  background: var(--header-bg);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  display: flex;
}
.chat-input {
  width: 100%;
  padding: 12px;
  background: #2C2C2C;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: white;
  font-size: 16px;
}
.send-button {
  margin-left: 8px;
  /* Add other styles for your send button */
}
body.chat-open {
  overflow: hidden; /* Prevent body scroll when chat is open on mobile */
}
/* =================================== */
/* === Close & Send Button Styles === */
/* =================================== */

/* --- Close Button --- */
.chat-close {
  background: transparent;
  border: none;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888; /* Muted color for the icon */
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-close:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
  transform: rotate(90deg);
}

.chat-close svg {
  width: 20px;
  height: 20px;
}

/* --- Send Button --- */
.send-button {
  background: var(--primary-color);
  border: none;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  margin-left: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-button:hover {
  background: var(--primary-dark, #059669); /* Uses the darker shade from our variables */
  transform: scale(1.1);
}

.send-button:active {
  transform: scale(1);
}

.send-button svg {
  width: 20px;
  height: 20px;
  /* Nudge the icon a bit for perfect visual centering */
  margin-left: 2px; 
  margin-bottom: 2px;
}
/* =================================== */
/* === Final Polish: Bubbles & Typing Indicator === */
/* =================================== */

/* --- Refined Message Bubble Shapes --- */
.message {
    padding: 12px 18px; /* Slightly more padding for a softer feel */
    line-height: 1.6;
    max-width: 85%;
    font-size: 0.95rem;
  color: var(--chat-text-color); /* ensure bubble text uses the chat-specific color */
}

.user-message {
    /* Softer, more rounded bubble shape with a 'tail' on the bottom right */
    border-radius: 22px 22px 6px 22px;
}

.bot-message {
    background: #2F2F2F; /* A slightly different shade for bot messages */
    /* Softer, more rounded bubble shape with a 'tail' on the bottom left */
    border-radius: 22px 22px 22px 6px;
}


/* --- Modern "Thinking" Indicator --- */
.message.typing {
    background: #2F2F2F;
    padding: 16px 18px; /* Give it a fixed padding */
    width: fit-content; /* Ensure it's only as wide as the dots */
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 7px; /* Space between dots */
}

/* Each individual dot */
.typing-dots span {
    width: 9px;
    height: 9px;
    background-color: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    animation: pulse 1.5s infinite ease-in-out;
}

/* Stagger the animation for a wave effect */
.typing-dots span:nth-of-type(1) {
    animation-delay: -0.3s;
}
.typing-dots span:nth-of-type(2) {
    animation-delay: -0.15s;
}
.typing-dots span:nth-of-type(3) {
    animation-delay: 0s;
}

/* The subtle pulsing animation */
@keyframes pulse {
    0%, 100% {
        transform: scale(0.75);
        opacity: 0.6;
    }
    50% {
        transform: scale(1);
        opacity: 1;
    }
}

/* =================== Light theme overrides =================== */
/* When the site uses the light theme we make the chat widget use
   light-friendly backgrounds and dark text so content remains readable. */
[data-theme="light"] #orrya-chat-widget .chat-widget-container {
  background: var(--surface-light, #ffffff);
  border-color: rgba(0, 0, 0, 0.06);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

[data-theme="light"] #orrya-chat-widget {
  /* ensure bubble text uses dark color in light theme */
  --chat-text-color: var(--text-primary-dark, #1a1a1a);
}

/* Fallbacks: some sites use classes instead of data-theme attribute */
body.light #orrya-chat-widget,
body.theme-light #orrya-chat-widget,
.light #orrya-chat-widget,
.theme-light #orrya-chat-widget {
  --chat-text-color: var(--text-primary-dark, #1a1a1a);
  /* ensure widget surfaces also use light variants */
}

/* Make sure input placeholder and text are readable in light theme fallbacks */
body.light #orrya-chat-widget .chat-input,
body.theme-light #orrya-chat-widget .chat-input,
.light #orrya-chat-widget .chat-input,
.theme-light #orrya-chat-widget .chat-input,
[data-theme="light"] #orrya-chat-widget .chat-input {
  color: var(--text-primary-dark, #1a1a1a);
}

body.light #orrya-chat-widget .chat-input::placeholder,
body.theme-light #orrya-chat-widget .chat-input::placeholder,
.light #orrya-chat-widget .chat-input::placeholder,
.theme-light #orrya-chat-widget .chat-input::placeholder,
[data-theme="light"] #orrya-chat-widget .chat-input::placeholder {
  color: rgba(0,0,0,0.45);
}

[data-theme="light"] #orrya-chat-widget .chat-header,
[data-theme="light"] #orrya-chat-widget .chat-input-container {
  background: var(--surface-light, #ffffff);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

[data-theme="light"] #orrya-chat-widget .chat-input {
  background: #ffffff;
  color: var(--text-primary-dark, #1a1a1a);
  border: 1px solid rgba(0,0,0,0.08);
}

[data-theme="light"] #orrya-chat-widget .message {
  color: var(--text-primary-dark, #1a1a1a);
}

[data-theme="light"] #orrya-chat-widget .bot-message {
  background: #f1f3f4; /* subtle light bubble */
  color: var(--text-primary-dark, #1a1a1a);
}

[data-theme="light"] #orrya-chat-widget .user-message {
  background: rgba(16,184,129,0.08); /* gentle primary tint */
  color: var(--text-primary-dark, #1a1a1a);
  border: 1px solid rgba(0,0,0,0.04);
}

[data-theme="light"] #orrya-chat-widget .message.typing {
  background: #f1f3f4;
}

[data-theme="light"] #orrya-chat-widget .typing-dots span {
  background-color: rgba(0,0,0,0.35);
}

[data-theme="light"] #orrya-chat-widget .chat-close {
  color: #444;
}

[data-theme="light"] #orrya-chat-widget .chat-toggle {
  box-shadow: 0 6px 20px rgba(16,185,129,0.15);
}

/* Stronger, explicit light-mode rules to guarantee readability */
[data-theme="light"] #orrya-chat-widget .chat-header,
[data-theme="light"] body.light #orrya-chat-widget .chat-header,
body.theme-light #orrya-chat-widget .chat-header,
.light #orrya-chat-widget .chat-header,
.theme-light #orrya-chat-widget .chat-header {
  background: #ffffff;
  color: var(--text-primary-dark, #1a1a1a);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

[data-theme="light"] #orrya-chat-widget .chat-messages,
body.light #orrya-chat-widget .chat-messages,
.light #orrya-chat-widget .chat-messages {
  background: #ffffff;
}

[data-theme="light"] #orrya-chat-widget .chat-input-container,
body.light #orrya-chat-widget .chat-input-container,
.light #orrya-chat-widget .chat-input-container {
  background: #ffffff;
  border-top: 1px solid rgba(0,0,0,0.06);
}

/* User bubble should be dark text on a soft primary tint */
[data-theme="light"] #orrya-chat-widget .message.user-message,
body.light #orrya-chat-widget .message.user-message,
.light #orrya-chat-widget .message.user-message {
  background: #E6FAF0; /* pale green tint */
  color: #08311a; /* strong dark green for readability */
  border: 1px solid rgba(6, 22, 11, 0.06);
}

/* Bot bubble should be neutral light background with dark text */
[data-theme="light"] #orrya-chat-widget .message.bot-message,
body.light #orrya-chat-widget .message.bot-message,
.light #orrya-chat-widget .message.bot-message {
  background: #F3F4F6; /* neutral light */
  color: var(--text-primary-dark, #1a1a1a);
  border: 1px solid rgba(0,0,0,0.04);
}

/* Typing indicator dots darker in light mode */
[data-theme="light"] #orrya-chat-widget .typing-dots span,
body.light #orrya-chat-widget .typing-dots span,
.light #orrya-chat-widget .typing-dots span {
  background-color: rgba(0,0,0,0.35);
}

/* Close and toggle icon colors */
[data-theme="light"] #orrya-chat-widget .chat-close,
body.light #orrya-chat-widget .chat-close,
.light #orrya-chat-widget .chat-close {
  color: #444;
}

[data-theme="light"] #orrya-chat-widget .chat-toggle svg,
body.light #orrya-chat-widget .chat-toggle svg,
.light #orrya-chat-widget .chat-toggle svg {
  color: #fff; /* toggle uses primary background, keep icon white */
}

/* Ensure send-button icon is visible on light backgrounds */
[data-theme="light"] #orrya-chat-widget .send-button svg,
body.light #orrya-chat-widget .send-button svg,
.light #orrya-chat-widget .send-button svg {
  color: #fff;
}

/* Make sure message text uses the chat variable (defensive specificity) */
[data-theme="light"] #orrya-chat-widget .message,
body.light #orrya-chat-widget .message,
.light #orrya-chat-widget .message {
  color: var(--chat-text-color, #1a1a1a) !important;
}
