/* ==========================================
   1. Base & Layout Styles
   Contains global resets, body container, and main chat wrapper
   ========================================== */
* {
  box-sizing: border-box;
  font-family: system-ui, -apple-system, sans-serif;
}

body {
  background-color: #f4f6f8;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  /* Adapts to full dynamic screen height on mobile browsers */
  margin: 0;
}

#chat-container {
  width: 100%;
  max-width: 500px;
  height: 100%;
  /* Spans full height on mobile */
  /* Maintains original desktop height cap */
  background: #ffffff;
  border-radius: 0;
  /* Full edge-to-edge on mobile */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Desktop override to retain original card appearance */
@media (min-height: 620px) and (min-width: 501px) {
  #chat-container {
    height: 600px;
    border-radius: 8px;
  }
}

/* ==========================================
   2. Status Bar Component
   Contains the top bar layout and status control buttons
   ========================================== */
/* Status Bar */
#status-bar {
  padding: 16px 16px;
  /* Adds top padding for iPhone notch / Dynamic Island safe area */
  padding-top: calc(16px + env(safe-area-inset-top));
  background-color: #2b303a;
  color: #ffffff;
  font-weight: bold;
  font-size: 14px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  gap: 16px;
}

.auto-message-button {
  padding: 16px;
  /* Add px units to make them circular */
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: #ffffff;

  /* Remove default browser button styling */
  border: none;
  box-sizing: border-box;

  /* Prevents the parent flexbox from crushing the circle */
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auto-message-button img,
.auto-message-button svg {
  width: 24px;
  height: 24px;
  object-fit: cover;
}

/* Style the new header Close button specifically */
#terminate-btn {
  padding: 8px;
  /* 1. Push completely to the right side of the status bar container */
  margin-left: auto;

  /* 2. Reset the white circle styling back to flat text */
  border: none;
  background-color: #2b303a;

  /* 3. Text styling to match your status bar header theme */
  color: #ffffff;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;

  /* 4. Disable flex shrinking so the word 'Close' stays wide */
  flex-shrink: 0;
}

/* Optional hover state to match desktop accessibility behavior */
#terminate-btn:hover {
  padding: 8px;
  background-color: #333740;
  /* Smooth grey dim on cursor hover */
}

/* ==========================================
   3. Message Stream & Image Overlay
   Contains the main scrolling chat area and full-area overlays
   ========================================== */
/* 1. MUST add position relative to your existing #messages selector so the image knows where to anchor */
#messages {
  flex: 1;
  padding: 16px;
  list-style: none;
  margin: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;

  /* CRITICAL ADDITION: Creates a bounding box for the absolute image */
  position: relative;
}

/* 2. Force the image container to stretch to all edges of the message area */
.message-image-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  /* Places it directly over any hidden background text/messages */

  display: flex;
  align-items: center;
  justify-content: center;
}

/* 3. Scale the image to fill the layout space without warping */
.chat-embedded-img {
  width: 80%;
  height: 80%;

  /* Forces the image to crop and cover the entire container perfectly */
  object-fit: cover;
}

/* ==========================================
   4. Message Bubbles & Variants
   Contains chat bubble styling for text messages and in-chat images
   ========================================== */
/* Message Bubbles */
.message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-line;
}

.message.system {
  align-self: center;
  background-color: #e2e8f0;
  color: #475569;
  font-size: 12px;
  border-radius: 12px;
}

.message.sent {
  align-self: flex-end;
  background-color: #00BBE6;
  color: #ffffff;
  border-bottom-right-radius: 2px;
}

.message.received {
  align-self: flex-start;
  background-color: #f1f5f9;
  color: #0f172a;
  border-bottom-left-radius: 2px;
}

.message.random-question-sender {
  align-self: flex-end;
  background-color: #f1f5f9;
  color: #00BBE6;
  font-size: 12px;
  border-radius: 12px;
}

.message.random-question-receiver {
  align-self: flex-start;
  background-color: #f1f5f9;
  color: #00BBE6;
  border-bottom-left-radius: 2px;
}

/* Image container bubble styling */
.message.message-image-wrapper {
  padding: 4px;
  background: transparent;
  /* Removes text bubble background */
  display: flex;
}

/* Ensure images fit nicely inside the bubble align boundaries */
.message-image-wrapper .chat-embedded-img {
  max-width: 100%;
  max-height: 250px;
  border-radius: 12px;
  object-fit: cover;
}

/* Bare Text Button */
.skip-partner-button {
  background: none;
  border: none;
  padding: 8px 16px;
  color: #64748b;
  font-size: 13px;
  font-weight: 500;
  align-self: center;
  cursor: pointer;
  display: none;
}

.skip-partner-button.visible {
  display: block;
}

/* ==========================================
   5. Input Controls & Global Button Styles
   Contains the main text input area and generic button elements
   ========================================== */
/* Controls Input Area */
#input-area {
  display: flex;
  padding: 12px;
  /* Adds bottom padding for iPhone Home Indicator bar */
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  gap: 8px;
  border-top: 1px solid #e2e8f0;
  background-color: #ffffff;
}

#messageInput {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  outline: none;
  font-size: 16px;
}

#messageInput:focus {
  border-color: #64748b;
}

button {
  padding: 10px 18px;
  color: #ffffff;
  border: none;
  border-radius: 20px;
  font-weight: bold;
  cursor: pointer;
}

/* ==========================================
   6. Popup Overlays & Modal Windows
   Contains screen dimming overlays, pop-up content boxes, and modal inputs
   ========================================== */
/* The semi-transparent dark background covering the whole screen */
.social-popup-overlay {
  display: none;
  /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  /* Dimmed background effect */
  z-index: 9999;
  /* Forces it above the status bar and all other elements */
  align-items: center;
  justify-content: center;
}

/* The semi-transparent dark background covering the whole screen */
.auto-message-popup-overlay {
  display: none;
  /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  /* Dimmed background effect */
  z-index: 9999;
  /* Forces it above the status bar and all other elements */
  align-items: center;
  justify-content: center;
}

/* The semi-transparent dark background covering the whole screen */
.random-question-popup-overlay {
  display: none;
  /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  /* Dimmed background effect */
  z-index: 9999;
  /* Forces it above the status bar and all other elements */
  align-items: center;
  justify-content: center;
}

/* A helper class that JavaScript will toggle to show the pop-up */
.social-popup-overlay.active {
  display: flex;
}

/* A helper class that JavaScript will toggle to show the pop-up */
.auto-message-popup-overlay.active {
  display: flex;
}

/* A helper class that JavaScript will toggle to show the pop-up */
.random-question-popup-overlay.active {
  display: flex;
}

/* The actual mini pop-up window box */
.popup-content {
  background-color: #ffffff;
  padding: 24px;
  border-radius: 8px;
  width: 280px;
  text-align: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  color: #2b303a;
  /* Dark text to contrast the white box */
}

/* Simple styling for the close button inside the pop-up */
#close-auto-message-btn {
  margin-top: 16px;
  padding: 8px 16px;
  background-color: #2b303a;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Simple styling for the close button inside the pop-up */
#close-social-btn {
  margin-top: 16px;
  padding: 8px 16px;
  background-color: #2b303a;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Simple styling for the close button inside the pop-up */
#close-random-question-btn {
  margin-top: 16px;
  padding: 8px 16px;
  background-color: #2b303a;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Simple styling for the close button inside the pop-up */
#random-question-btn {
  margin-top: 16px;
  padding: 8px 16px;
  background-color: #2b303a;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#roll-random-question-btn {
  margin-top: 16px;
  padding: 8px 16px;
  background-color: #00BBE6;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#roll-random-question-btn:disabled {
  margin-top: 16px;
  padding: 8px 16px;
  background-color: #ccc;
  color: #2b303a;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#socialInput {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  outline: none;
  font-size: 16px;
}

#socialInput:focus {
  border-color: #64748b;
}

#autoMessageInput {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  outline: none;
  font-size: 16px;
}

#autoMessageInput:focus {
  border-color: #64748b;
}

/* ==========================================
   7. Circular Selection Grid Components
   Contains the 3x2 category grid, icon buttons, and selection states
   ========================================== */
/* Container for the 3x2 Grid */
.circular-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}

.grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Circular Button Styling */
.circle-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid #ccc;
  background-color: #f9f9f9;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
}

.circle-btn img {
  width: 60%;
  height: 60%;
  object-fit: contain;
}

.circle-btn.selected-highlight {
  border-color: #00BBE6;
  /* Matches your send button color */
  box-shadow: 0 0 10px rgba(0, 187, 230, 0.6);
  background-color: #e6f8fc;
  transform: scale(1.05);
  /* Slight pop effect */
  transition: all 0.2s ease-in-out;
}

/* Text Underneath Buttons */
.btn-text {
  margin-top: 5px;
  font-size: 12px;
  color: #333;
}

/* Vertical Stacking for Action Buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 0px;
  width: 100%;
}

.action-buttons button {
  width: 100%;
  padding: 0px;
  cursor: pointer;
}

.header-right-group {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.online-counter {
  font-size: 13px;
  color: #a0aec0;
  font-weight: normal;
  white-space: nowrap;
}