/* General styles */
html,
body {
  height: 100%;
  margin: 0;
  background-color: #f5f5f5;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Chat page layout
 *
 * Scoped to the chat page so the other pages keep the body scrolling that
 * model.html's .scrollable-menu dropdown relies on.
 *
 * iOS Safari resolves vh against the large viewport, the height the page would
 * have with its toolbars retracted, then draws those toolbars over the result.
 * A vh-based height therefore lays the message input out below what you can
 * see, and html/body at height 100% leaves the root with no scroll range to
 * reach it or to retract the toolbars that would reveal it. dvh tracks the
 * viewport that is actually visible, and measuring the navbar with flex drops
 * the hardcoded height that had been wrong since the navbar was slimmed.
 */
body.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh; /* Fallback for engines without dvh */
  height: 100dvh;
  overflow: hidden;
}

/* Navbar slimmer for mobile */
.navbar-slim {
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
  min-height: 42px;
}

.navbar-slim .navbar-brand {
  font-size: 1rem;
  padding: 0;
  margin-right: 0.5rem;
}

.navbar-slim .nav-link {
  padding: 0.25rem 0.5rem;
  font-size: 0.9rem;
}

/* Chat app layout
 * Takes whatever the navbar leaves rather than guessing the navbar's height */
.chat-app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0; /* Shrink instead of overflowing when the input grows */
}

/* Chat header */
.chat-header {
  background-color: #f8f9fa;
  border-bottom: 1px solid #ddd;
  min-height: 40px;
}

.chat-title {
  font-size: 0.9rem;
  font-weight: 500;
}

.credits-text {
  font-size: 0.6rem;
}

/* Chat container */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background-color: white;
}

/* Message styles */
.message {
  margin-bottom: 15px;
  padding: 10px;
  border-radius: 5px;
  background-color: #f1f1f1;
}

.message-header {
  margin-bottom: 5px;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  align-items: center;
}

.username {
  font-weight: bold;
  color: #007bff;
}

.timestamp {
  font-size: 0.8em;
  color: #6c757d;
  font-style: italic;
  padding-left: 10px;
  white-space: nowrap;
}

.message-content {
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.5;
}

/* Form styles */
.message-input-container {
  padding: 10px;
  /* Clear the home indicator on a notched iPhone; resolves to 0 elsewhere */
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background-color: #f8f9fa;
  border-top: 1px solid #ddd;
}

#message-form {
  margin: 0;
}

/* The single definition of how tall the input may grow. chat.js sizes the
 * textarea to its content and lets this clamp it, so there is one ceiling
 * rather than two that disagree about which viewport they mean. */
#message-input {
  resize: none;
  max-height: 50vh; /* Fallback for engines without dvh */
  max-height: 50dvh;
  overflow-y: auto;
  line-height: 1.5;
  transition: height 0.1s ease-out;
}

.d-flex {
  gap: 10px;
}

.send-btn {
  padding: 0.375rem 0.75rem;
  align-self: flex-end;
  min-width: 42px;
}

/* Login page */
.card {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.card-header {
  background-color: #f8f9fa;
}

/* Model settings page - Custom dropdown styling */
.model-dropdown .dropdown-toggle {
  text-align: left;
  background-color: #fff;
  border: 1px solid #ced4da;
}

/* Override Bootstrap dropdown positioning to ensure it stays within viewport */
.scrollable-menu {
  height: auto;
  max-height: 40vh; /* Use viewport height for responsive sizing */
  overflow-x: hidden;
  overflow-y: auto;
}

.model-dropdown .dropdown-item {
  white-space: normal;
  word-wrap: break-word;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}

.model-dropdown .dropdown-item:last-child {
  border-bottom: none;
}

.model-dropdown .dropdown-item:hover {
  background-color: #f8f9fa;
}

#selected-model-text,
#selected-reasoning-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-grow: 1;
  text-align: left;
}

/* Message action buttons */
.edit-btn,
.delete-btn {
  padding: 0.375rem 0.5rem;
  font-size: 0.875rem;
  color: #6c757d;
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  display: inline-block;
  vertical-align: middle;
}

.edit-btn:hover,
.delete-btn:hover {
  opacity: 1;
  color: #495057;
}

.edit-btn i,
.delete-btn i {
  font-size: 1rem;
  pointer-events: none; /* Ensure clicks pass through to button */
}

/* Position edit button with spacing */
.edit-btn {
  margin-left: 0.5rem;
}

/* Position delete button to the right */
.delete-btn {
  margin-left: auto;
}

/* Messages drawn locally that the server has not confirmed yet */
.message-pending {
  opacity: 0.65;
}

.message-failed {
  background-color: #fdf0f1;
  border-left: 3px solid #dc3545;
}

/* Edit and delete act on a server-side uuid an unsent message does not have */
.message-unsent .edit-btn,
.message-unsent .delete-btn {
  display: none;
}

.message-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: #6c757d;
}

.message-status:empty {
  display: none;
}

.message-failed .message-status-text {
  color: #b02a37;
}

.message-status .status-btn {
  padding: 0 0.25rem;
  font-size: 0.75rem;
  line-height: 1.2;
  vertical-align: baseline;
}

/* Edit mode styles */
.edit-container {
  margin-top: 0.5rem;
  width: 100%;
}

.edit-textarea {
  font-size: 0.9rem;
  resize: vertical;
  min-height: 60px;
}

.edit-buttons {
  display: flex;
  gap: 0.5rem;
}
