/* ============================================================
   TOD Chat Widget — diary-themed group chat styles
   ============================================================ */

/* --- Character colors (from diary.css palette) --- */
:root {
  --chat-andrew: #1B3A5C;
  --chat-sanjana: #D4600A;
  --chat-joomal: #5C3D1E;
  --chat-sajid: #2E7D32;
  --chat-system: #888888;
  --chat-visitor: #4A2C0A;
  --chat-bg: #FDF6E3;
  --chat-panel-bg: #FAF3E0;
  --chat-header-bg: #D4600A;
  --chat-border: #E8D5B0;
  --chat-shadow: rgba(44, 36, 22, 0.15);
  --chat-radius: 10px;
}

/* --- Toggle button --- */
#tod-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #D4600A;
  color: #FDF6E3;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--chat-shadow);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
}
#tod-chat-toggle:hover {
  transform: scale(1.08);
  background: #A84E08;
}

/* --- Panel --- */
#tod-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  max-height: 520px;
  background: var(--chat-panel-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: 0 8px 32px var(--chat-shadow);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Source Serif 4', 'Libre Baskerville', Georgia, serif;
  font-size: 14px;
  color: #2C2416;
}

/* --- Header --- */
#tod-chat-header {
  background: var(--chat-header-bg);
  color: #FDF6E3;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#tod-chat-title {
  font-family: 'Caveat', cursive;
  font-size: 20px;
  font-weight: 700;
}
#tod-chat-close {
  background: none;
  border: none;
  color: #FDF6E3;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.8;
}
#tod-chat-close:hover { opacity: 1; }

/* --- Session picker --- */
#tod-chat-picker {
  padding: 12px 16px;
  overflow-y: auto;
  flex: 1;
}
.tod-picker-intro {
  font-style: italic;
  color: #888;
  font-size: 13px;
  margin: 0 0 12px;
  line-height: 1.5;
}
.tod-session-card {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-left: 3px solid #D4600A;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.tod-session-card:hover {
  border-left-color: #A84E08;
  box-shadow: 0 2px 8px var(--chat-shadow);
}
.tod-session-card .tod-sc-title {
  font-weight: 600;
  font-size: 14px;
  color: #2C2416;
  margin-bottom: 4px;
}
.tod-session-card .tod-sc-meta {
  font-size: 11px;
  color: #888;
}
.tod-session-card .tod-sc-meta .tod-mood {
  text-transform: capitalize;
  color: #D4600A;
}

/* --- Messages area --- */
#tod-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  scroll-behavior: smooth;
  background:
    repeating-linear-gradient(
      transparent,
      transparent 30px,
      #E8D5B0 30px,
      #E8D5B0 31px
    );
}

/* --- Message bubble --- */
.tod-msg {
  margin-bottom: 10px;
  animation: todFadeIn 0.3s ease;
  position: relative;
  display: flex;
  flex-direction: column;
}
.tod-msg-name {
  font-family: 'Caveat', cursive;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 2px;
}
.tod-msg-text {
  font-size: 13.5px;
  line-height: 1.55;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.6);
  display: inline-block;
  max-width: 80%;
}
.tod-msg-stage {
  font-style: italic;
  font-size: 11.5px;
  color: #999;
  margin-top: 2px;
}

/* Left-aligned: character messages */
.tod-msg-left {
  align-items: flex-start;
}
.tod-msg-left .tod-msg-text {
  border-radius: 2px 10px 10px 10px;
}

/* Right-aligned: visitor messages */
.tod-msg-right {
  align-items: flex-end;
}
.tod-msg-right .tod-msg-text {
  border-radius: 10px 2px 10px 10px;
  border-left: none !important;
  border-right: 2px solid var(--chat-visitor);
  background: rgba(74, 44, 10, 0.06);
}

/* Center-aligned: system messages */
.tod-msg-center {
  align-items: center;
}

/* Character-specific name colors */
.tod-msg[data-char="andrew"] .tod-msg-name { color: var(--chat-andrew); }
.tod-msg[data-char="sanjana"] .tod-msg-name { color: var(--chat-sanjana); }
.tod-msg[data-char="joomal"] .tod-msg-name { color: var(--chat-joomal); }
.tod-msg[data-char="sajid"] .tod-msg-name { color: var(--chat-sajid); }
.tod-msg[data-char="system"] .tod-msg-name { color: var(--chat-system); }
.tod-msg[data-char="visitor"] .tod-msg-name { color: var(--chat-visitor); }

/* Character-specific left border */
.tod-msg[data-char="andrew"] .tod-msg-text { border-left: 2px solid var(--chat-andrew); }
.tod-msg[data-char="sanjana"] .tod-msg-text { border-left: 2px solid var(--chat-sanjana); }
.tod-msg[data-char="joomal"] .tod-msg-text { border-left: 2px solid var(--chat-joomal); }
.tod-msg[data-char="sajid"] .tod-msg-text { border-left: 2px solid var(--chat-sajid); }
.tod-msg[data-char="system"] .tod-msg-text { border-left: none; background: rgba(0,0,0,0.04); }

/* --- Typing indicator --- */
.tod-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
}
.tod-typing-name {
  font-family: 'Caveat', cursive;
  font-size: 14px;
  color: #999;
}
.tod-typing-dots {
  display: flex;
  gap: 3px;
}
.tod-typing-dots span {
  width: 5px;
  height: 5px;
  background: #C8B898;
  border-radius: 50%;
  animation: todDotPulse 1.2s infinite;
}
.tod-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.tod-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* --- Join banner --- */
#tod-chat-join {
  padding: 10px 16px;
  text-align: center;
  background: rgba(212, 96, 10, 0.06);
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}
#tod-chat-join-btn {
  background: #D4600A;
  color: #FDF6E3;
  border: none;
  padding: 8px 24px;
  border-radius: 20px;
  font-family: 'Caveat', cursive;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s;
}
#tod-chat-join-btn:hover { background: #A84E08; }

/* --- Input area --- */
#tod-chat-input {
  display: flex;
  padding: 8px 12px;
  gap: 8px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-bg);
  flex-shrink: 0;
}
#tod-chat-text {
  flex: 1;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  outline: none;
}
#tod-chat-text:focus { border-color: #D4600A; }
#tod-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #D4600A;
  color: #FDF6E3;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
#tod-chat-send:hover { background: #A84E08; }
#tod-chat-send:disabled { background: #C8B898; cursor: default; }

/* --- Status bar --- */
#tod-chat-status {
  padding: 6px 16px;
  font-size: 11px;
  color: #888;
  text-align: center;
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}

/* --- Recommendations --- */
#tod-chat-recs {
  padding: 8px 16px 12px;
  border-top: 1px solid var(--chat-border);
  background: rgba(212, 96, 10, 0.04);
  flex-shrink: 0;
}
.tod-recs-label {
  font-family: 'Caveat', cursive;
  font-size: 15px;
  color: #D4600A;
  margin-bottom: 6px;
}
.tod-rec-card {
  padding: 6px 10px;
  margin-bottom: 4px;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-left: 2px solid #D4600A;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  transition: box-shadow 0.2s;
}
.tod-rec-card:hover {
  box-shadow: 0 1px 6px var(--chat-shadow);
}
.tod-rec-card .tod-rc-title {
  font-weight: 600;
  color: #2C2416;
}
.tod-rec-card .tod-rc-mood {
  color: #D4600A;
  font-size: 10px;
  text-transform: capitalize;
}

/* --- Share button on messages --- */
.tod-msg-share {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(212, 96, 10, 0.12);
  color: #D4600A;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  align-items: center;
  justify-content: center;
}
.tod-msg:hover .tod-msg-share { display: flex; }
.tod-msg[data-char="system"] .tod-msg-share,
.tod-msg[data-char="visitor"] .tod-msg-share { display: none !important; }

/* --- Quote card overlay --- */
#tod-quote-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 22, 0.6);
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: todFadeIn 0.2s ease;
}
#tod-quote-card {
  width: 340px;
  background: var(--chat-bg);
  border: 2px solid var(--chat-border);
  border-radius: 8px;
  padding: 24px 20px 16px;
  position: relative;
  box-shadow: 0 12px 48px rgba(44, 36, 22, 0.3);
  text-align: center;
  font-family: 'Source Serif 4', 'Libre Baskerville', Georgia, serif;
}
.tod-quote-close {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 20px;
  color: #999;
  cursor: pointer;
  line-height: 1;
}
.tod-quote-close:hover { color: #2C2416; }
.tod-quote-header {
  font-family: 'Caveat', cursive;
  font-size: 22px;
  color: #D4600A;
  margin-bottom: 12px;
}
.tod-quote-char {
  font-family: 'Caveat', cursive;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}
.tod-quote-text {
  font-size: 14px;
  line-height: 1.6;
  color: #2C2416;
  margin: 0 0 12px;
  padding: 12px 16px;
  border-left: 3px solid #D4600A;
  background: rgba(255, 255, 255, 0.5);
  text-align: left;
  font-style: italic;
}
.tod-quote-session {
  font-size: 11px;
  color: #999;
  margin-bottom: 8px;
}
.tod-quote-footer {
  font-size: 10px;
  color: #C8B898;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* --- AI disclaimer --- */
#tod-chat-disclaimer {
  padding: 4px 16px 6px;
  font-size: 9px;
  color: #B8A88A;
  text-align: center;
  line-height: 1.3;
  flex-shrink: 0;
}

/* --- Utility --- */
.tod-hidden { display: none !important; }

/* --- Animations --- */
@keyframes todFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes todDotPulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* --- Responsive --- */
@media (max-width: 480px) {
  #tod-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 85vh;
    border-radius: var(--chat-radius) var(--chat-radius) 0 0;
  }
  #tod-chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
  #tod-quote-card {
    width: 90%;
    max-width: 340px;
  }
}
