/* ===================================================================
   HEARTH AI TUTOR — Embeddable Chat Widget
   Overlays on existing course pages
   =================================================================== */

/* === ROOT CONTAINER — must sit above all course content === */
#hearth-tutor-root {
  position: static;
  display: contents;
}

/* === FLOATING BUBBLE === */
.tutor-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5D4037, #3E2723);
  border: 3px solid #D7A86E;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 40px rgba(62, 39, 35, 0.35), 0 0 20px rgba(215, 168, 110, 0.3);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 99999;
  padding: 0;
  outline: none;
}

.tutor-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 40px rgba(62, 39, 35, 0.35), 0 0 30px rgba(215, 168, 110, 0.5);
}

.tutor-bubble.tutor-hidden { display: none; }

.tutor-bubble svg {
  width: 30px;
  height: 30px;
  fill: #D7A86E;
}

.tutor-bubble .tutor-pulse {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #D7A86E;
  animation: tutorPulse 2s ease-out infinite;
  pointer-events: none;
}

@keyframes tutorPulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* === CHAT PANEL === */
.tutor-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 420px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 48px);
  background: #FAF8F5;
  border-radius: 16px;
  border: 2px solid #D7A86E;
  box-shadow: 0 8px 40px rgba(62, 39, 35, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  z-index: 100000;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: 'Open Sans', -apple-system, sans-serif;
  font-size: 14px;
  color: #3E2723;
  line-height: 1.5;
}

.tutor-panel.tutor-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Reset for all tutor elements to avoid course CSS interference */
.tutor-panel *, .tutor-panel *::before, .tutor-panel *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* === HEADER === */
.tutor-header {
  background: linear-gradient(135deg, #3E2723, #5D4037);
  color: #FAF8F5;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.tutor-header-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(215, 168, 110, 0.2);
  border: 2px solid #D7A86E;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tutor-header-icon svg {
  width: 18px;
  height: 18px;
  fill: #D7A86E;
}

.tutor-header-info { flex: 1; }

.tutor-header-title {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.tutor-header-sub {
  font-size: 11px;
  opacity: 0.8;
  margin-top: 1px;
}

.tutor-close {
  background: none;
  border: none;
  color: #FAF8F5;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tutor-close:hover { background: rgba(255,255,255,0.15); }

/* === NAME SCREEN === */
.tutor-name-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}

.tutor-name-screen.tutor-hidden { display: none; }

.tutor-name-screen h2 {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 20px;
  color: #3E2723;
  margin-bottom: 8px;
  font-weight: 700;
}

.tutor-name-screen p {
  color: #6D5949;
  font-size: 14px;
  margin-bottom: 24px;
  line-height: 1.5;
}

.tutor-name-wrap {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 280px;
}

.tutor-name-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #E8C9A0;
  border-radius: 10px;
  font-family: 'Open Sans', sans-serif;
  font-size: 14px;
  color: #3E2723;
  background: white;
  outline: none;
  transition: border-color 0.3s;
}

.tutor-name-input:focus { border-color: #D7A86E; }

.tutor-name-go {
  padding: 10px 18px;
  background: #5D4037;
  color: #FAF8F5;
  border: none;
  border-radius: 10px;
  font-family: 'Open Sans', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.3s;
}

.tutor-name-go:hover { background: #3E2723; }

.tutor-name-skip {
  margin-top: 12px;
  background: none;
  border: none;
  color: #6D5949;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-family: 'Open Sans', sans-serif;
}

.tutor-name-skip:hover { color: #5D4037; }

/* === MODE SCREEN === */
.tutor-modes {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  overflow-y: auto;
}

.tutor-modes.tutor-hidden { display: none; }

.tutor-modes h3 {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 16px;
  color: #3E2723;
  margin-bottom: 4px;
  font-weight: 700;
}

.tutor-modes > p {
  font-size: 13px;
  color: #6D5949;
  margin-bottom: 16px;
}

.tutor-mode-card {
  background: white;
  border: 2px solid #EFEBE9;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s;
}

.tutor-mode-card:hover {
  border-color: #D7A86E;
  box-shadow: 0 2px 12px rgba(62, 39, 35, 0.1);
  transform: translateY(-1px);
}

.tutor-mode-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.tutor-mode-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}

.tutor-mode-icon.tutor-icon-general { background: rgba(93, 64, 55, 0.1); }
.tutor-mode-icon.tutor-icon-coach { background: rgba(215, 168, 110, 0.2); }

.tutor-mode-card-title {
  font-weight: 700;
  font-size: 14px;
  color: #3E2723;
}

.tutor-mode-card-desc {
  font-size: 13px;
  color: #6D5949;
  line-height: 1.4;
}

/* Sub-modes */
.tutor-submodes { padding-left: 8px; margin-top: 8px; }
.tutor-submodes.tutor-hidden { display: none; }

.tutor-submode {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: #FAF8F5;
  border: 1.5px solid #EFEBE9;
  border-radius: 10px;
  cursor: pointer;
  font-family: 'Open Sans', sans-serif;
  font-size: 13px;
  color: #3E2723;
  text-align: left;
  transition: border-color 0.3s, background 0.3s;
}

.tutor-submode:hover {
  border-color: #D7A86E;
  background: white;
}

.tutor-submode .tutor-sub-icon { font-size: 16px; flex-shrink: 0; }

/* === CHAT AREA === */
.tutor-chat { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tutor-chat.tutor-hidden { display: none; }

.tutor-mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #EFEBE9;
  border-bottom: 1px solid rgba(215, 168, 110, 0.2);
  flex-shrink: 0;
}

.tutor-mode-label {
  font-size: 12px;
  font-weight: 600;
  color: #5D4037;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tutor-mode-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tutor-new-scenario {
  background: #5D4037;
  color: #FAF8F5;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'Open Sans', sans-serif;
  cursor: pointer;
  transition: background 0.3s;
}

.tutor-new-scenario:hover { background: #3E2723; }
.tutor-new-scenario.tutor-hidden { display: none; }

.tutor-change-mode {
  background: none;
  border: none;
  font-size: 12px;
  color: #B8894A;
  cursor: pointer;
  font-family: 'Open Sans', sans-serif;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tutor-change-mode:hover { color: #5D4037; }

/* Messages */
.tutor-messages {
  flex: 1;
  overflow-y: scroll;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.tutor-messages {
  scrollbar-width: thin;
  scrollbar-color: #D7A86E #EFEBE9;
}
.tutor-messages::-webkit-scrollbar { width: 8px; }
.tutor-messages::-webkit-scrollbar-track { background: #EFEBE9; border-radius: 4px; }
.tutor-messages::-webkit-scrollbar-thumb { background: #D7A86E; border-radius: 4px; min-height: 40px; }
.tutor-messages::-webkit-scrollbar-thumb:hover { background: #B8894A; }

.tutor-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.tutor-msg-ai {
  align-self: flex-start;
  background: white;
  border: 1px solid #EFEBE9;
  border-bottom-left-radius: 4px;
  color: #3E2723;
}

.tutor-msg-user {
  align-self: flex-end;
  background: #5D4037;
  color: #FAF8F5;
  border-bottom-right-radius: 4px;
}

.tutor-msg-ai p { margin-bottom: 8px; }
.tutor-msg-ai p:last-child { margin-bottom: 0; }
.tutor-msg-ai strong { color: #3E2723; }
.tutor-msg-ai ul, .tutor-msg-ai ol { margin: 4px 0 8px 18px; }
.tutor-msg-ai li { margin-bottom: 2px; }

/* Typing indicator */
.tutor-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border: 1px solid #EFEBE9;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.tutor-typing.tutor-hidden { display: none; }

.tutor-dot {
  width: 7px;
  height: 7px;
  background: #D7A86E;
  border-radius: 50%;
  animation: tutorBounce 1.4s ease-in-out infinite;
}

.tutor-dot:nth-child(2) { animation-delay: 0.2s; }
.tutor-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes tutorBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Input */
.tutor-input-area {
  padding: 12px 14px;
  border-top: 1px solid #EFEBE9;
  background: white;
  flex-shrink: 0;
}

.tutor-input-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.tutor-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #EFEBE9;
  border-radius: 12px;
  font-family: 'Open Sans', sans-serif;
  font-size: 14px;
  color: #3E2723;
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.3s;
  background: white;
}

.tutor-input:focus { border-color: #D7A86E; }

.tutor-send {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #5D4037;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
  flex-shrink: 0;
}

.tutor-send:hover { background: #3E2723; }
.tutor-send:disabled { background: #8D6E63; cursor: not-allowed; opacity: 0.6; }
.tutor-send svg { width: 18px; height: 18px; fill: #FAF8F5; }

/* === MOBILE === */
@media (max-width: 480px) {
  .tutor-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .tutor-bubble { bottom: 16px; right: 16px; width: 56px; height: 56px; }
}
