/* =========================================================================
   Pro Chat Sidebar Polishing
   Place this file at: static/css/custom.css
   ========================================================================= */

/* ----------------------------- Color tokens ----------------------------- */
:root {
  --chat-bg: #f8f9fa;
  --chat-border: #dee2e6;
  --chat-shadow: 0 2px 6px rgba(0,0,0,.05);
  --bubble-bot-bg: #f7f9fc;
  --bubble-bot-border: #eef2f7;
  --bubble-user-bg: #e7f1ff;
  --bubble-user-border: #cfe2ff;
}

/* ----------------------- Chat card (right sidebar) ---------------------- */
.col-lg-4 .card {
  border-radius: .75rem;
  box-shadow: 0 .1rem .6rem rgba(16,24,40,.06);
}

/* Header spacing + typography */
.col-lg-4 .card-header {
  padding: .6rem .9rem;
}
.col-lg-4 .card-header small {
  font-weight: 600;
}

/* Ensure inner header row spans full width so right label can align right */
.card-header .d-flex {
  width: 100%;
}

/* -------------------- Chat body / transcript area ----------------------- */
#chat-body {
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: .5rem;
  padding: 1rem;
  height: 420px;               /* comfortable height */
  overflow-y: auto;
  box-shadow: var(--chat-shadow);
  font-size: .95rem;
  line-height: 1.5;
}

/* Polished scrollbars */
#chat-body::-webkit-scrollbar { width: 8px; }
#chat-body::-webkit-scrollbar-thumb { background:#d0d5dd; border-radius:10px; }
#chat-body { scrollbar-width: thin; scrollbar-color: #d0d5dd transparent; }

/* Bot message bubble (matches your JS classes) */
#chat-body .mb-2.p-2.bg-light.rounded {
  background: var(--bubble-bot-bg) !important;
  border: 1px solid var(--bubble-bot-border);
  border-radius: .75rem;
  padding: .6rem .8rem !important;
  max-width: 95%;
  word-wrap: break-word;
}

/* User message bubble (your JS uses 'text-end mb-2') */
#chat-body .text-end.mb-2 {
  max-width: 90%;
  margin-left: auto;
  background: var(--bubble-user-bg);
  border: 1px solid var(--bubble-user-border);
  border-radius: .75rem .75rem .25rem .75rem;
  padding: .5rem .75rem;
  display: inline-block;
}

/* Typing indicator refinement */
.typing-indicator {
  background: #eef2f7;
  color: #475467;
  border-radius: 1rem;
}

/* -------------------- Composer (textarea + buttons) --------------------- */

/* Textarea */
#chat-input {
  resize: none;
  min-height: 44px;
  max-height: 160px;
  border: 1px solid #e4e7ec !important;
  border-radius: .5rem;
  padding: .55rem .7rem;
  box-shadow: inset 0 1px 2px rgba(16,24,40,.04);
  background: #fff;
}

/* Buttons row: make all three equal width and same height */
#mic-btn, #send-btn, #stop-stream-btn {
  height: 42px;
  border-radius: .5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  box-shadow: 0 1px 2px rgba(16,24,40,.05);
  flex: 1 1 0;          /* evenly spread in the row */
  min-width: 0;         /* allow shrinking on small screens */
}

/* Mic states (your JS toggles these classes) */
#mic-btn.btn-outline-secondary { border-color:#d0d5dd; }
#mic-btn.btn-danger { color:#fff; }

/* Stop button look */
#stop-stream-btn.btn-warning {
  color: #7a4100;
  border-color: #fddcab;
  background: #ffe4bd;
}
#stop-stream-btn:disabled { opacity: .5; cursor: not-allowed; }

/* “Edit Response” button (if present) */
#cache-edit-btn {
  border-color: #e5e7eb !important;
  background: #fff !important;
}

/* -------------------------- Audio element ------------------------------- */
audio {
  width: 100%;
  margin-top: .5rem;
  border-radius: .5rem;
  border: 1px solid #e5e7eb;
  background: #fff;
}

/* ------------------ Read-aloud word highlighting ------------------------ */
#tts-content span,
.chat-tts-content span {
  display: inline-block;
  background-color: transparent;
  transition: background-color .1s ease;
}
#tts-content span.highlight,
.chat-tts-content span.highlight {
  background-color: #ffeb3b !important;
  padding: 0 2px;
  border-radius: 2px;
}

/* ------------------ TTS mini controls in lesson area -------------------- */
.tts-controls { gap: .5rem; }
.tts-status { margin-left: auto; font-size: .8rem; color: #667085; }

/* Pagination chips for textbook TTS */
.tts-nav-btns { gap: .25rem; }
.tts-nav-btns .page-num-btn {
  min-width: 2rem;
  padding: .2rem .5rem;
  font-size: .75rem;
  border-radius: .25rem;
}

/* ---------------------- Header dropdowns (optional) --------------------- */
/* If you keep Language/Voice selects in the header, ensure they look right */
.card-header.bg-primary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  flex-wrap: wrap;
}

.card-header .form-select {
  min-width: 120px;
  background: #fff !important;
  color: #212529 !important;
  border: 1px solid #dee2e6 !important;
  border-radius: .375rem !important;
  padding: .25rem .5rem !important;
  height: auto !important;
  line-height: 1.25;
  box-shadow: none !important;
  appearance: auto;
  -webkit-appearance: menulist;
  -moz-appearance: menulist;
}

/* Fix Safari/iOS text color */
.card-header .form-select,
.card-header .form-select:focus {
  -webkit-text-fill-color: #212529 !important;
}

.card-header .form-select option {
  color: #212529 !important;
  background: #fff !important;
}

/* --------------------------- Responsive tweaks -------------------------- */
@media (max-width: 992px) {
  #chat-body { height: 360px; }
}

@media (max-width: 576px) {
  .card-header.bg-primary {
    padding-top: .5rem !important;
    padding-bottom: .5rem !important;
    gap: .4rem;
  }
  .card-header .form-select {
    flex: 1 1 48%;
    min-width: 0;
  }
}
