/* ══════════════════════════════════════════════════════════════════
   Chat Reader Theme — e-reader aesthetic for the chat interface
   Forces dark theme regardless of site dark-mode toggle
   ══════════════════════════════════════════════════════════════════ */

/* ── Force dark page background ───────────────────────────────── */
body:has(#chat-background) {
  background: #1a1418 !important;
}
#chat-background {
  background: #1a1418 !important;
  padding: 0 !important;
  min-height: calc(100vh - 70px);
}
#chat-background > .container {
  max-width: 100% !important;
  padding: 0 !important;
}
section#chat-background .chat-background {
  background: #1e191d !important;
  border: none !important;
  border-radius: 0 !important;
  min-height: calc(100vh - 70px);
}

/* ── Contact / Character sidebar (chapter-list style) ─────────── */
section#chat-background .col-contacts-border {
  background: #2d2429 !important;
  border-right: 1px solid #3d3238 !important;
  max-width: 260px;
}
section#chat-background .ai-contacts-top {
  padding: 14px 16px 10px !important;
  border-bottom: 1px solid #3d3238 !important;
  min-height: auto !important;
  background: #2d2429 !important;
}
section#chat-background .ai-contacts-top strong {
  font-size: 0.7rem !important;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #888 !important;
  font-weight: 400 !important;
}
section#chat-background .ai-contacts-top span {
  font-size: 0.78rem !important;
  color: #555 !important;
}
section#chat-background .ai-contacts-scroll {
  height: calc(100vh - 180px) !important;
  background: #2d2429 !important;
}
section#chat-background .ai-contacts-scroll::-webkit-scrollbar { width: 3px; }
section#chat-background .ai-contacts-scroll::-webkit-scrollbar-thumb { background: #4a3a44; border-radius: 3px; }
section#chat-background .ai-contacts-scroll::-webkit-scrollbar-track { background: transparent; }
section#chat-background .ai-contacts-item {
  padding: 10px 12px !important;
  gap: 10px !important;
  border-bottom: 1px solid #3d3238 !important;
  transition: background 0.15s;
}
section#chat-background .ai-contacts-item:hover { background: #3d3238 !important; }
section#chat-background .ai-contacts-item-active,
section#chat-background .ai-contacts-item-active:hover {
  background: #3d2838 !important;
  border-left: 3px solid #C5A6BB !important;
}
section#chat-background .ai-contacts-image {
  width: 38px !important;
  min-width: 38px !important;
  height: 38px !important;
}
section#chat-background .ai-contacts-name {
  font-size: 0.82rem !important;
  color: #E0C5DB !important;
  font-weight: 600 !important;
}
section#chat-background .ai-contacts-job {
  font-size: 0.7rem !important;
  color: #888 !important;
}

/* ── Chat top bar ─────────────────────────────────────────────── */
section#chat-background .ai-chat-top {
  background: #252023 !important;
  border-bottom: 1px solid #3d3238 !important;
  padding: 10px 18px !important;
  min-height: auto !important;
  position: relative !important;
  overflow: visible !important;
}
section#chat-background .wrapper-ai-chat-top { gap: 0 12px !important; }
section#chat-background .ai-chat-top-image {
  width: 42px !important;
  height: 42px !important;
  min-width: 42px !important;
  border-radius: 50% !important;
  overflow: hidden;
  background: #2d2429 !important;
}
section#chat-background .ai-chat-top-image img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}
section#chat-background .ai-chat-top-name h4 {
  font-size: 0.9rem !important;
  color: #e8e0d5 !important;
  margin: 0 !important;
  font-weight: 600 !important;
}
section#chat-background .ai-chat-top-job {
  font-size: 0.72rem !important;
  color: #888 !important;
}
section#chat-background .ai-chat-top .badge,
section#chat-background .ai-chat-top .badge-info {
  background: #3d2838 !important;
  color: #C5A6BB !important;
  font-size: 0.68rem !important;
  border: 1px solid #4a3044 !important;
}
section#chat-background .ai-chat-top .dropdown-toggle,
section#chat-background .ai-chat-top .btn {
  color: #aaa !important;
  font-size: 0.78rem !important;
}
section#chat-background .ai-chat-top .dropdown-menu {
  background: #2a2030 !important;
  border: 1px solid #3d3238 !important;
  border-radius: 8px !important;
}
section#chat-background .ai-chat-top .dropdown-item {
  color: #ccc !important;
  font-size: 0.82rem !important;
}
section#chat-background .ai-chat-top .dropdown-item:hover {
  background: #3d2838 !important;
  color: #E0C5DB !important;
}

/* ── Chat frame & conversation area ───────────────────────────── */
section#chat-background .chat-frame {
  background: #1e191d !important;
  background-image: none !important;
}
section#chat-background #overflow-chat {
  background: #1e191d !important;
  padding: 20px 24px !important;
}
section#chat-background #overflow-chat::-webkit-scrollbar { width: 3px !important; }
section#chat-background #overflow-chat::-webkit-scrollbar-thumb { background: #4a3a44 !important; border-radius: 3px; }
section#chat-background #overflow-chat::-webkit-scrollbar-track { background: transparent !important; }

/* ── Conversation threads ─────────────────────────────────────── */
section#chat-background .conversation-thread {
  margin-bottom: 14px !important;
}
section#chat-background .message-container {
  background: #2d2429 !important;
  border: 1px solid #3d3238 !important;
  border-radius: 12px !important;
  border-bottom: none !important;
  padding: 12px 16px !important;
}
section#chat-background .message-container::before {
  border-right-color: #2d2429 !important;
}
section#chat-background .thread-ai .message-container {
  background: #2d2429 !important;
  border: 1px solid #3d3238 !important;
  border-bottom: none !important;
  min-width: auto !important;
}
section#chat-background .thread-user .message-container {
  background: #3d2838 !important;
  border: 1px solid #4a3044 !important;
  border-bottom: none !important;
}
section#chat-background .thread-user .message-container::before {
  display: none !important;
}
section#chat-background .thread-user .message-text::before {
  display: none !important;
}

/* Message text — reader-like serif */
section#chat-background .chat-response,
section#chat-background .message-text,
section#chat-background .message-container .message-text {
  font-size: 0.88rem !important;
  line-height: 1.75 !important;
  color: #d8d0c5 !important;
  font-family: Georgia, 'Times New Roman', serif !important;
}
section#chat-background .thread-user .message-text,
section#chat-background .thread-user .chat-response {
  color: #e8e0d5 !important;
}

/* User name */
section#chat-background .message-container .user-name h5 {
  color: #E0C5DB !important;
  font-size: 0.82rem !important;
}

/* Avatar */
section#chat-background .user-image {
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  left: 0 !important;
}

/* Date labels */
section#chat-background .date-chat {
  font-size: 0.68rem !important;
  color: #555 !important;
}

/* Action buttons */
section#chat-background .chat-actions {
  background: transparent !important;
  border: none !important;
}
section#chat-background .chat-action-buttons {
  background: #2a2030 !important;
  border: 1px solid #3d3238 !important;
  border-radius: 6px !important;
  color: #888 !important;
}
section#chat-background .chat-action-buttons:hover {
  background: #3d2838 !important;
  color: #E0C5DB !important;
}
section#chat-background .chat-action-buttons i {
  color: inherit !important;
}
section#chat-background .copy-text i,
section#chat-background .delete-message i {
  color: #888 !important;
  font-size: 14px !important;
}
section#chat-background .copy-text:hover i,
section#chat-background .delete-message:hover i {
  color: #E0C5DB !important;
}
section#chat-background .icons-options img,
section#chat-background .copy-text img {
  filter: brightness(0) saturate(100%) invert(100%) !important;
}

/* Typing indicator */
section#chat-background .is_typing,
section#chat-background .wait {
  color: #E0C5DB !important;
  font-size: 0.78rem !important;
}
section#chat-background .character-typing div {
  background: #2d2429 !important;
  color: #E0C5DB !important;
  font-size: 0.82rem !important;
}

/* ── Message input area ───────────────────────────────────────── */
section#chat-background .message-area-bottom {
  background: #252023 !important;
  border-top: 1px solid #3d3238 !important;
  padding: 12px 16px !important;
}
section#chat-background .chat-input {
  gap: 12px !important;
}
section#chat-background .chat-input textarea,
section#chat-background .chat-input input,
section#chat-background #chat {
  background: #1e191d !important;
  color: #e8e0d5 !important;
  border: 1px solid #3d3238 !important;
  font-size: 0.88rem !important;
  font-family: Georgia, 'Times New Roman', serif !important;
  border-radius: 20px !important;
  padding: 10px 16px !important;
}
section#chat-background .chat-input textarea::placeholder,
section#chat-background #chat::placeholder {
  color: #666 !important;
  font-style: italic;
}
section#chat-background .chat-input textarea:focus,
section#chat-background .chat-input input:focus,
section#chat-background #chat:focus {
  outline: none !important;
  box-shadow: none !important;
  border-color: #C5A6BB !important;
}

/* Send / Cancel buttons */
section#chat-background .btn-send-chat {
  background: #C5A6BB !important;
  border: none !important;
  border-radius: 20px !important;
  padding: 6px 18px !important;
  font-size: 0.8rem !important;
  color: #fff !important;
}
section#chat-background .btn-send-chat:hover,
section#chat-background .btn-send-chat:active,
section#chat-background .btn-send-chat:focus {
  background: #A888A0 !important;
  color: #fff !important;
}
section#chat-background .btn-send-chat img {
  filter: brightness(10) !important;
  height: 14px;
}
section#chat-background .btn-cancel-chat {
  background: #3d2838 !important;
  border: 1px solid #4a3044 !important;
  border-radius: 20px !important;
  color: #ccc !important;
}
section#chat-background .stop-chat-label {
  font-size: 0.78rem !important;
}

/* Credits bar */
section#chat-background .my-credits {
  color: #888 !important;
  font-size: 0.72rem !important;
}

/* ── Options / form selects ───────────────────────────────────── */
section#chat-background .col-options-input .form-floating label {
  color: #888 !important;
  font-size: 0.78rem !important;
}
section#chat-background .form-floating > .form-select,
section#chat-background .form-select {
  background-color: #2d2429 !important;
  color: #d8d0c5 !important;
  border: 1px solid #3d3238 !important;
  font-size: 0.82rem !important;
  border-radius: 8px !important;
}
section#chat-background .form-floating > label {
  color: #888 !important;
}
section#chat-background .form-select:focus {
  border-color: #C5A6BB !important;
  box-shadow: none !important;
}
section#chat-background .form-select option {
  background: #2d2429 !important;
  color: #d8d0c5 !important;
}

/* ── Image upload / mic ───────────────────────────────────────── */
section#chat-background .image-upload-wrapper .image-label {
  color: #888 !important;
}
section#chat-background .image-upload-wrapper .image-label:hover {
  color: #E0C5DB !important;
}
section#chat-background #microphone-button {
  filter: brightness(0.6) !important;
}
section#chat-background #microphone-button:hover {
  filter: brightness(0.8) !important;
}

/* ── Modals ───────────────────────────────────────────────────── */
section#chat-background .modal-content {
  background: #2d2429 !important;
  border: 1px solid #3d3238 !important;
  color: #d8d0c5 !important;
}
section#chat-background .modal-header {
  border-bottom: 1px solid #3d3238 !important;
}
section#chat-background .modal-footer {
  border-top: 1px solid #3d3238 !important;
}
section#chat-background .modal-title {
  color: #E0C5DB !important;
  font-size: 0.95rem !important;
}
section#chat-background .modal-body {
  font-size: 0.85rem !important;
  line-height: 1.6 !important;
  color: #bbb !important;
}
section#chat-background .btn-close {
  filter: invert(1) !important;
}
section#chat-background .list-group-item {
  background: #1e191d !important;
  border-color: #3d3238 !important;
  color: #d8d0c5 !important;
  font-size: 0.82rem !important;
}
section#chat-background .use-suggestion {
  background: #C5A6BB !important;
  border: none !important;
  color: #fff !important;
  font-size: 0.78rem !important;
}

/* ── VIP panels ───────────────────────────────────────────────── */
section#chat-background .wrapper-vip-credit-pack {
  background: #2d2429 !important;
  border: 1px solid #3d3238 !important;
  border-radius: 10px !important;
}
section#chat-background .wrapper-vip-credit-info h4 {
  color: #e8e0d5 !important;
  font-size: 0.9rem !important;
}
section#chat-background .wrapper-vip-credit-info h5 {
  color: #E0C5DB !important;
  font-size: 0.85rem !important;
}
section#chat-background .wrapper-vip-message {
  background: #2d2429 !important;
  border: 1px solid #3d3238 !important;
  color: #d8d0c5 !important;
}

/* ── Dropdown menus ───────────────────────────────────────────── */
section#chat-background .dropdown-menu {
  background: #2a2030 !important;
  border: 1px solid #3d3238 !important;
}
section#chat-background .dropdown-item {
  color: #ccc !important;
  font-size: 0.82rem !important;
}
section#chat-background .dropdown-item:hover {
  background: #3d2838 !important;
  color: #E0C5DB !important;
}

/* ── Alert messages ───────────────────────────────────────────── */
section#chat-background .alert {
  background: #2d2429 !important;
  border: 1px solid #3d3238 !important;
  color: #d8d0c5 !important;
  font-size: 0.85rem !important;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 991px) {
  section#chat-background .col-contacts-border {
    display: none !important;
  }
}

@media (max-width: 767px) {
  /* Chat top header — safe padding so nothing clips edges */
  section#chat-background .ai-chat-top {
    padding: 10px 14px !important;
    min-height: auto !important;
    position: relative !important;
    overflow: visible !important;
  }
  section#chat-background .wrapper-ai-chat-top {
    gap: 0 10px !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
  }
  section#chat-background .ai-chat-top-image {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    min-height: 42px !important;
    flex-shrink: 0 !important;
  }
  section#chat-background .ai-chat-top-info {
    flex: 1 !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }
  section#chat-background .ai-chat-top-name h4 {
    font-size: 0.9rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  section#chat-background .ai-chat-top-job {
    font-size: 0.72rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  section#chat-background .icons-options {
    gap: 8px !important;
    flex-shrink: 0 !important;
  }

  /* Message scroll area — enough padding so avatar isn't clipped */
  section#chat-background #overflow-chat {
    padding: 14px 12px 14px 46px !important;
  }

  /* Conversation thread — position:relative so absolute avatar sits inside */
  section#chat-background .conversation-thread {
    position: relative !important;
    margin-left: 0 !important;
    margin-bottom: 18px !important;
  }

  /* Avatar — anchored inside thread, not clipping outside viewport */
  section#chat-background .user-image {
    position: absolute !important;
    left: -38px !important;
    top: 0 !important;
    width: 30px !important;
    min-width: 30px !important;
    height: 30px !important;
    min-height: 30px !important;
  }

  /* Message bubble — full available width, small border-radius on mobile */
  section#chat-background .message-container {
    border-radius: 10px !important;
    padding: 10px 12px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  section#chat-background .thread-ai .message-container {
    margin-right: 0 !important;
    margin-left: 0 !important;
  }
  section#chat-background .thread-user .message-container {
    margin-left: auto !important;
    max-width: 92% !important;
  }

  /* Input bar — sits flush at bottom, proper side padding */
  section#chat-background .message-area-bottom {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    padding: 10px 14px !important;
    box-sizing: border-box !important;
    z-index: 999 !important;
  }
  section#chat-background .chat-input {
    gap: 8px !important;
  }
  section#chat-background .chat-input textarea,
  section#chat-background .chat-input input {
    font-size: 0.9rem !important;
    height: 52px !important;
    padding: 8px 12px !important;
    border-radius: 8px !important;
  }
  section#chat-background .btn-send-chat,
  section#chat-background .btn-cancel-chat {
    padding: 0 14px !important;
    font-size: 0.85rem !important;
    border-radius: 8px !important;
    min-height: 52px !important;
  }
  /* Microphone button */
  section#chat-background #microphone-button {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
  }

  /* Extra scroll-bottom space so the fixed input doesn't cover last message */
  section#chat-background #overflow-chat {
    padding-bottom: 90px !important;
  }

  /* Aa font toggle position fix for mobile */
  .chat-fs-controls {
    right: 0 !important;
  }

  /* Badge tags wrap nicely */
  section#chat-background .ai-chat-top .badge {
    font-size: 0.62rem !important;
    padding: 2px 6px !important;
  }
}

/* ── Font size controls ───────────────────────────────────────── */
.chat-fs-controls {
  position: absolute;
  right: 16px;
  top: 100%;
  background: #2d2429;
  border: 1px solid #3d3238;
  border-radius: 8px;
  padding: 8px 10px;
  display: none;
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 999;
  margin-top: 4px;
}
.chat-fs-controls.open { display: flex; }
.chat-fs-controls__label {
  font-size: 0.68rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-right: 4px;
  display: flex;
  align-items: center;
}
.chat-fs-btn {
  background: none;
  border: 1px solid #4a3a44;
  color: #aaa;
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}
.chat-fs-btn:hover { border-color: #E0C5DB; color: #E0C5DB; }
.chat-fs-btn.active {
  background: #3d2838;
  border-color: #C5A6BB;
  color: #E0C5DB;
}

/* Font size modifier classes */
section#chat-background.chat-fs-s .chat-response,
section#chat-background.chat-fs-s .message-text,
section#chat-background.chat-fs-s .message-container .message-text {
  font-size: 0.78rem !important;
  line-height: 1.65 !important;
}
section#chat-background.chat-fs-m .chat-response,
section#chat-background.chat-fs-m .message-text,
section#chat-background.chat-fs-m .message-container .message-text {
  font-size: 0.88rem !important;
  line-height: 1.75 !important;
}
section#chat-background.chat-fs-l .chat-response,
section#chat-background.chat-fs-l .message-text,
section#chat-background.chat-fs-l .message-container .message-text {
  font-size: 1.05rem !important;
  line-height: 1.85 !important;
}
section#chat-background.chat-fs-s .date-chat { font-size: 0.62rem !important; }
section#chat-background.chat-fs-l .date-chat { font-size: 0.75rem !important; }
section#chat-background.chat-fs-s .message-container .user-name h5 { font-size: 0.72rem !important; }
section#chat-background.chat-fs-l .message-container .user-name h5 { font-size: 0.92rem !important; }

/* Aa toggle button in chat top bar */
.chat-font-toggle {
  background: none !important;
  border: 1px solid #4a3a44 !important;
  color: #aaa !important;
  border-radius: 6px !important;
  padding: 3px 10px !important;
  font-size: 0.82rem !important;
  cursor: pointer !important;
  transition: all 0.2s !important;
  font-family: Georgia, serif !important;
  font-weight: 700 !important;
  margin-left: 8px !important;
}
.chat-font-toggle:hover {
  border-color: #E0C5DB !important;
  color: #E0C5DB !important;
}
