/* Base styles and CSS custom properties */
:root {
  --primary-color: #ff69b4;
  --primary-dark: #ff1493;
  --text-color: #333;
  --bg-color: #f0f0f0;
  --container-bg: #fff;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --border-radius: 15px;
  --transition-speed: 0.3s;
  --spacing-unit: 20px;

  /* Animation control variable */
  --animation-enabled: running; /* Default to running */
}

/* Dark mode variables */
[data-theme="dark"] {
  --primary-color: #ffb6c1;
  --primary-dark: #ff69b4;
  --text-color: #e0e0e0;
  --bg-color: #121212;
  --container-bg: #333;
  --shadow-color: rgba(255, 255, 255, 0.1);
}

/* Global styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Ensure html and body take full viewport height */
html, body {
  height: 100vh; /* Changed from 100% to 100vh for explicit viewport height */
}

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Oxygen, Ubuntu, sans-serif;
  color: var(--text-color);
  background-color: var(--bg-color);
  line-height: 1.6;
  transition: background-color var(--transition-speed) ease,
              color var(--transition-speed) ease;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing-unit);
  height: 100%; /* Remains 100% of its parent (body) */
  display: flex;
  flex-direction: column;
}

/* Header styles */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-unit) 0;
}

.app-header h1 {
  color: var(--primary-color);
  font-size: 2em;
  margin: 0;
}

.app-header .controls {
  display: flex; /* Arrange controls horizontally */
  gap: 10px; /* Space between controls */
  align-items: center;
}

/* New control button styles */
.control-button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  padding: 8px 12px; /* Adjust padding for better look with icon */
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-button svg {
  fill: currentColor;
  width: 24px;
  height: 24px;
}

.control-button:hover {
  background-color: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--shadow-color);
}

.control-button:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Main content area */
.app-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-unit);
  flex: 1;
  /* Add min-height to ensure it respects the flex container's height */
  min-height: 0; /* Allow the grid container to shrink */
}

@media (max-width: 768px) {
  .app-main {
    grid-template-columns: 1fr;
  }
}

/* Girlfriend container styles */
.girlfriend-container {
  position: relative;
  border-radius: var(--border-radius);
  overflow: hidden;
  background: var(--container-bg);
  box-shadow: 0 8px 20px var(--shadow-color);
  /* Ensure grid items can shrink and respect parent's height */
  min-height: 0; 
}

#girlfriend-model {
  width: 100%;
  height: auto;
  object-fit: cover;
  transition: transform 0.05s ease-in-out;
  /* Control animation-play-state based on custom property */
  animation-play-state: var(--animation-enabled);
}

/* Chat section styles */
.chat-section {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-unit);
  flex: 1;
  /* Ensure grid items can shrink and respect parent's height */
  min-height: 0; 
}

.chat-container {
  flex: 1;
  padding: var(--spacing-unit);
  background: var(--container-bg);
  border-radius: var(--border-radius);
  overflow-y: auto;
  box-shadow: 0 8px 20px var(--shadow-color);
  border: 1px solid var(--primary-color);
}

/* Scrollbar styles for Webkit browsers */
.chat-container::-webkit-scrollbar {
  width: 8px;
}

.chat-container::-webkit-scrollbar-track {
  background: var(--bg-color);
  border-radius: 10px;
}

.chat-container::-webkit-scrollbar-thumb {
  background-color: var(--primary-color);
  border-radius: 10px;
  border: 2px solid var(--bg-color);
}

.chat-container::-webkit-scrollbar-thumb:hover {
  background-color: var(--primary-dark);
}

/* Message styles */
.message {
  margin-bottom: 15px;
  padding: 10px 15px;
  border-radius: 15px;
  max-width: 80%;
  position: relative;
  /* Ensure animation state respects the global setting */
  animation-play-state: var(--animation-enabled);
}

.user-message {
  background-color: var(--primary-color);
  color: white;
  margin-left: auto;
}

.girlfriend-message {
  background-color: var(--container-bg);
  border: 1px solid var(--primary-color);
}

/* New message indicator */
.new-message-indicator {
  position: sticky;
  bottom: 10px;
  background-color: var(--primary-color);
  color: white;
  padding: 5px 10px;
  border-radius: 15px;
  margin: 10px auto;
  text-align: center;
  cursor: pointer;
  width: fit-content;
  box-shadow: 0 2px 5px var(--shadow-color);
  animation: pulse 1.5s infinite;
  animation-play-state: var(--animation-enabled); /* Control animation state */
}

@keyframes pulse {
  0% { opacity: 0.7; }
  50% { opacity: 1; }
  100% { opacity: 0.7; }
}

/* Typing indicator */
.typing-indicator {
  background-color: var(--container-bg);
  border: 1px solid var(--primary-color);
  border-radius: 15px;
  padding: 10px 15px;
  margin-bottom: 15px;
  width: fit-content;
  display: flex;
  align-items: center;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background-color: var(--primary-color);
  border-radius: 50%;
  display: inline-block;
  margin: 0 2px;
  animation: typing 1s infinite ease-in-out;
  animation-play-state: var(--animation-enabled); /* Control animation state */
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* Input container styles */
.input-container {
  display: flex;
  gap: 10px;
  background: var(--container-bg);
  padding: 15px;
  border-radius: var(--border-radius);
  box-shadow: 0 8px 20px var(--shadow-color);
  border-top: 1px solid var(--primary-color);
}

.user-input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--primary-color);
  border-radius: var(--border-radius);
  background: transparent;
  color: var(--text-color);
  resize: none;
  font-family: inherit;
}

/* Enhanced button styles */
.send-button {
  padding: 12px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-button:hover {
  background-color: var(--primary-dark);
  transform: scale(1.05);
}

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

.send-button svg {
  fill: currentColor;
  transition: transform var(--transition-speed) ease;
}

.send-button:hover svg {
  transform: translateX(2px);
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: #cccccc; /* Make disabled state visually distinct */
}

/* Error container styles */
.error-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
}

.error-message {
  background-color: #ff4444;
  color: white;
  padding: 15px 20px;
  border-radius: var(--border-radius);
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease-out;
  animation-play-state: var(--animation-enabled); /* Control animation state */
}

/* Critical error styling */
.fatal-error {
  padding: 2rem;
  text-align: center;
  background: #ffebee;
  color: #b71c1c;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.fatal-error button {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: #b71c1c;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Animations */
@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

/* Loading overlay */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  animation-play-state: var(--animation-enabled); /* Control animation state */
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Dark mode toggle */
.dark-mode-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.dark-mode-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 34px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .switch-slider {
  background-color: var(--primary-color);
}

input:focus + .switch-slider {
  box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .switch-slider:before {
  transform: translateX(26px);
}

/* Message metadata */
.message-metadata {
  font-size: 0.75em;
  margin-top: 5px;
  display: flex;
  justify-content: space-between;
}

.timestamp {
  opacity: 0.7;
}

.emotion-indicator {
  font-style: italic;
}

/* Utility classes */
.hidden {
  display: none !important;
}

/* Private Chat Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(5px);
}

.modal-content {
  background: var(--container-bg);
  padding: var(--spacing-unit);
  border-radius: var(--border-radius);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  max-width: 600px;
  width: 90%;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-height: 90vh; /* Limit modal height */
  overflow-y: auto; /* Allow scrolling if content overflows */
}

.modal-content h2 {
  color: var(--primary-color);
  margin-bottom: 5px;
}

.modal-content p {
  color: var(--text-color);
  margin-bottom: 10px;
}

.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.8em;
  color: var(--text-color);
  cursor: pointer;
  transition: color 0.2s ease;
}

.modal-close-btn:hover {
  color: var(--primary-dark);
}

.modal-input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--primary-color);
  border-radius: 8px;
  background: transparent;
  color: var(--text-color);
  font-family: inherit;
  font-size: 1em;
  resize: vertical;
  min-height: 80px;
  max-height: 200px;
}

.modal-button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 1em;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.modal-button:hover {
  background-color: var(--primary-dark);
  transform: translateY(-2px);
}

.modal-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: #ccc;
}

.private-chat-output-container {
  position: relative;
  background: var(--bg-color);
  border: 1px solid var(--primary-color);
  border-radius: 8px;
  padding: 15px;
  min-height: 100px;
  max-height: 300px; /* Limit output display height */
  overflow-y: auto;
  color: var(--text-color);
  white-space: pre-wrap; /* Preserve whitespace and wrap text */
  word-wrap: break-word; /* Break long words */
}

.private-chat-spinner-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5); /* Slightly transparent */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 10;
}

/* Spinner for modal */
.private-chat-spinner-overlay .spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--primary-color);
}

/* Image Gallery Styles */
.image-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  padding: 10px;
  max-height: 60vh; /* Ensure grid does not overflow modal */
  overflow-y: auto;
  background: var(--bg-color);
  border-radius: var(--border-radius);
  border: 1px solid var(--primary-color);
}

.image-gallery-item {
  width: 100%;
  height: 120px; /* Fixed height for grid items */
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: 1px solid transparent; /* default border */
}

.image-gallery-item:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 10px var(--shadow-color);
  border: 1px solid var(--primary-color); /* Highlight on hover */
}

/* Enlarged Image Modal Specific Styles */
.enlarged-image-content {
  max-width: 90vw; /* Use vw for responsiveness */
  max-height: 90vh; /* Use vh for responsiveness */
  width: auto;
  height: auto;
  padding: 15px; /* Adjust padding for images */
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent; /* Transparent background for full image focus */
  box-shadow: none; /* No shadow for the content itself */
}

#enlarged-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain; /* Ensure the whole image is visible */
  border-radius: var(--border-radius);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5); /* Add shadow to the image */
  background: var(--container-bg); /* Background for the image itself */
}

.enlarged-image-content .modal-close-btn {
  color: white; /* Make close button visible on dark overlay */
  text-shadow: 0 0 5px rgba(0,0,0,0.8);
}

.enlarged-image-content .modal-close-btn:hover {
  color: var(--primary-color);
}