:root {
  color-scheme: dark;
  --bg-page: #121212;
  --text: #e0e0e0;
  --surface: #1e1e1e;
  --surface-alt: #252526;
  --border: #333;
  --border-soft: #444;
  --input-bg: #333;
  --input-text: #ffffff;
  --muted: #888;
  --muted-soft: #444;
  --highlight: #0d6efd;
  --bubble-bg: #2c2c2e;
  --bubble-text: #ffffff;
  --button-bg: #333;
  --button-text: #ffffff;
  --danger: #dc3545;
  --success: #28a745;
  --modal-bg: #1e1e1e;
  --modal-border: #333;
  --scrollbar-thumb: #444;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg-page: #f5f6fa;
  --text: #1f2937;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #d1d5db;
  --border-soft: #e5e7eb;
  --input-bg: #ffffff;
  --input-text: #111827;
  --muted: #6b7280;
  --muted-soft: #9ca3af;
  --highlight: #2563eb;
  --bubble-bg: #f3f4f6;
  --bubble-text: #111827;
  --button-bg: #e5e7eb;
  --button-text: #111827;
  --danger: #dc2626;
  --success: #16a34a;
  --modal-bg: #ffffff;
  --modal-border: #d1d5db;
  --scrollbar-thumb: #cbd5e1;
}
html, body {
  /* Fallback for very old browsers */
  height: 100% !important; 
  
  /* Forces the layout to match the exact visible area in iOS Chrome */
  height: 100dvh !important; 
  
  margin: 0 !important;
  padding: 0 !important;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text);
  overflow: hidden; /* Disable page-level scrolling */
}
#website-footer {
  font-size: 0.65rem;
  color: #555;
  text-align: center;
  line-height: 1.4;
}
.footer-reminder {
  color: #444;
  margin-top: 5px;
}
#chat-container {
  width: 95%; /* Better for mobile */
  max-width: 800px;
  height: 95%; /* Slightly larger height now that title is gone */
  display: flex;
  flex-direction: column;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
}
#chat-container.drag-over {
  border-color: #0d6efd;
  box-shadow: 0 4px 30px rgba(13, 110, 253, 0.4);
}
@media (min-width: 768px) {
  #chat-container {
    width: 80%;
  }
}
#messages {
  flex-grow: 1;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden; /* Prevent horizontal scrolling */
  /* Subtle separation from input */
  border-bottom: 1px solid var(--border);
  background-color: var(--surface);
  display: flex;
  flex-direction: column;
}
#scroll-to-bottom-btn {
  position: absolute;
  right: 8px;
  bottom: 115px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(13, 110, 253, 0.92);
  color: white;
  font-size: 1.25rem;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(13, 110, 253, 0.35);
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  pointer-events: none;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
#scroll-to-bottom-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
#scroll-to-bottom-btn:hover {
  box-shadow: 0 10px 24px rgba(13, 110, 253, 0.45);
  background: rgba(11, 94, 215, 1);
}
.message {
  margin: 0 0 20px 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.message:first-child {
  margin-top: 0;
}
.message-row {
  display: flex;
  align-items: flex-end; /* Align delete button to the bottom of the content group */
  gap: 10px;
  width: 100%;
  max-width: 100%;
  position: relative;
  box-sizing: border-box;
}
.message-content-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  max-width: calc(100% - 40px);
}
.delete-btn {
  background: rgba(220, 53, 69, 0.1);
  color: #dc3545;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  flex-shrink: 0; /* Prevent the button from squishing */
  font-size: 14px;
  margin-bottom: 5px; /* Alignment adjustment */
}
.message-row:hover .delete-btn {
  opacity: 1;
}
.delete-btn:hover {
  background: #dc3545;
  color: white;
  transform: scale(1.1);
}
.message .text {
  background-color: var(--bubble-bg);
  color: var(--bubble-text);
  padding: 12px 16px;
  border-radius: 18px;
  border-bottom-left-radius: 4px; /* Stylish chat bubble "tail" */
  display: inline-block;
  max-width: 100%; /* Take full width of parent group */
  line-height: 1.5;
  word-wrap: break-word;
  margin-block-end: auto;
  white-space: pre-wrap; /* Support multiple lines and preserve spaces */
  cursor: pointer;
  user-select: text; /* Allow manual selection but don't force 'all' */
  box-sizing: border-box;
}
.message .text:active {
  background-color: var(--border-soft);
}
.message img {
  max-width: 100%; /* Take full width of parent group */
  max-height: 400px; /* Increased from 300px for better visibility */
  border-radius: 12px;
  margin-top: 5px;
  cursor: pointer;
  display: block;
  object-fit: contain;
  box-sizing: border-box;
}
.uploading-indicator {
  font-size: 0.8rem;
  color: #0d6efd;
  margin-top: 5px;
  font-style: italic;
}
#input-area {
  display: flex;
  padding: 15px; /* Reduced from 20px */
  background-color: var(--surface-alt);
  border-top: 1px solid var(--border);
  gap: 8px; /* Reduced from 10px */
  position: relative; /* For copy notification positioning */
  overflow: visible !important; /* Ensure notification isn't clipped */
}
@media (min-width: 768px) {
  #input-area {
    padding: 20px;
    gap: 10px;
  }
}
#input-wrapper {
  position: relative;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--input-bg);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
}
#image-preview-container {
  display: none;
  padding: 10px;
  background-color: var(--surface-alt);
  border-bottom: 1px solid var(--border-soft);
  position: relative;
  max-height: 120px;
  overflow: hidden;
  text-align: center;
}
#image-preview-container img {
  height: 80px;
  border-radius: 8px;
  display: inline-block;
  border: 2px solid #0d6efd;
}
#file-preview-container {
  display: none;
  padding: 10px;
  background-color: var(--surface-alt);
  border-bottom: 1px solid var(--border-soft);
  position: relative;
  align-items: center;
  gap: 10px;
  color: var(--highlight);
  font-size: 0.85rem;
}
#file-icon {
  font-size: 1.5rem;
}
#remove-preview, #remove-file-preview {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(220, 53, 69, 0.8);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.2s;
  z-index: 5;
}
#remove-preview:hover, #remove-file-preview:hover {
  background: #dc3545;
}
.file-attachment {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #2c2c2e;
  padding: 12px 16px;
  border-radius: 12px;
  color: #fff;
  text-decoration: none;
  margin-top: 5px;
  border: 1px solid #444;
  transition: background 0.2s;
  max-width: 300px;
}
.file-attachment:hover {
  background: #3a3a3c;
  border-color: #0d6efd;
}
.file-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.file-name {
  font-weight: bold;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-size {
  font-size: 0.75rem;
  color: #888;
}
#attach-button {
  background-color: var(--button-bg);
  color: var(--muted);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 0 12px;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s;
}
#attach-button:hover {
  background-color: var(--border-soft);
  color: var(--button-text);
  border-color: var(--highlight);
}
#message-input {
  flex-grow: 1;
  background-color: transparent;
  color: var(--input-text);
  border: none;
  padding: 12px 15px;
  font-size: 14px;
  outline: none;
  resize: none;
  height: 40px;
  line-height: 1.4;
  resize: vertical;
  min-height: 40px;
}
#message-input::placeholder {
  color: transparent;
}
.message-input-placeholder {
  position: absolute;
  left: 15px;
  top: 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: pre-wrap;
}
.message-input-placeholder.hidden {
  opacity: 0;
  transform: translateY(4px);
  visibility: hidden;
}
#input-wrapper:focus-within {
  border-color: #0d6efd;
}
#ctrl-enter-hint {
  position: absolute;
  bottom: 5px;
  right: 12px;
  font-size: 0.65rem;
  color: var(--muted);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
#copy-notification {
  position: fixed; /* Changed to fixed */
  bottom: 100px; /* Position above the input area */
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--success);
  color: white;
  padding: 8px 20px;
  border-radius: 25px;
  font-size: 0.85rem;
  font-weight: bold;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
  z-index: 10000;
  box-shadow: 0 4px 15px rgba(0,0,0,0.25);
}
#copy-notification.show {
  opacity: 1;
  transform: translate(-50%, -20px);
}
/* Image Modal Styles */
#image-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  z-index: 20000;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  overflow: hidden;
}
#image-modal img {
  max-width: 95%;
  max-height: 95%;
  border-radius: 8px;
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
  transform-origin: center center;
  transition: transform 0.05s ease-out;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}
/* Generic Modal Styles */
#custom-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 30000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
}
.modal-content {
  background-color: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  animation: modalAppear 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes modalAppear {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-title {
  font-size: 1.2rem;
  font-weight: bold;
  color: #0d6efd;
  margin-bottom: 12px;
}
.modal-message {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 20px;
}
.modal-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--input-text);
  margin-bottom: 20px;
  outline: none;
  box-sizing: border-box;
}
.modal-input:focus {
  border-color: var(--highlight);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-btn {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}
.modal-btn-cancel {
  background: #2f3135;
  color: #eef2ff;
}
.modal-btn-cancel:hover {
  background: #424549;
  color: #ffffff;
}
.modal-btn-confirm {
  background: var(--highlight);
  color: white;
}
.modal-btn-confirm:hover {
  background: #0b5ed7;
}
.modal-btn-danger {
  background: #dc3545;
  color: white;
}
.modal-btn-danger:hover {
  background: #bb2d3b;
}
#message-input:not(:placeholder-shown) + #ctrl-enter-hint {
  opacity: 1;
}
#send-button {
  background-color: var(--highlight);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0 15px; /* Reduced from 20px */
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: background-color 0.2s;
  flex-shrink: 0; /* Prevent button from squashing */
  white-space: nowrap; /* Keep text on one line */
}
@media (min-width: 768px) {
  #send-button {
    padding: 0 20px;
  }
}
#send-button:hover {
  background-color: #0b5ed7;
}
#change-room-btn:hover {
  background-color: #444 !important;
  color: #fff !important;
  border-color: #0d6efd !important;
}
#clear-room-btn:hover {
  background-color: #dc3545 !important;
  color: #fff !important;
  border-color: #dc3545 !important;
}
.message .timestamp {
  font-size: 0.75rem;
  color: #888;
  margin-top: 5px;
  margin-left: 5px;
}
/* Custom Scrollbar for a polished look */
#messages::-webkit-scrollbar {
  width: 6px;
}
#messages::-webkit-scrollbar-thumb {
  background-color: #444;
  border-radius: 10px;
}
/* Hide scrollbar for header while keeping it scrollable */
#chat-header::-webkit-scrollbar {
  display: none;
}
#chat-header {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
  position: relative;
}

#settings-btn {
  background: #333;
  color: #fff;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
#settings-btn:hover {
  background: #444;
  color: #fff;
  border-color: #0d6efd;
}
#settings-panel {
  position: absolute;
  top: 52px;
  right: 10px;
  background: #1c1c1c;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 14px;
  min-width: 220px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: none;
}
#settings-panel label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: #ddd;
  font-size: 0.85rem;
}
#settings-panel input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #0d6efd;
  cursor: pointer;
}
#settings-panel .settings-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: #0d6efd;
}
#settings-panel .settings-description {
  color: #aaa;
  font-size: 0.78rem;
  line-height: 1.4;
  margin-top: 6px;
}

/* Responsive header for mobile screens */
@media (max-width: 600px) {
  #chat-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  #chat-header > div:first-child {
    justify-content: flex-start;
  }
  #chat-header > div:last-child {
    justify-content: flex-start;
    width: 100%;
  }
  #search-input {
    max-width: 100% !important;
  }
}
/* Spinner */
.spinner {
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-left-color: #0d6efd;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 20px auto;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
/* Clipboard preview bar */
#clipboard-preview-container {
  display: none;
  padding: 10px;
  background-color: #2c2c2e;
  border-bottom: 1px solid #444;
  position: relative;
  align-items: center;
  gap: 10px;
  color: #ddd;
  font-size: 0.85rem;
}
#clipboard-preview-container #clipboard-preview-text {
  max-width: 420px;
}