/* KidsGPT custom styles */

/* Conversation starter cards */
.card-starter {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-starter:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Chat input area (landing page legacy) */
.container-tight {
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

/* ============================================================
   Chat Page Layout (Tabler navbar-vertical sidebar)
   ============================================================ */

.chat-page {
  height: 100vh;
  overflow: hidden;
}

/* Make the navbar-vertical sidebar use full height with flex layout */
.chat-page .navbar-vertical > .container-fluid {
  flex-direction: column;
  align-items: stretch;
}

.chat-page .navbar-vertical .navbar-collapse {
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Page wrapper fills remaining space */
.chat-page .page-wrapper {
  height: 100vh;
  max-height: 100vh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden;
}

.chat-main {
  flex: 1;
  min-height: 0;
  height: 100%;
}

/* Sidebar search input styling for dark theme */
.chat-page .navbar-vertical .form-control {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--tblr-light);
}

.chat-page .navbar-vertical .form-control::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.chat-page .navbar-vertical .form-control:focus {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--tblr-primary);
  color: var(--tblr-light);
}

/* Sidebar footer */
.chat-sidebar-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: auto;
  width: 100%;
}

.chat-sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.chat-sidebar-username {
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.8);
}

.chat-sidebar-footer-link {
  color: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  padding: 0.25rem;
  border-radius: var(--tblr-border-radius);
}

.chat-sidebar-footer-link:hover {
  color: var(--tblr-light);
  background: rgba(255, 255, 255, 0.1);
}


/* Conversation list groups */
.conversation-group {
  margin-bottom: 0.5rem;
}

.conversation-group-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.4);
  padding: 0.5rem 0.75rem 0.25rem;
}

/* Conversation items */
.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: var(--tblr-border-radius);
  cursor: pointer;
  position: relative;
  min-height: 44px; /* Touch target */
}

.conversation-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.conversation-item.active {
  background: rgba(255, 255, 255, 0.15);
}

.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
}

.conversation-actions {
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.conversation-item:hover .conversation-actions {
  opacity: 1;
}

.btn-menu {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 2px;
  border-radius: var(--tblr-border-radius);
}

.btn-menu:hover {
  color: var(--tblr-light);
  background: rgba(255, 255, 255, 0.1);
}

/* Conversation context menu popup */
.conv-menu-popup {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  background: var(--tblr-bg-surface);
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  min-width: 120px;
  overflow: hidden;
}

.conv-menu-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  color: var(--tblr-body-color);
  font-size: 0.875rem;
}

.conv-menu-item:hover {
  background: var(--tblr-bg-surface-secondary);
}

.conv-menu-danger {
  color: var(--tblr-danger);
}

.conv-menu-danger:hover {
  background: rgba(var(--tblr-danger-rgb), 0.1);
}

/* Inline rename input */
.conversation-rename-input {
  font-size: 0.875rem;
  padding: 0.125rem 0.375rem;
  height: auto;
}

/* Inline delete confirmation */
.btn-inline-confirm {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  vertical-align: middle;
  color: inherit;
}

.btn-inline-confirm:hover {
  color: var(--tblr-primary);
}


/* ============================================================
   Main Chat Area
   ============================================================ */

.chat-main {
  min-width: 0;
  min-height: 0;
  background: var(--tblr-bg-surface-secondary);
  position: relative;
  overflow: hidden;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  padding-bottom: 1rem;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 0%;
}

/* Empty state */
.empty-state {
  pointer-events: auto;
}

.empty-state .starter-cards,
.empty-state .card-starter {
  pointer-events: auto;
}

/* ============================================================
   Message Bubbles
   ============================================================ */

.message {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 0;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.message-user {
  flex-direction: row-reverse;
}

.message-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tblr-primary-lt);
  border-radius: 50%;
  color: var(--tblr-primary);
}

.message-bubble {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  position: relative;
  line-height: 1.5;
}

.message-user .message-bubble {
  background: var(--tblr-primary-lt);
  border-bottom-right-radius: 0.25rem;
  color: var(--tblr-body-color);
}

.message-assistant .message-bubble {
  background: var(--tblr-bg-surface);
  border: 1px solid var(--tblr-border-color);
  border-bottom-left-radius: 0.25rem;
}

/* Message content prose styles */
.message-content p:last-child {
  margin-bottom: 0;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin-top: 0.75rem;
  margin-bottom: 0.5rem;
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
  margin-top: 0;
}

.message-content ul,
.message-content ol {
  margin-bottom: 0.5rem;
  padding-left: 1.25rem;
}

.message-content table {
  width: 100%;
  margin-bottom: 0.5rem;
  border-collapse: collapse;
}

.message-content table th,
.message-content table td {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--tblr-border-color);
}

.message-content table th {
  background: var(--tblr-bg-surface-secondary);
  font-weight: 600;
}

.message-content a {
  color: var(--tblr-primary);
  text-decoration: underline;
}

/* Message hover actions */
.message-hover-actions {
  position: absolute;
  top: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.message-user .message-hover-actions {
  left: -2rem;
}

.message-assistant .message-hover-actions {
  right: -2rem;
}

.message-bubble:hover .message-hover-actions {
  opacity: 1;
}

.btn-msg-action {
  background: var(--tblr-bg-surface);
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  padding: 0.25rem;
  cursor: pointer;
  color: var(--tblr-secondary);
  display: flex;
  align-items: center;
}

.btn-msg-action:hover {
  color: var(--tblr-body-color);
  background: var(--tblr-bg-surface-secondary);
}

/* Regenerate button */
.regenerate-btn {
  align-self: flex-start;
  margin-left: 2.75rem; /* align with assistant bubble */
}

/* ============================================================
   Streaming Cursor
   ============================================================ */

.streaming-cursor::after {
  content: '\2588';
  animation: blink 1s step-end infinite;
  color: var(--tblr-primary);
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ============================================================
   Code Blocks
   ============================================================ */

.code-block {
  position: relative;
  border-radius: var(--tblr-border-radius);
  overflow: hidden;
  margin: 0.5rem 0;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #2d333b;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

.code-lang {
  color: #8b949e;
  font-family: var(--tblr-font-monospace);
}

.btn-copy {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #8b949e;
  cursor: pointer;
  padding: 0.125rem 0.5rem;
  border-radius: var(--tblr-border-radius);
  font-size: 0.75rem;
  transition: color 0.15s, border-color 0.15s;
}

.btn-copy:hover {
  color: #c9d1d9;
  border-color: rgba(255, 255, 255, 0.3);
}

.code-block pre {
  margin: 0;
  padding: 0.75rem;
  background: #1c2128;
  overflow-x: auto;
}

.code-block code {
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* ============================================================
   Chat Input Area
   ============================================================ */

.chat-input-area {
  padding: 1rem;
  background: var(--tblr-bg-surface);
  border-top: 1px solid var(--tblr-border-color);
  flex-shrink: 0;
}

.chat-input-area textarea {
  resize: none;
  overflow-y: auto;
  max-height: 150px;
  line-height: 1.5;
}

/* ============================================================
   Responsive / Mobile
   ============================================================ */

@media (max-width: 991.98px) {

  /* Wider bubbles on mobile */
  .message-bubble {
    max-width: 90%;
  }

  /* Prevent iOS zoom on input focus */
  .chat-input-area textarea {
    font-size: 16px;
  }

  .chat-input-area {
    padding: 0.5rem;
  }

  /* Adjust message hover actions for touch -- always visible */
  .message-hover-actions {
    opacity: 1;
  }

  /* Touch targets -- ensure minimum 44x44px on mobile */
  .btn-msg-action {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn-copy {
    min-width: 44px;
    min-height: 44px;
  }

  .btn-menu {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .conv-menu-item {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .btn-inline-confirm {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  #send-btn,
  #stop-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .card-starter {
    min-height: 44px;
  }

  .regenerate-btn {
    min-height: 44px;
  }
}

/* Edit inline textarea */
.edit-container {
  width: 100%;
}

.edit-textarea {
  width: 100%;
  resize: none;
  border-radius: 0.5rem;
  font-size: inherit;
  font-family: inherit;
  line-height: 1.5;
  padding: 0.5rem 0.75rem;
  background: var(--tblr-bg-surface);
  color: var(--tblr-body-color);
  border: 1px solid var(--tblr-border-color);
}

.edit-textarea:focus {
  outline: none;
  border-color: var(--tblr-primary);
  box-shadow: 0 0 0 0.25rem rgba(var(--tblr-primary-rgb), 0.25);
}

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

/* ============================================================
   Generated Images
   ============================================================ */

.generated-image {
  width: 100%;
  border-radius: 8px;
  margin: 0.5rem 0;
  display: block;
}

.image-caption {
  display: block;
  font-size: 0.8rem;
  color: var(--tblr-secondary);
  font-style: italic;
  margin-top: 0.25rem;
}

/* Model label shown below assistant messages */
.model-label {
  font-size: 0.75rem;
  color: var(--tblr-secondary);
  margin-top: 0.5rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--tblr-border-color-translucent);
}

/* ============================================================
   File Attachments
   ============================================================ */

/* Drop overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(var(--tblr-primary-rgb), 0.08);
  border: 2px dashed var(--tblr-primary);
  border-radius: var(--tblr-border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--tblr-primary);
  font-size: 1rem;
  font-weight: 500;
}

/* Attachment preview strip above input */
.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  max-height: 120px;
  overflow-y: auto;
}

.attachment-preview-item {
  position: relative;
  display: inline-flex;
}

.attachment-preview-thumb {
  max-height: 60px;
  max-width: 80px;
  border-radius: var(--tblr-border-radius);
  object-fit: cover;
}

.attachment-chip-preview {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--tblr-bg-surface-secondary);
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  padding: 4px 8px;
  font-size: 0.8125rem;
  max-width: 180px;
}

.attachment-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100px;
}

.attachment-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--tblr-border-color);
  border-radius: 50%;
  background: var(--tblr-bg-surface);
  color: var(--tblr-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.attachment-remove-btn:hover {
  color: var(--tblr-danger);
  border-color: var(--tblr-danger);
}

/* Attachment display in message bubbles */
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.attachment-thumbnail {
  max-width: 300px;
  max-height: 200px;
  border-radius: var(--tblr-border-radius);
  cursor: pointer;
  object-fit: contain;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--tblr-bg-surface-secondary);
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  padding: 4px 8px;
  font-size: 0.8125rem;
}

/* Toast notification */
.toast-notification {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  min-width: 300px;
  max-width: 450px;
  animation: toast-fade-in 0.3s ease;
  transition: opacity 0.3s ease;
}

@keyframes toast-fade-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

