/* ==========================================================
   SHS Bot - floating AI study-helper widget
   Self-contained: brand colors are re-declared here (not
   inherited from the host page's :root) so this widget looks
   right and stays isolated from page styles on any page it's
   dropped into.
   ========================================================== */
#shs-bot-launcher,
#shs-bot-panel {
  --shs-indigo: #211B5E;
  --shs-indigo-deep: #150F3E;
  --shs-marigold: #E2962E;
  --shs-vermilion: #B33F32;
  --shs-paper: #F7F1E4;
  --shs-paper-2: #EFE6D2;
  --shs-ink: #2A2620;
  --shs-line: #E4D9BC;
  --shs-white: #FFFDF8;
  --shs-radius: 20px;
  font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
#shs-bot-launcher *,
#shs-bot-panel * { box-sizing: border-box; }
#shs-bot-launcher button, #shs-bot-panel button,
#shs-bot-panel textarea {
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
#shs-bot-panel svg, #shs-bot-launcher svg { display: block; flex-shrink: 0; }

/* ---------------- Launcher ---------------- */
#shs-bot-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9999;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--shs-indigo), var(--shs-indigo-deep));
  box-shadow: 0 10px 26px rgba(21, 15, 62, .38);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}
#shs-bot-launcher:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 32px rgba(21,15,62,.46); }
#shs-bot-launcher.shs-hidden { opacity: 0; transform: scale(.5); pointer-events: none; }
#shs-bot-launcher svg { fill: var(--shs-white); }
#shs-bot-launcher .shs-pulse {
  position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(226,150,46,.55);
  animation: shsPulse 2.4s infinite;
  pointer-events: none;
}
@keyframes shsPulse {
  0%   { box-shadow: 0 0 0 0 rgba(226,150,46,.5); }
  70%  { box-shadow: 0 0 0 16px rgba(226,150,46,0); }
  100% { box-shadow: 0 0 0 0 rgba(226,150,46,0); }
}

/* ---------------- Panel shell ---------------- */
#shs-bot-panel {
  position: fixed;
  right: 22px;
  bottom: 96px;
  z-index: 9999;
  width: 384px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 140px);
  background: var(--shs-white);
  border-radius: var(--shs-radius);
  box-shadow: 0 24px 64px rgba(20,15,60,.30);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.97);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
#shs-bot-panel.open { opacity: 1; visibility: visible; transform: none; pointer-events: auto; }

/* ---------------- Header ---------------- */
.shs-head {
  background: linear-gradient(135deg, var(--shs-indigo), var(--shs-indigo-deep));
  color: var(--shs-white);
  padding: 14px 12px 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}
.shs-head .shs-avatar {
  position: relative;
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .74rem; letter-spacing: .02em;
}
.shs-avatar .shs-status {
  position: absolute; right: -1px; bottom: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #3fbb63; border: 2px solid var(--shs-indigo-deep);
}
.shs-head .shs-title { flex: 1; min-width: 0; line-height: 1.25; }
.shs-head .shs-title b { display: block; font-size: .98rem; font-weight: 700; }
.shs-head .shs-title span { display: block; font-size: .72rem; opacity: .82; }
.shs-head-btn {
  background: rgba(255,255,255,.14);
  border: none; color: var(--shs-white);
  width: 32px; height: 32px; border-radius: 9px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s ease;
}
.shs-head-btn:hover { background: rgba(255,255,255,.26); }
.shs-head-btn svg { fill: var(--shs-white); }
.shs-sound-toggle.muted { background: rgba(0,0,0,.2); }

/* ---------------- Privacy strip ---------------- */
.shs-privacy {
  flex: 0 0 auto;
  font-size: .7rem;
  color: #7A6F52;
  background: var(--shs-paper-2);
  padding: 7px 14px;
  border-bottom: 1px solid var(--shs-line);
}

/* ---------------- Messages ---------------- */
.shs-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--shs-paper);
}
.shs-msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 15px;
  font-size: .87rem;
  line-height: 1.48;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(21,15,62,.05);
}
.shs-msg.bot   { align-self: flex-start; background: var(--shs-white); border: 1px solid var(--shs-line); color: var(--shs-ink); border-bottom-left-radius: 4px; }
.shs-msg.user  { align-self: flex-end; background: linear-gradient(135deg, var(--shs-indigo), var(--shs-indigo-deep)); color: #fff; border-bottom-right-radius: 4px; box-shadow: 0 3px 10px rgba(21,15,62,.22); }
.shs-msg.error { align-self: flex-start; background: #FBEDEA; border: 1px solid #EAC1B8; color: var(--shs-vermilion); }

.shs-typing { align-self: flex-start; display: flex; gap: 4px; padding: 11px 13px; background: var(--shs-white); border: 1px solid var(--shs-line); border-radius: 15px; border-bottom-left-radius: 4px; }
.shs-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--shs-marigold); opacity: .55; animation: shsBounce 1.2s infinite; }
.shs-typing span:nth-child(2) { animation-delay: .15s; }
.shs-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes shsBounce { 0%, 60%, 100% { transform: translateY(0); opacity:.4; } 30% { transform: translateY(-4px); opacity:1; } }

/* ---------------- Input bar ---------------- */
.shs-inputbar {
  flex: 0 0 auto;
  border-top: 1px solid var(--shs-line);
  padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--shs-white);
}
.shs-inputbar textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--shs-line);
  border-radius: 13px;
  padding: 10px 12px;
  font-size: .87rem;
  max-height: 90px;
  outline: none;
  color: var(--shs-ink);
  background: var(--shs-paper);
  transition: border-color .15s ease, background .15s ease;
}
.shs-inputbar textarea::placeholder { color: #9A8F72; }
.shs-inputbar textarea:focus { border-color: var(--shs-indigo); background: var(--shs-white); }

.shs-icon-btn {
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s ease, transform .1s ease;
}
.shs-icon-btn:active { transform: scale(.92); }

.shs-mic-btn { background: var(--shs-paper-2); }
.shs-mic-btn svg { fill: var(--shs-indigo); }
.shs-mic-btn:hover { background: var(--shs-line); }
.shs-mic-btn.listening { background: var(--shs-vermilion); animation: shsMicPulse 1s infinite; }
.shs-mic-btn.listening svg { fill: #fff; }
@keyframes shsMicPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.shs-send-btn { background: var(--shs-indigo); }
.shs-send-btn svg { fill: #fff; }
.shs-send-btn:hover { background: var(--shs-indigo-deep); }
.shs-send-btn:disabled { opacity: .5; cursor: default; }

/* ---------------- Scrollbar polish (WebKit) ---------------- */
.shs-messages::-webkit-scrollbar { width: 6px; }
.shs-messages::-webkit-scrollbar-thumb { background: var(--shs-line); border-radius: 6px; }

/* ==========================================================
   Responsive
   Tablet: 481px – 900px  -> resized floating card
   Mobile: <= 480px       -> true full-screen takeover
   ========================================================== */
@media (min-width: 481px) and (max-width: 900px) {
  #shs-bot-panel {
    width: min(400px, calc(100vw - 40px));
    height: min(600px, calc(100vh - 130px));
  }
}

@media (max-width: 480px) {
  #shs-bot-launcher { right: 16px; bottom: 16px; width: 56px; height: 56px; }
  #shs-bot-launcher svg { width: 24px; height: 24px; }

  #shs-bot-panel {
    right: 0; left: 0; top: 0; bottom: 0;
    width: 100%; max-width: 100%;
    height: 100%; max-height: 100%;
    border-radius: 0;
    transform: translateY(100%);
  }
  #shs-bot-panel.open { transform: none; }

  .shs-head { padding-top: max(14px, env(safe-area-inset-top)); }
  .shs-msg { max-width: 90%; }
}
