/* Variables */
:root {

  /* Button (light theme) */
  --button-bg: rgba(128, 128, 128, 0.15);
  --button-bg-hover: rgba(255, 242, 0, 0.2);
  --button-border: rgba(60, 60, 70, 0.1);
  --button-border-hover: rgba(255, 255, 255, 0.8);
  --button-text: #222;
  --button-text-hover: rgba(0, 0, 0, 0.8);
  --button-danger-bg: rgba(191, 32, 44, 0.2);
  --button-neutral-bg: #f0f0f0;

  /* Text */
  --text-muted: #666;
  --sidebar-title: #333;
}

/* Dark theme overrides */
.dark {

  /* Buttons */
  --button-bg: rgba(60, 60, 70, 0.6);
  --button-bg-hover: rgba(80, 80, 90, 0.8);
  --button-border: rgba(60, 60, 70, 0.1);
  --button-border-hover: rgba(60, 60, 70, 0.3);
  --button-text: #e0e0e0;
  --button-danger-bg: rgba(220, 53, 69, 0.25);
  --button-neutral-bg: rgba(90, 90, 100, 0.5);

  /* Text */
  --text-muted: #a0a0a0;
  --sidebar-title: #f0f0f0;
}

/* Hide default Chainlit elements */

/* Built with Chainlit text in the footer */
.watermark,

/* Readme button in the header */
#readme-button,

/* Placeholder text in the input box */
#chat-input::before,

/* Thread share link */
#share-thread,

/* User nav button when in iframe */
body.in-iframe #user-nav-button,

/* Copy to clipboard buttons */
.ai-message button:first-of-type:not(.message-link, .card-btn),
.ai-message button:nth-of-type(2):not(.message-link, .card-btn),
.ai-message button:nth-of-type(3):not(.message-link, .card-btn) {

  display: none !important;
}

/*******************************
 * Chat Messages
 *******************************/

/* Message spacing */
.ai-message .message-content {
  margin-bottom: 0.5rem !important;
}

/* Assistant message avatar */
.ai-message>.inline-block>span {
  width: 2.5rem !important;
  height: 1.5rem !important;
}

/* Message links styling */
.message-link {
  /* border-radius: 10px; */
  /* color: #bf202c !important; */
  /* text-decoration: none !important; */
  /* line-height: 1.3 !important; */
  padding: 0.1rem 1rem !important;
  /* background-color: rgba(255, 242, 0, 0.3) !important; */
  /* border: 2px solid #bf202c !important; */
  /* font-family: "Montserrat Alternates", sans-serif !important; */
  /* font-weight: normal !important; */
  /* margin-left: 0 !important; */
  /* margin-right: 0 !important; */
}

/*******************************
 * Global Button Styles
 *******************************/

/* === Base Button Styles === */
button {
  color: var(--button-text) !important;
  position: relative;
  background-color: rgba(255, 255, 255, 0.15) !important;
  backdrop-filter: blur(2px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.8) !important;
  border-radius: 2rem !important;
  box-shadow: 0 1px 8px rgba(31, 38, 135, 0.2),
    inset 0 2px 0 rgba(255, 255, 255, 0.3) !important;
  margin: 0 0.4rem !important;
}

button::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2rem;
  backdrop-filter: blur(1px);
  box-shadow: inset -10px -8px 0px -11px rgba(255, 255, 255, 1),
    inset 0px -5px 0px -4px rgba(255, 255, 255, 1);
  opacity: 0.5;
  z-index: -1;
  filter: blur(1px) drop-shadow(2px 4px 15px black) brightness(115%);
}

button:hover,
button[data-active="true"] {
  background-color: var(--button-bg-hover) !important;
  border-color: var(--button-border-hover) !important;
  color: var(--button-text-hover) !important;
}

/* === Special buttons ===*/

/* Sidebar rail button */
button[data-sidebar="rail"] {
  background: none !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
  height: auto !important;
  min-width: auto !important;
  right: initial !important;
  transform: initial !important;

  &::after {
    display: none !important;
  }
}

/* Sidebar thread button */
button[data-sidebar="menu-button"] {
  box-shadow: none !important;
  font-size: 0.8rem !important;
  font-weight: 500 !important;
  border-radius: 0 !important;
  border: none !important;
}

button[data-sidebar="menu-button"]::after {
  display: none !important;
}

/* Settings popin dropdown */
button[role="combobox"] {
  /* background: none !important; */
  /* border-width: 1px !important; */
  margin: 0 !important;
}

/* Profiles dropdown menu */
#chat-profiles {
  margin-left: 0.5rem !important;
}

/* New chat button */
#new-chat-button {
  margin-right: 1.5rem !important;
}

/* === Button Variants === */

/* Danger buttons */
button.danger {
  background-color: var(--button-danger-bg) !important;
}

/* === Sidebar Button Styles === */

/* Sidebar action buttons - positioning */
aside #reset-button,
aside #show-facts-button,
aside #exit-button,
aside #ai-respond-button {
  zoom: 0.75 !important;
  position: absolute;
  bottom: 1rem;
}

aside #reset-button {
  right: 5.5rem;
}

aside #exit-button {
  right: 1.4rem;
}

aside #show-facts-button {
  right: 12.4rem;
}

aside #ai-respond-button {
  right: 21.5rem;
}

/* === Special Button Behaviors === */

/* Hide default clipboard buttons */
.ai-message button:first-of-type:not(.message-link, .card-btn),
.ai-message button:nth-of-type(2):not(.message-link, .card-btn),
.ai-message button:nth-of-type(3):not(.message-link, .card-btn) {
  display: none !important;
}

/* =====================================
 * Global interaction lock during AI play
 * Disables all button elements while the AI is "playing",
 * except the control button itself (#ai-respond-button).
 * ===================================== */
.ai-playing button {
  pointer-events: none !important;
}

.ai-playing button#ai-respond-button {
  pointer-events: auto !important;
}

/* Explicitly disable sidebar menu buttons during AI play */
.ai-playing button[data-sidebar="menu-button"] {
  pointer-events: none !important;
}


/*******************************
 * Language Switcher
 *
 * Displays language selection buttons (EN, ES) at the top right of the sidebar.
 *
 * Implementation Notes:
 * - Uses fixed positioning to overlay at top right of sidebar
 * - Scaled down to 75% size via zoom property
 * - Inherits button styles from global button definitions
 * - Component source: /app/public/elements/LanguageSwitcher.jsx
 * - Backend action: /app/actions/language.py (change_language)
 *
 * Related Files:
 * - Translation files: /app/.chainlit/translations/*.json
 * - UI config: /app/ui.toml (element: language_switcher)
 *******************************/

/* Base Container Styles */
#language-switcher {
  display: flex !important;
  gap: 0.2rem !important;
  /* Space between buttons */
}

/* Button Styles */
#language-switcher button {
  font-family: Arial, sans-serif !important;
  font-weight: 400 !important;
  font-size: 0.875rem !important;
  padding: 0.5rem 0.75rem !important;
}

/* Header Positioning - next to chat profiles */
#header #language-switcher {
  display: flex !important;
  align-items: center !important;
  margin-left: 0.5rem !important;
}

/* Hide in sidebar (legacy positioning) */
aside #language-switcher {
  display: none !important;
}

/* User profile button styling - override the red background */
#header button[aria-haspopup="menu"] span.bg-primary,
#header button span span.bg-primary {
  background: rgba(128, 128, 128, 0.15) !important;
  color: transparent !important;
  position: relative !important;
}

/* Hide the letter in user button */
#header button[aria-haspopup="menu"] span span.bg-primary {
  font-size: 0 !important;
}

/* Add user icon to profile button */
#header button[aria-haspopup="menu"] span span.bg-primary::before {
  content: "👤" !important;
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  font-size: 16px !important;
  color: rgba(0, 0, 0, 0.75) !important;
}

/* Dark theme user icon */
.dark #header button[aria-haspopup="menu"] span span.bg-primary::before {
  color: rgba(255, 255, 255, 0.85) !important;
}

/*******************************
 * Admin Launcher - Header Integration
 *******************************/

/* Hide launcher until it's moved into the header */
#admin-launcher {
  display: none !important;
}

/* Display in the header, adjacent to the language switcher */
#header #admin-launcher {
  display: flex !important;
  align-items: center !important;
  margin-left: 0.2rem !important;
}

/* Icon button styling */
#header #admin-launcher .admin-launcher__button {
  min-height: 2.25rem !important;
  min-width: 2.25rem !important;
  padding: 0 !important;
  margin: 0 0.4rem !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Icon sizing */
#header #admin-launcher .admin-launcher__button svg {
  width: 1.1rem !important;
  height: 1.1rem !important;
}

/*******************************
 * Right Sidebar 
 *******************************/

/* Sidebar container */
aside>div {
  background: linear-gradient(to right, rgba(255, 255, 255, 0.1), rgba(255, 242, 0, 0.2)) !important;
  border: 0 !important;
  position: relative !important;
  padding-top: 3rem !important;
  /* Extra top padding for language switcher overlay */
}

/* Dark theme sidebar container */
.dark aside>div {
  background: linear-gradient(135deg, rgba(30, 30, 40, 0.95), rgba(50, 50, 60, 0.9)) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

/* Sidebar background image */
aside>div::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-image: url("sidebar_bg.png") !important;
  background-position: bottom right !important;
  background-repeat: no-repeat !important;
  background-size: 70% !important;
  opacity: 0.2;
  z-index: 0;
}

/* Dark theme background image adjustment */
.dark aside>div::before {
  opacity: 0.08 !important;
  filter: invert(1) !important;
}

/* Ensure sidebar content appears above background */
aside>div>* {
  position: relative;
  z-index: 1;
}

/* Sidebar icon color */
aside .icon {
  /* color: #bf202c; */
}

/* Sidebar title styling */
#side-view-title {
  background-image: url("sidebar_title_bg.png") !important;
  background-repeat: no-repeat !important;
  background-size: 10% !important;
  background-position: 1rem center !important;
  color: var(--sidebar-title) !important;
  font-family: "Montserrat Alternates", sans-serif !important;
  font-size: 1.1rem !important;
  font-weight: bold !important;
  line-height: 1.2 !important;
  margin-left: 2rem !important;
  margin-bottom: 1rem !important;
  padding-left: 6rem !important;
}

/* Dark theme title filter */
.dark #side-view-title {
  filter: brightness(1.2) !important;
}

/* Hide sidebar close button */
#side-view-title>button {
  display: none !important;
}

/* Sidebar content area */
#side-view-content {
  padding-bottom: 2.3rem 0 !important;
}

/*******************************
 * Action Cards
 *******************************/

.card-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin: 30px 0;
}

.action-card {
  background: white;
  border-radius: 12px;
  padding: 25px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
  transition: transform 0.3s ease;
  margin: 20px auto;
  max-width: 300px;
}

.action-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.card-icon {
  font-size: 32px;
  margin-bottom: 15px;
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  color: #2d3748;
  margin-bottom: 10px;
  font-family: "Montserrat Alternates", sans-serif !important;
}

.card-description {
  font-size: 14px;
  color: #718096;
  margin-bottom: 20px;
}

.card-btn {
  padding: 12px 24px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: block !important;
  transition: all 0.3s ease;
  background-color: rgba(255, 242, 0, 0.3) !important;
  color: #222 !important;
  border: 2px solid #bf202c !important;
  margin: 0 auto !important;
  min-width: 160px;
  font-family: "Montserrat Alternates", sans-serif !important;
}

.card-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  background-color: rgba(255, 242, 0, 0.6) !important;
  color: #222 !important;
}

#side-view-content>.inline-custom {
  flex: 0 1 auto !important;
}


/* Debrief section styling */
aside .debrief {
  background-color: #fff !important;
  position: relative;

  .dark & {
    background-color: #000 !important;
    color: #fff !important;
  }
}

aside .debrief button {
  background-color: #fff !important;
  border: 0 !important;
  position: absolute;
  top: 10px;
  right: 0;
  z-index: 1;
}

/*******************************
 * Step Display Styling
 *******************************/

/* Position step display within the title area */
.step-display {
  position: absolute !important;
  top: -30px !important;
  left: 0 !important;
  right: 0 !important;
  margin: 0 !important;
  padding-left: 5.5rem !important;
}

/* Step display text color */
.step-display .text-muted-foreground {
  color: var(--text-muted) !important;
}

/* Make the content area relative so step display can position relative to it */
#side-view-content {
  position: relative !important;
}

/*******************************
 * Switch/Toggle Button Styling
 *******************************/

/* Switch button base styling */
input[type="checkbox"],
.switch,
.toggle,
[role="switch"] {
  background-color: #cccccc !important;
  /* Grey background (unchecked) */
}

/* Switch button checked state */
input[type="checkbox"]:checked,
.switch:checked,
.toggle:checked,
[role="switch"][aria-checked="true"] {
  background-color: #28a745 !important;
  /* Green background when checked */
}

/* Switch handles - always white */
input[type="checkbox"]::before,
.switch::before,
.toggle::before,
[role="switch"]::before {
  background-color: #ffffff !important;
}

/* Switch containers */
.switch-container:has(input:checked),
.toggle-container:has(input:checked) {
  background-color: #28a745 !important;
}

.switch-container:has(input:not(:checked)),
.toggle-container:has(input:not(:checked)) {
  background-color: #cccccc !important;
}

/*******************************
 * Tablet & Small Desktop Responsiveness
 *******************************/
@media (min-width: 769px) and (max-width: 1600px) {

  /* Adjust sidebar width for smaller desktop screens */
  aside {
    /* width: 340px !important; */
  }

  /* Adjust title styling */
  #side-view-title {
    font-size: 1rem !important;
    padding-left: 4.5rem !important;
    margin-left: 1rem !important;
    background-size: 2.5rem !important;
  }

  /* Responsive button adjustments - stack vertically */
  aside #reset-button,
  aside #show-facts-button,
  aside #exit-button,
  aside #ai-respond-button {
    zoom: 0.7 !important;
    right: 1rem !important;
  }

  aside #ai-respond-button {
    bottom: 9rem !important;
  }

  aside #show-facts-button {
    bottom: 6.5rem !important;
  }

  aside #reset-button {
    bottom: 4rem !important;
  }

  aside #exit-button {
    bottom: 1.5rem !important;
  }
}

/*******************************
 * Small Tablet & Large Mobile Responsiveness
 *******************************/
@media (min-width: 600px) and (max-width: 768px) {

  /* Responsive button adjustments for small tablets */
  aside #reset-button,
  aside #show-facts-button,
  aside #exit-button,
  aside #ai-respond-button {
    zoom: 0.65 !important;
    right: 1rem !important;
  }

  aside #ai-respond-button {
    bottom: 8rem !important;
  }

  aside #show-facts-button {
    bottom: 6rem !important;
  }

  aside #reset-button {
    bottom: 4rem !important;
  }

  aside #exit-button {
    bottom: 2rem !important;
  }
}

/*******************************
 * Mobile Responsiveness
 *******************************/
@media (max-width: 768px) {

  /* Mobile header button adjustments - override base styles */
  #header button:not(#readme-button),
  #language-switcher button {
    height: 36px !important;
    min-width: 36px !important;
    padding: 0 8px !important;
    font-size: 13px !important;
  }

  /* Adjust header spacing for mobile */
  #header div:last-child {
    gap: 4px !important;
  }

  #header div:last-child>button:last-child {
    margin-right: 8px !important;
  }

  /*
     * The mobile sidebar is a div[role="dialog"], not an <aside> element.
     * These styles target the mobile sidebar specifically for a full-screen, clean look.
     */

  /* Make sidebar full screen */
  div[role="dialog"][data-state="open"] {
    width: auto !important;
    height: 100% !important;
    left: 10% !important;
    right: 0 !important;
    padding: 1rem !important;
    border-radius: 0 !important;
    border: none !important;
  }

  #side-view-content {
    gap: 0 !important;
  }

  /* Align title to the left and add space below */
  div[role="dialog"][data-state="open"] #side-view-title {
    padding-left: 3.7rem !important;
    margin-left: 0 !important;
    text-align: left !important;
    margin-bottom: 1rem !important;
  }

  /* Remove backgrounds and borders from all content blocks */
  div[role="dialog"][data-state="open"] .bg-card {
    padding: 0.5rem !important;
  }

  div[role="dialog"][data-state="open"] .debrief {
    background-color: #FFF !important;
    box-shadow: none !important;
    padding: 0.4rem !important;
  }

  /* Clean up inner padding and margins for a seamless look */
  div[role="dialog"][data-state="open"] .bg-card>div[class*="p-"] {
    padding: 0 !important;
  }

  div[role="dialog"][data-state="open"] .space-y-4 {
    margin-top: 0 !important;
  }

  div[role="dialog"][data-state="open"] .mt-8 {
    margin-top: 1.5rem !important;
  }

  /* Hide unnecessary elements on mobile */
  button[data-state="closed"] svg[width="24"][height="24"],
  #new-progress-check-button,
  div[role="dialog"][data-state="open"] #ai-respond-button,
  div[role="dialog"][data-state="open"] #show-facts-button,
  div[role="dialog"][data-state="open"] #send-test-email-button {
    display: none !important;
  }

  /* Position remaining buttons at the bottom of the screen */
  div[role="dialog"][data-state="open"] #exit-button,
  div[role="dialog"][data-state="open"] #reset-button {
    position: fixed;
    bottom: 1.5rem;
    zoom: 0.9;
  }

  div[role="dialog"][data-state="open"] #exit-button {
    right: 1.5rem;
  }

  div[role="dialog"][data-state="open"] #reset-button {
    right: 6rem;
  }
}

/*******************************
 * Splash Screen Styles
 *******************************/

/* Splash screen container */
#ci-splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: white;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.7s ease-out;
}

/* Hide splash screen when disabled globally */
body.splash-disabled #ci-splash-screen {
  display: none !important;
}

/* Dark mode splash background */
.dark #ci-splash-screen {
  background: #1a1a1a;
}

/* Fade out animation */
#ci-splash-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* Splash content container */
.splash-content {
  text-align: center;
  animation: fadeInScale 0.8s ease-out;
}

/* Splash logo */
.splash-logo {
  width: 200px;
  height: auto;
  margin: 0 auto 2rem auto;
  display: block;
  animation: pulse 2s infinite;
}

/* Splash title */
.splash-title {
  font-family: 'Montserrat Alternates', sans-serif;
  font-size: 2.5rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 2rem;
  animation: slideUp 0.6s ease-out 0.3s both;
}

/* Dark mode title color */
.dark .splash-title {
  color: #f0f0f0;
}

/* Loading dots container */
.splash-loader {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* Loading dots */
.splash-loader span {
  width: 10px;
  height: 10px;
  background: #E11D48;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

/* Dark mode loading dots */
.dark .splash-loader span {
  background: #FF6B6B;
}

/* Stagger the bounce animation */
.splash-loader span:nth-child(1) {
  animation-delay: -0.32s;
}

.splash-loader span:nth-child(2) {
  animation-delay: -0.16s;
}

.splash-loader span:nth-child(3) {
  animation-delay: 0s;
}

/* Splash screen animations */
@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.9);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }
}

@keyframes bounce {

  0%,
  80%,
  100% {
    transform: scale(0);
    opacity: 0.5;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}
