:root {
  --blue: #5baaff;
  --pink: #ff5bca;
  --purple: #a172ff;
  --gradient: linear-gradient(90deg, #5baaff 0%, #ff5bca 50%, #a172ff 100%);
  --gradient-btn: linear-gradient(89deg, #fc67fa 0%, #5baaff 100%);
  --gradient-selector: linear-gradient(90deg, #fc67fa 0%, #a172ff 100%);
  --bg: #000000;
  --chat-bg: #000000;
  --bot-bg: #191919; /* Set to blue for bot messages as requested previously */
  --bot-text: #fff;
  --user-bg: #2563eb;
  --radius: 32px;
  --shadow: 0 6px 24px rgba(0,0,0,0.28);
  --text: #f3f4fa;
  font-family: 'Google Sans', Arial, sans-serif;
}

body {
  background: var(--bg);
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100vw;
  background: var(--bg);
  min-height: 100vh;
  box-sizing: border-box;
  padding-bottom: 58px;
}

.outer-gradient-border {
  background: var(--gradient);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px;
  width: 95vw;
  max-width: 100vw;
  height: 75vh;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  box-sizing: border-box;
}

.ai-search-container {
  background: var(--chat-bg);
  border-radius: calc(var(--radius) - 3px);
  width: 100%;
  height: 100%;
  min-height: 200px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  padding: 20px 10px 20px 10px;
  justify-content: flex-end;
}

.chat-window {
  flex: 1 1 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 0 8px 18px 8px;
  min-height: 80px;
  background: var(--chat-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  position: relative;
  box-sizing: border-box;
}

.chat-brand-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 22px 0 14px 0;
  animation: fadeIn 2s;
}

.brand-logo-wrapper {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  box-shadow: 0 0 0 3px rgba(91,170,255,0.12);
}
.brand-logo { width: 70px; height: 70px; object-fit: contain; border-radius: 50%; display: block; aspect-ratio: 1 / 1; }
.brand-welcome { color: var(--text); font-size: 1.3rem; font-weight: 500; letter-spacing: 0.01em; opacity: 0.91; }

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9);}
  to { opacity: 1; transform: scale(1);}
}

.input-area-wrapper {
  display: flex; flex-direction: column; align-items: stretch; gap: 0.5em; width: 100%;
  background: transparent; border-radius: var(--radius); padding: 0; margin-top: 0; box-sizing: border-box; position: relative;
}
.textfield-container {
  display: flex; align-items: flex-end; background: #23242a; border-radius: 20px; width: 100%; padding: 0; margin-bottom: 0; position: relative;
  box-sizing: border-box;
}
#user-input {
  flex: 1 1 0; padding: 14px 18px 14px 18px; border-radius: 20px; border: none; outline: none; background: transparent; color: var(--text); font-size: 1.09rem;
  transition: box-shadow 0.18s, border-radius 0.18s; box-sizing: border-box; margin: 0; resize: none; min-height: 44px; max-height: 184px; line-height: 1.6; overflow-y: auto; width: 100%;
}

.sendbar-row { display: flex; flex-direction: row; align-items: center; justify-content: space-between; margin-top: 7px; width: 100%; gap: 0; padding: 0; }
.model-selector-bar-inline { display: flex; flex-direction: row; align-items: center; width: 100%; justify-content: space-between; gap: 0; }
.model-selector-wrapper { position: relative; display: inline-block; vertical-align: middle; margin-right: 0; }

/* send button with custom gradient */
#send-btn {
  background: var(--gradient-btn);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  box-shadow: 0 2px 8px #1a73e820;
  cursor: pointer;
  transition: background 0.18s;
  font-weight: 500;
  outline: none;
  margin-left: auto;
  margin-right: 0;
  position: relative;
  padding: 0;
  z-index: 2;
}
#send-btn .send-icon { width: 30px; height: 30px; display: block; }
#send-btn:hover {
  background: linear-gradient(90deg,#5baaff 0%,#ff5bca 60%,#a172ff 100%);
  color: #fff;
}

#model-selector-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #23242a;
  color: #f3f4fa;
  border: none;
  border-radius: 18px;
  padding: 6px 16px 6px 10px;
  cursor: pointer;
  font-size: 1.05rem;
  font-family: inherit;
  transition: background 0.15s;
  outline: none;
  min-width: 112px;
  margin-right: 4px;
  height: 38px;
  position: relative;
  z-index: 3;
}

.emoji-dropdown {
  font-size: 0.95em;
  margin-left: 2px;
}

/* Model dropdown container - this is the small, inline dropdown now */
.model-dropdown {
  display: none; /* Hidden by default, toggled by JS */
  position: absolute;
  left: 0;
  bottom: 110%; /* Position above the button */
  min-width: 160px;
  background: #23242a;
  border-radius: 18px;
  box-shadow: 0 2px 14px #23243a90;
  z-index: 10;
  padding: 10px;
  border: 1px solid #282a3a;

  /* Flexbox for single column & scrollability */
  flex-direction: column; /* Stacks items vertically */
  gap: 0; /* No gap between columns, items are in one column */
  flex-wrap: nowrap;
  overflow-x: hidden; /* Hide horizontal scroll */
  overflow-y: auto; /* Enable vertical scrolling */
  max-height: 250px; /* Set maximum height as requested */

  -webkit-overflow-scrolling: touch; /* For smoother scrolling on iOS */
  scrollbar-width: thin; /* Firefox scrollbar */
  -ms-overflow-style: -ms-autohiding-scrollbar; /* IE and Edge scrollbar */
}

/* Custom scrollbar styling for Chrome, Safari, Opera */
.model-dropdown::-webkit-scrollbar {
    width: 8px; /* Width of the scrollbar */
    background-color: #333a45; /* Track color */
    border-radius: 4px;
}

.model-dropdown::-webkit-scrollbar-thumb {
    background-color: #555c6b; /* Handle color */
    border-radius: 4px;
}
.model-dropdown::-webkit-scrollbar-thumb:hover {
    background-color: #6a748c; /* Handle hover color */
}

.model-dropdown.open {
  display: flex; /* Show when 'open' class is present */
  animation: fadeIn 0.18s;
}

/* Styles for columns within the model-dropdown (now effectively a single column holder) */
.model-dropdown .model-column {
    display: flex;
    flex-direction: column; /* Ensures items within this single "column" stack vertically */
    min-width: 100%; /* Take full width of the dropdown */
    border-right: none; /* No border for the single column */
    padding-right: 0; /* No padding for the separator */
}

.model-dropdown .column-header {
    color: #8c97b2;
    font-size: 0.85em;
    font-weight: 700;
    text-transform: uppercase;
    margin-top: 10px; /* Add some space between groups */
    margin-bottom: 8px;
    padding: 0 18px; /* Match switch-model-item padding for alignment */
}

.model-dropdown .model-column .column-header:first-child {
    margin-top: 0; /* No top margin for the very first header */
}

/* Model option items inside the inline dropdown */
.model-dropdown .model-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 18px;
  cursor: pointer;
  color: #f3f4fa;
  font-size: 1.05rem;
  border-radius: 14px;
  margin: 2px 0;
  transition: background 0.13s, color 0.13s;
  position: relative;
  white-space: nowrap;
}

.model-dropdown .model-option.selected,
.model-dropdown .model-option.selected:hover {
  background: var(--gradient-selector);
  color: #fff;
  border-radius: 14px;
  box-shadow: 0 2px 8px #c67aff60;
  padding-left: 18px;
  padding-right: 18px;
}

.model-dropdown .model-option:hover:not(.selected) {
  background: #23243a;
  color: #fff;
}


.model-icon { font-size: 1.15em; }
.model-label { font-size: 1.10em; }

/* Message bubbles */
.message {
  display: flex;
  align-items: flex-start; /* Changed to flex-start to align avatar and content wrapper */
  gap: 10px;
  max-width: 95%;
  position: relative;
  /* Removed flex-wrap here, as message-content-wrapper will manage it */
}
.message.user { align-self: flex-end; flex-direction: row-reverse; justify-content: flex-end; }
.message.bot { align-self: flex-start; flex-direction: row; justify-content: flex-start; } /* Important for bot message alignment */

/* New wrapper for bubble and controls to stack vertically */
.message-content-wrapper {
  display: flex;
  flex-direction: column;
  flex-grow: 1; /* Allows it to take up available space in the message row */
  align-items: flex-start; /* Align bubble and controls to the left within this wrapper */
  max-width: calc(100% - 42px); /* Calc width based on avatar size + gap */
}

.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--purple); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 1.1rem; }
.avatar.user { background: var(--user-bg); color: #fff; }
.avatar.bot { background: var(--bot-bg); color: #fff; }

.bubble {
  padding: 16px 20px;
  border-radius: 18px;
  font-size: 1.12rem;
  box-shadow: 0 1px 4px #0e16253a;
  word-break: break-word;
  white-space: pre-line;
  max-width: 100%; /* Now max-width is relative to message-content-wrapper */
  width: auto; /* Allow width to adjust based on content up to max-width */
  min-width: 40px;
  position: relative;
  display: flex;
  flex-direction: column; /* Keep this as column for general content stacking */
  gap: 8px; /* Gap between text and code inside bubble */
}

.user .bubble {
  background: var(--user-bg);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bot .bubble {
  background: var(--bot-bg);
  color: var(--bot-text);
  border-bottom-left-radius: 6px;
}
/* --- Modern CODE CONTAINER --- */
.code-script-container {
  background: #181c24;
  border-radius: 15px;
  margin-top: 5px; /* Adjusted margin to fit within bubble better */
  box-shadow: 0 2px 8px #0005;
  overflow: hidden;
  font-family: 'JetBrains Mono', 'Fira Mono', 'Menlo', 'Monospace';
  display: flex;
  flex-direction: column;
  width: 100%; /* Ensured code container takes full width of bubble */
}
.code-script-brief {
  color: #60b4fa;
  background: none;
  margin: 0 0 8px 0;
  font-size: 1.08em;
  font-weight: 500;
  border-left: 3px solid #3f8fff;
  padding-left: 12px;
  padding-top: 2px;
  padding-bottom: 2px;
}
.code-script-tab {
  background: #23283a;
  color: #8ad2fa;
  font-size: 0.99em;
  font-weight: 600;
  padding: 7px 16px 7px 16px;
  display: flex;
  align-items: center;
  border-radius: 12px 12px 0 0;
  user-select: all;
  border-bottom: 1px solid #252c3a;
}
.code-script-tab .file-icon {
  background: #25304a;
  color: #6fc5ff;
  border-radius: 5px;
  font-size: 0.97em;
  margin-right: 8px;
  padding: 2px 10px 2px 10px;
  font-family: inherit;
}
.code-script-content {
  background: #15171e;
  overflow-x: auto;
  padding: 18px 0 8px 0;
  color: #e9eaf0;
  font-size: 0.9em;
  border-radius: 0 0 0 0;
  counter-reset: line;
  white-space: pre;
  font-family: 'JetBrains Mono', 'Fira Mono', 'Menlo', monospace;
}
.code-script-content code {
  background: none;
  color: inherit;
  font-size: inherit;
  padding: 0;
  margin: 0;
  display: block;
  line-height: 1.6;
}
.code-line { display: flex; width: 100%; }
.code-lineno {
  color: #586080;
  opacity: 0.55;
  text-align: right;
  min-width: 2.5em;
  padding-right: 1.2em;
  font-size: 1em;
  user-select: none;
  font-family: inherit;
}
.code-line-content {
  flex: 1;
  padding-right: 14px;
  word-break: break-word;
}
.code-script-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #181c24;
  color: #8c97b2;
  font-size: 0.99em;
  padding: 6px 14px 6px 18px;
  border-top: 1px solid #23283a;
}
.code-script-statusbar .code-script-actions {
  display: flex;
  gap: 12px;
}
.code-script-statusbar .code-script-action-btn {
  background: none;
  border: none;
  color: #b2c7e0;
  font-size: 1.12em;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 5px;
  transition: background 0.14s, color 0.14s;
  display: inline-flex;
  align-items: center;
}
.code-script-statusbar .code-script-action-btn:hover {
  background: #23243a;
  color: #fff;
}

/* Controls wrapper for action buttons and generation navigation */
.message-controls-wrapper {
  display: flex;
  flex-wrap: nowrap; /* Ensures they stay on one line */
  justify-content: flex-end; /* Pushes to the right */
  align-items: center;
  gap: 10px; /* Space between generation nav and action buttons */
  width: 100%; /* Take full width of its parent (message-content-wrapper) */
  margin-top: 5px; /* Small margin from the bubble above */
  box-sizing: border-box;
  overflow-x: auto; /* Allows horizontal scrolling if content overflows */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none;  /* IE and Edge */
}

/* Hide scrollbar for Chrome, Safari, Opera */
.message-controls-wrapper::-webkit-scrollbar {
    display: none;
}

/* Adjustments for elements within the new wrapper */
.bot-actions-row {
  margin: 0; /* Remove previous explicit margins */
  flex-shrink: 0;
  order: 2; /* Set order to 2 to appear after generation-nav */
  display: flex; /* Ensure buttons in this row are also flexed */
  gap: 10px; /* Space between individual action buttons */
}
.generation-nav {
  margin: 0; /* Remove previous explicit margins */
  flex-shrink: 0;
  order: 1; /* Set order to 1 to appear before bot-actions-row */
}

/* Ensure action buttons are always aligned left within their row (already correct, keeping for clarity) */
.code-script-statusbar .code-script-action-btn {
  background: none;
  border: none;
  color: #b2c7e0;
  font-size: 1.12em;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 5px;
  transition: background 0.14s, color 0.14s;
  display: inline-flex;
  align-items: center;
}
.code-script-statusbar .code-script-action-btn:hover {
  background: #23243a;
  color: #fff;
}

/* Bot Actions Row (general styling, specific margins handled by parent) */
.bot-actions-row {
  align-items: center;
  /* The gap is now defined in .message-controls-wrapper */
}
.action-btn {
  background: #333a45;
  color: #b2e1f7;
  border: none;
  border-radius: 8px;
  padding: 7px 9px 6px 9px;
  cursor: pointer;
  font-size: 1.23em;
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
  box-shadow: 0 1px 6px #0002;
}
.action-btn:active, .action-btn.selected {
  background: orange;
  color: white;
}
.action-btn:not(:last-child) {
  /* Removed margin-right as gap on parent handles it */
}
.generation-nav {
  align-items: center;
  /* The gap is now defined in .message-controls-wrapper */
  font-size: 1.08em;
  color: #ddd;
  opacity: 0.85;
  user-select: none;
}
.generation-nav button {
  background: none;
  border: none;
  color: #eee;
  font-size: 1.08em;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 7px;
  transition: background 0.13s, color 0.13s;
}
.generation-nav button[disabled] {
  color: #555;
  opacity: 0.6;
  cursor: default;
}
.generation-nav button:hover:enabled {
  background: var(--gradient);
  color: #fff;
}
.generation-nav .gen-indicator {
  font-weight: 600;
  color: #fff;
  margin: 0 3px;
}
.reply-banner {
  margin-left: 40px; /* Keep this as it's a separate element's margin */
  background: #282a36;
  color: #8af;
  font-size: 0.97em;
  padding: 4px 13px;
  border-radius: 7px;
  margin-top: 3px;
}

/* Popup styles (for the larger 'Switch model' popup) */
.switch-model-popup {
  position: fixed;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  background: #23242a;
  border-radius: 18px;
  box-shadow: 0 4px 28px #15172840;
  padding: 16px 0 8px 0;
  width: auto;
  max-width: 90vw;
  display: none; /* Hidden by default, toggled by JS */
  flex-direction: column;
  min-width: 50vw;
  max-height: 50vh; /* Retained for larger popup's scrollability */
}
.switch-model-popup.active { display: flex; }

.switch-model-header {
  font-size: 1.1rem;
  color: #ccc;
  font-weight: 600;
  padding: 8px 28px 8px 28px;
  margin-bottom: 4px;
  border-bottom: 1px solid #343545;
  text-align: left;
}

/* Flexbox for columns within the switch model popup (single column for this too) */
.switch-model-list {
  display: flex;
  flex-direction: column; /* Changed to column for single column layout */
  margin: 6px 0 10px 0;
  gap: 0px; /* No gap between items */
  flex-wrap: nowrap;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  -ms-overflow-style: -ms-autohiding-scrollbar;
  max-height: calc(100% - 70px - 50px); /* Max height to ensure it scrolls */
}

/* Custom scrollbar styling for Chrome, Safari, Opera */
.switch-model-list::-webkit-scrollbar {
    width: 8px;
    background-color: #333a45;
    border-radius: 4px;
}

.switch-model-list::-webkit-scrollbar-thumb {
    background-color: #555c6b;
    border-radius: 4px;
}
.switch-model-list::-webkit-scrollbar-thumb:hover {
    background-color: #6a748c;
}

/* Column styling within the popup (now effectively a single column holder) */
.switch-model-popup .model-column {
    display: flex;
    flex-direction: column;
    min-width: 100%;
    border-right: none;
    padding-right: 0;
}

.switch-model-popup .model-column:last-child {
    border-right: none;
    padding-right: 0;
}

.switch-model-popup .column-header {
    color: #8c97b2;
    font-size: 0.85em;
    font-weight: 700;
    text-transform: uppercase;
    margin-top: 10px;
    margin-bottom: 8px;
    padding: 0 18px;
}

.switch-model-popup .model-column .column-header:first-child {
    margin-top: 0;
}

.switch-model-item {
  padding: 10px 18px;
  font-size: 1.1rem;
  cursor: pointer;
  color: #eee;
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: 14px;
  margin: 6px 0;
  transition: background 0.15s;
}
.switch-model-item[data-selected="true"], .switch-model-item.selected {
  background: var(--gradient-selector);
  color: #fff;
  box-shadow: 0 2px 8px #c67aff60;
}
.switch-model-item:hover {
  background: var(--gradient);
  color: #fff;
}
.switch-model-cancel {
  border: none;
  background: transparent;
  color: #aaa;
  font-size: 1rem;
  padding: 10px 0 0 0;
  cursor: pointer;
  border-radius: 0 0 18px 18px;
  transition: color 0.13s;
}
.switch-model-cancel:hover { color: #fa3; }
.popup-backdrop {
  display: none;
  position: fixed;
  left: 0; top: 0;
  width: 100vw; height: 100vh;
  background: #23243add;
  z-index: 999;
}
.replied-context {
  position: relative;
  width: 100%;
  background: #23242a;
  border-radius: 20px;
  margin-bottom: 0.5em;
  padding: 8px 22px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.replied-msg {
  flex-grow: 1;
  color: #fff;
  font-size: 1em;
  font-family: inherit;
  min-height: 28px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-line;
}

.unreply-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  color: #ffffff;
  border: none;
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8em;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.unreply-btn:hover {
  background: #ffffff;
  color: #ff0800;
}
.popup-backdrop.active { display: block; }
.dev-mark {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Google Sans', Arial, sans-serif;
  font-size: 1.21rem;
  color: #fafafa;
  letter-spacing: 0.04em;
  text-shadow: 0 0 3px #181a20, 0 2px 8px #23243a88;
  font-weight: 500;
  user-select: none;
  opacity: 0.85;
  animation: fadeIn 1.8s;
  padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
  z-index: 99;
  background: transparent;
}
.dev-mark .ayu-logo {
  font-family: 'Google Sans', Arial, sans-serif;
  font-weight: 900;
  letter-spacing: 0.10em;
  color: #fff;
  background: linear-gradient(90deg, #5baaff 0%, #ff5bca 60%, #a172ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-fill-color: transparent;
  font-size: 1.28em;
  margin: 0 0.12em;
}

/* Loading Dots Animation */
@keyframes dot-pulse {
    0%, 80%, 100% {
        opacity: 0.2;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

.loading-dots { /* Added this block */
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    width: 100%;
    gap: 4px; /* Space between the dots */
}

.loading-dots span {
    display: inline-block;
    width: 6px; /* Size of the dot */
    height: 6px;
    background-color: #fff; /* Color of the dots */
    border-radius: 50%;
    /* Removed margin: 0 2px; to use gap instead */
    animation: dot-pulse 1.4s infinite ease-in-out both;
    opacity: 0.2; /* Initial state */
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}
.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}
.loading-dots span:nth-child(3) {
    animation-delay: 0s;
}
