/* Study Hall — acewithgrace.space library chat widget.
   Brand palette: dark teal #2A5E51, cream #F7F3EA, terracotta #CD7346, charcoal #2A2A28.
   Only renders when /api/library/status reports inLibrary=true. */

#sh-fab {
  position: fixed; right: 18px; bottom: 90px; z-index: 2147483000;
  display: flex; align-items: center; gap: 8px;
  background: #2A5E51; color: #F7F3EA; border: none; border-radius: 999px;
  padding: 12px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 18px rgba(0,0,0,.25); font-family: inherit;
}
#sh-fab:hover { background: #234e44; }
#sh-fab .sh-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #7fc8a9;
  box-shadow: 0 0 6px #7fc8a9;
}
#sh-fab .sh-count {
  background: #CD7346; border-radius: 999px; padding: 1px 8px; font-size: 12px;
}

#sh-panel {
  position: fixed; right: 18px; bottom: 148px; z-index: 2147483001;
  width: 380px; max-width: calc(100vw - 36px); height: 520px; max-height: calc(100vh - 110px);
  background: #F7F3EA; border-radius: 16px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
  display: none; flex-direction: column; font-family: inherit; color: #2A2A28;
}
#sh-panel.sh-open { display: flex; }

#sh-head {
  background: #2A5E51; color: #F7F3EA; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
#sh-head .sh-title { font-weight: 700; font-size: 15px; }
#sh-head .sh-sub { font-size: 12px; opacity: .85; }
#sh-head .sh-icons { display: flex; gap: 6px; }
#sh-head button {
  background: transparent; border: 1px solid rgba(247,243,234,.4); color: #F7F3EA;
  border-radius: 8px; padding: 4px 9px; font-size: 12px; cursor: pointer;
}
#sh-head button:hover { background: rgba(255,255,255,.12); }

#sh-online {
  background: #e9e2d2; font-size: 12px; padding: 6px 14px; display: none;
  max-height: 90px; overflow-y: auto;
}
#sh-online.sh-open { display: block; }
#sh-online span {
  display: inline-block; background: #fff; border-radius: 999px;
  padding: 2px 10px; margin: 2px 4px 2px 0; border: 1px solid #d8cfb8;
}

#sh-msgs { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.sh-msg { max-width: 88%; }
.sh-msg .sh-meta { font-size: 11px; color: #6b6252; margin-bottom: 2px; }
.sh-msg .sh-exam {
  background: #2A5E51; color: #F7F3EA; border-radius: 4px; padding: 0 5px;
  font-size: 10px; margin-left: 5px;
}
.sh-msg .sh-bubble {
  background: #fff; border: 1px solid #e0d8c2; border-radius: 12px;
  padding: 8px 11px; font-size: 14px; line-height: 1.45; word-wrap: break-word;
  position: relative;
}
.sh-msg.sh-mine { align-self: flex-end; }
.sh-msg.sh-mine .sh-bubble { background: #2A5E51; color: #F7F3EA; border-color: #2A5E51; }
.sh-msg.sh-mine .sh-meta { text-align: right; }
.sh-report {
  position: absolute; top: 2px; right: 6px; background: none; border: none;
  font-size: 11px; color: #a39a86; cursor: pointer; opacity: 0; padding: 2px 4px;
}
.sh-msg:hover .sh-report { opacity: 1; }
.sh-report:hover { color: #b0482f; }
.sh-time { font-size: 10px; color: #a39a86; margin-left: 6px; }

#sh-inputbar { border-top: 1px solid #e0d8c2; padding: 10px 12px; background: #F7F3EA; }
#sh-inputbar select {
  width: 100%; margin-bottom: 8px; padding: 7px 9px; border-radius: 8px;
  border: 1px solid #d8cfb8; background: #fff; font-size: 13px; font-family: inherit;
}
#sh-inputrow { display: flex; gap: 8px; }
#sh-text {
  flex: 1; border: 1px solid #d8cfb8; border-radius: 10px; padding: 9px 11px;
  font-size: 14px; font-family: inherit; resize: none; max-height: 90px;
}
#sh-send {
  background: #CD7346; color: #fff; border: none; border-radius: 10px;
  padding: 0 16px; font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit;
}
#sh-send:hover { background: #b8623a; }
#sh-send:disabled { opacity: .5; cursor: default; }
#sh-hint { font-size: 11px; color: #8a8172; margin-top: 6px; }

/* Modals */
.sh-modal-back {
  position: fixed; inset: 0; z-index: 2147483002; background: rgba(0,0,0,.5);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.sh-modal-back.sh-open { display: flex; }
.sh-modal {
  background: #F7F3EA; border-radius: 16px; padding: 22px; max-width: 420px; width: 100%;
  max-height: 85vh; overflow-y: auto; color: #2A2A28; font-family: inherit;
}
.sh-modal h3 { margin: 0 0 10px; color: #2A5E51; font-size: 18px; }
.sh-modal p { font-size: 14px; line-height: 1.55; }
.sh-modal ol { font-size: 14px; line-height: 1.6; padding-left: 20px; }
.sh-modal ol li { margin-bottom: 8px; }
.sh-modal input[type=text] {
  width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: 15px;
  border: 1px solid #d8cfb8; border-radius: 10px; font-family: inherit; margin: 6px 0 4px;
}
.sh-modal .sh-err { color: #b0482f; font-size: 13px; min-height: 18px; }
.sh-modal .sh-primary {
  width: 100%; background: #2A5E51; color: #F7F3EA; border: none; border-radius: 10px;
  padding: 12px; font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 10px;
  font-family: inherit;
}
.sh-modal .sh-primary:hover { background: #234e44; }
.sh-modal label.sh-check { display: flex; gap: 8px; font-size: 14px; margin-top: 12px; cursor: pointer; }

@media (max-width: 480px) {
  #sh-panel { right: 0; left: 0; bottom: 0; width: 100%; max-width: 100%;
    height: 78vh; max-height: 78vh; border-radius: 16px 16px 0 0; }
  #sh-fab { right: 14px; bottom: 90px; }
}

.sh-mocktest-button {
  flex: 0 0 auto; background: #2A5E51; color: #F7F3EA; border: none;
  border-radius: 10px; padding: 0 11px; font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.sh-mocktest-button:hover { background: #234e44; }
.sh-mocktest-back {
  position: fixed; inset: 0; z-index: 2147483003; background: rgba(0,0,0,.58);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.sh-mocktest-back.sh-mocktest-open { display: flex; }
.sh-mocktest-modal {
  width: 100%; max-width: 460px; max-height: 85vh; overflow-y: auto;
  box-sizing: border-box; padding: 20px; border-radius: 16px;
  background: #F7F3EA; color: #2A2A28; font-family: inherit;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.sh-mocktest-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sh-mocktest-title { margin: 0; color: #2A5E51; font-size: 18px; }
.sh-mocktest-close {
  flex: 0 0 auto; border: 1px solid #d8cfb8; background: #fff; color: #2A2A28;
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; font-size: 12px;
}
.sh-mocktest-intro { margin: 10px 0 14px; font-size: 14px; line-height: 1.45; }
.sh-mocktest-subjects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sh-mocktest-subject {
  min-height: 44px; padding: 9px 11px; border: 1px solid #d8cfb8; border-radius: 10px;
  background: #fff; color: #2A5E51; text-align: left; font: inherit;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.sh-mocktest-subject:hover, .sh-mocktest-subject:focus-visible {
  border-color: #2A5E51; background: #e9f0ec; outline: none;
}
.sh-mocktest-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 8px; padding: 10px 12px; border: 1px solid #2A5E51;
  border-radius: 10px; background: #edf3ef; color: #234e44;
  font-size: 13px; font-weight: 700; text-decoration: none;
}
.sh-mocktest-card:hover { background: #dfeae3; text-decoration: underline; }
.sh-mocktest-card-label { min-width: 0; }
.sh-mocktest-card-arrow { flex: 0 0 auto; font-size: 18px; }
@media (max-width: 480px) {
  .sh-mocktest-button { padding: 0 8px; font-size: 11px; }
  .sh-mocktest-modal { padding: 16px; }
  .sh-mocktest-subjects { grid-template-columns: 1fr; }
}

.dark #sh-panel,
.dark .sh-modal,
.dark .sh-mocktest-modal {
  background: hsl(var(--card));
  color: hsl(var(--foreground));
}

.dark #sh-online {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.dark #sh-online span,
.dark #sh-inputbar select,
.dark #sh-text,
.dark .sh-modal input,
.dark .sh-mocktest-close,
.dark .sh-mocktest-subject {
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}

.dark .sh-msg:not(.sh-mine) .sh-bubble {
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}

.dark .sh-msg .sh-meta,
.dark .sh-time,
.dark .sh-report,
.dark #sh-hint {
  color: hsl(var(--muted-foreground));
}

.dark .sh-modal h3,
.dark .sh-mocktest-title {
  color: hsl(var(--primary));
}

.dark .sh-modal .sh-err {
  color: hsl(var(--destructive));
}

.dark .sh-mocktest-subject:hover,
.dark .sh-mocktest-subject:focus-visible {
  background: hsl(var(--secondary));
  border-color: hsl(var(--primary));
}

.dark .sh-mocktest-card {
  background: hsl(var(--secondary));
  border-color: hsl(var(--primary));
  color: hsl(var(--foreground));
}

.dark .sh-mocktest-card:hover {
  background: hsl(var(--muted));
}

/* Study Hall nudge feature — append to study-hall.css.
   Brand palette: dark teal #2A5E51, cream #F7F3EA, terracotta #CD7346. */

/* ---------- nudge buttons in the Online panel ---------- */
#sh-online .sh-user {
  display: inline-flex; align-items: center; gap: 4px;
}
.sh-nudge-btn {
  background: #2A5E51; color: #F7F3EA; border: none; border-radius: 999px;
  padding: 2px 10px; font-size: 11px; font-weight: 600; cursor: pointer;
  font-family: inherit; line-height: 1.6;
}
.sh-nudge-btn:hover:not(:disabled) { background: #234e44; }
.sh-nudge-btn:disabled { opacity: .55; cursor: default; }
.sh-nudge-hint {
  font-size: 11px; color: #8a8172; margin-top: 6px;
}

/* ---------- toasts ---------- */
#sh-toast-wrap {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  z-index: 2147483003; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none;
}
.sh-toast {
  background: #2A2A28; color: #F7F3EA; border-radius: 999px;
  padding: 10px 20px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
  max-width: 90vw; text-align: center;
}
.sh-toast-out { opacity: 0; transition: opacity .4s ease; }

/* ---------- animations: mild and simple ---------- */

/* Incoming inline nudge — gentle rise with a soft bounce */
@keyframes sh-nudge-in {
  0%   { transform: translateY(24px) scale(.96); opacity: 0; }
  60%  { transform: translateY(-4px) scale(1.01); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* 2. Nudge-back received — soft warm pulse */
@keyframes sh-nudge-back {
  0%   { transform: scale(.94); box-shadow: 0 0 0 0 rgba(205,115,70,.5); }
  70%  { transform: scale(1.02); box-shadow: 0 0 0 10px rgba(205,115,70,0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(205,115,70,0); }
}
.sh-anim-nudge-back { animation: sh-nudge-back .8s ease-out; }

/* 3. Decline received — gentle fade and settle */
@keyframes sh-nudge-decline {
  0%   { transform: translateY(-8px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
.sh-anim-nudge-decline { animation: sh-nudge-decline .5s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .sh-anim-nudge-back, .sh-anim-nudge-decline { animation: none; }
}

/* ---------- nudge in-chat message ---------- */
.sh-nudge-msg {
  margin: 8px 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(205, 115, 70, 0.1);
  border: 1px solid rgba(205, 115, 70, 0.32);
  animation: sh-nudge-in 0.32s ease-out;
}
.sh-nudge-msg-text { font-size: 15px; line-height: 1.4; margin-bottom: 10px; }
.sh-nudge-msg-actions { display: flex; gap: 10px; }
.sh-nudge-msg-actions .sh-nudge-accept,
.sh-nudge-msg-actions .sh-nudge-decline {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.sh-nudge-msg-actions .sh-nudge-accept {
  background: #2A5E51;
  color: #F7F3EA;
  border: 1px solid #2A5E51;
}
.sh-nudge-msg-actions .sh-nudge-decline {
  background: transparent;
  color: #2A5E51;
  border: 1px solid #2A5E51;
}
.sh-nudge-msg-actions .sh-nudge-accept:hover,
.sh-nudge-msg-actions .sh-nudge-decline:hover { filter: brightness(0.94); }
.sh-nudge-msg-actions .sh-nudge-accept:active,
.sh-nudge-msg-actions .sh-nudge-decline:active {
  transform: scale(0.96);
  filter: brightness(0.9);
}
.sh-nudge-msg-actions .sh-nudge-accept:focus-visible,
.sh-nudge-msg-actions .sh-nudge-decline:focus-visible,
.sh-dir-tappable:focus-visible {
  outline: 2px solid #CD7346;
  outline-offset: 2px;
}
.sh-nudge-result { font-size: 14px; opacity: 0.75; font-style: italic; }

/* ---------- public/private destination control and inline private messages ---------- */
.sh-dir-tappable {
  color: #1d4ed8; font-weight: 700; text-decoration: underline; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.12s ease, filter 0.12s ease;
  animation: sh-dir-pulse 2s ease-in-out infinite;
}
.sh-dir-tappable:active { transform: scale(0.96); filter: brightness(0.9); }
@keyframes sh-dir-pulse {
  0%, 100% { text-shadow: 0 0 6px rgba(37, 99, 235, 0.4); }
  50% { text-shadow: 0 0 18px rgba(37, 99, 235, 0.9); }
}
.sh-msg.sh-private {
  border-left: 3px solid #8b5cf6;
  background: rgba(139, 92, 246, 0.06);
}
.sh-msg.sh-private .sh-bubble { background: rgba(139, 92, 246, 0.1); }

/* ---------- dark mode ---------- */
.dark .sh-nudge-msg {
  background: hsl(var(--secondary));
  border-color: hsl(var(--border));
  color: hsl(var(--foreground));
}
.dark .sh-nudge-msg-actions .sh-nudge-decline {
  background: transparent;
  border-color: hsl(var(--border));
  color: hsl(var(--foreground));
}
.dark .sh-nudge-result { color: hsl(var(--muted-foreground)); }
.dark .sh-dir-tappable { color: #60a5fa; animation: sh-dir-pulse-dark 2s ease-in-out infinite; }
@keyframes sh-dir-pulse-dark {
  0%, 100% { text-shadow: 0 0 6px rgba(96, 165, 250, 0.4); }
  50% { text-shadow: 0 0 18px rgba(96, 165, 250, 0.9); }
}
.dark .sh-msg.sh-private {
  border-left-color: #c4b5fd;
  background: rgba(139, 92, 246, 0.14);
}
.dark .sh-msg.sh-private .sh-bubble {
  background: rgba(139, 92, 246, 0.22);
  color: hsl(var(--foreground));
}

@media (prefers-reduced-motion: reduce) {
  .sh-nudge-msg,
  .sh-nudge-msg-actions .sh-nudge-accept,
  .sh-nudge-msg-actions .sh-nudge-decline,
  .sh-dir-tappable { animation: none; transition: none; }
}

/* Ambient gold finish — shadow-only pulses preserve contrast in light and dark mode. */
#sh-panel {
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3), inset 0 0 0 1px rgba(212, 175, 55, .25);
}

#sh-fab {
  overflow: hidden;
  isolation: isolate;
  --sh-gold-pulse-low: .30;
  --sh-gold-pulse-high: .65;
  animation: sh-gold-pulse 3s ease-in-out infinite;
}

#sh-head {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

#sh-fab::after,
#sh-head::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 215, 130, .28) 48%, rgba(255, 255, 255, .35) 52%, transparent 70%);
  background-size: 250% 100%;
  background-position: 120% 0;
  animation: sh-sheen 5.5s linear infinite;
  pointer-events: none;
}

#sh-panel:has(#sh-online.sh-open) #sh-online-btn,
#sh-send,
.sh-msg.sh-mine .sh-bubble {
  --sh-gold-pulse-low: .15;
  --sh-gold-pulse-high: .45;
  animation: sh-gold-pulse 3s ease-in-out infinite;
}

@keyframes sh-gold-pulse {
  0%, 100% { box-shadow: 0 0 12px rgba(212, 175, 55, var(--sh-gold-pulse-low, .30)); }
  50% { box-shadow: 0 0 22px rgba(212, 175, 55, var(--sh-gold-pulse-high, .65)); }
}

@keyframes sh-sheen {
  from { background-position: 120% 0; }
  to { background-position: -20% 0; }
}

@media (prefers-reduced-motion: reduce) {
  #sh-fab,
  #sh-fab::after,
  #sh-head::after,
  #sh-panel:has(#sh-online.sh-open) #sh-online-btn,
  #sh-send,
  .sh-msg.sh-mine .sh-bubble {
    animation: none;
  }
}
