:root {
  --hit-maroon:      #7D1A1A;
  --hit-maroon-dark: #5C1111;
  --hit-maroon-light:#9E2020;
  --hit-green:       #1A4731;
  --hit-green-dark:  #123321;
  --white:           #FFFFFF;
  --bg-light:        #F6F6F6;
  --bg-bot-msg:      #EFEFEF;
  --text-dark:       #1C1C1C;
  --text-muted:      #666666;
  --border-color:    #DDDDDD;
 
  --widget-w:        380px;
  --widget-h:        560px;
}

#hit-chat-toggle {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--hit-maroon);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(125,26,26,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform 0.2s ease, background 0.2s ease;
  outline: none;
}
#hit-chat-toggle:hover {
  background: var(--hit-maroon-light);
  transform: scale(1.08);
}
#hit-chat-toggle svg {
  width: 28px;
  height: 28px;
  fill: var(--white);
  transition: opacity 0.2s ease;
}
#hit-chat-toggle .icon-close { display: none; }

/* notification badge */
#hit-chat-toggle .badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: #E53935;
  border: 2px solid var(--white);
  border-radius: 50%;
  display: none;
}
#hit-chat-toggle.has-unread .badge { display: block; }

/* â”€â”€ Chat window â”€â”€ */
#hit-chat-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: var(--widget-w);
  height: var(--widget-h);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 9999;
  overflow: hidden;

  opacity: 0;
  transform: translateY(20px) scale(0.97);
  pointer-events: none;

  transition: 
    opacity 0.25s ease, 
    transform 0.25s ease,
    pointer-events 0s linear 0.25s; /* 👈 delay */
}

#hit-chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;

  transition: 
    opacity 0.25s ease, 
    transform 0.25s ease,
    pointer-events 0s; /* 👈 no delay */
}

/* â”€â”€ Header â”€â”€ */
.chat-header {
  background: linear-gradient(135deg, var(--hit-maroon) 0%, var(--hit-maroon-dark) 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.chat-header-avatar img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}
.chat-header-avatar .avatar-fallback {
  font-size: 18px;
  font-weight: 700;
  color: var(--hit-maroon);
  font-family: sans-serif;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--white);
  font-family: 'Segoe UI', Arial, sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-info p {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: rgba(255,255,255,0.78);
  font-family: 'Segoe UI', Arial, sans-serif;
  display: flex;
  align-items: center;
  gap: 5px;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4CAF50;
  display: inline-block;
  flex-shrink: 0;
}
.chat-header-actions { display: flex; gap: 6px; }
.chat-header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-header-btn:hover { background: rgba(255,255,255,0.28); }
.chat-header-btn svg { fill: var(--white); width: 16px; height: 16px; }

/* â”€â”€ Welcome banner â”€â”€ */
.chat-welcome {
  background: var(--hit-green);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-welcome p {
  margin: 0;
  font-size: 12.5px;
  color: rgba(255,255,255,0.9);
  font-family: 'Segoe UI', Arial, sans-serif;
  line-height: 1.4;
}
.chat-welcome svg { flex-shrink: 0; fill: rgba(255,255,255,0.8); width: 16px; height: 16px; }

/* â”€â”€ Messages area â”€â”€ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-light);
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #CCCCCC; border-radius: 4px; }

/* message row */
.msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.msg-row.user { flex-direction: row-reverse; }

/* avatar */
.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  font-family: 'Segoe UI', Arial, sans-serif;
}
.msg-row.bot .msg-avatar  { background: var(--hit-maroon); color: var(--white); }
.msg-row.user .msg-avatar { background: var(--hit-green);  color: var(--white); }

/* bubble */
.msg-bubble {
  max-width: 78%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  font-family: 'Segoe UI', Arial, sans-serif;
  word-wrap: break-word;
}
.msg-row.bot  .msg-bubble {
  background: var(--white);
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
}
.msg-row.user .msg-bubble {
  background: var(--hit-maroon);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.msg-bubble .msg-text { margin: 0; }
.msg-bubble .msg-time {
  font-size: 10px;
  margin-top: 4px;
  opacity: 0.6;
  text-align: right;
}

/* sources accordion */
.msg-sources {
  margin-top: 8px;
  border-top: 1px solid rgba(0,0,0,0.08);
  padding-top: 6px;
}
.sources-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 11.5px;
  color: var(--hit-maroon);
  font-family: 'Segoe UI', Arial, sans-serif;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}
.sources-toggle svg { width: 12px; height: 12px; fill: var(--hit-maroon); transition: transform 0.2s; }
.sources-toggle.open svg { transform: rotate(180deg); }

.sources-list {
  display: none;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sources-list.hidden { display: none; }

.source-chip {
  font-size: 11px;
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--text-muted);
  font-family: 'Segoe UI', Arial, sans-serif;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.source-chip .sc-category {
  background: var(--hit-green);
  color: var(--white);
  font-size: 9.5px;
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.source-chip .sc-score {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* â”€â”€ Typing indicator â”€â”€ */
.typing-indicator {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.typing-bubble {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hit-maroon);
  opacity: 0.4;
  animation: typingDot 1.2s infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}

/* â”€â”€ Quick suggestion chips â”€â”€ */
.quick-chips {
  padding: 0 14px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--bg-light);
  flex-shrink: 0;
}
.quick-chip {
  background: var(--white);
  border: 1px solid var(--hit-maroon);
  color: var(--hit-maroon);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 11.5px;
  font-family: 'Segoe UI', Arial, sans-serif;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.quick-chip:hover {
  background: var(--hit-maroon);
  color: var(--white);
}

/* â”€â”€ Input area â”€â”€ */
.chat-input-area {
  padding: 12px 14px;
  background: var(--white);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.chat-input-wrap {
  flex: 1;
  background: var(--bg-light);
  border: 1.5px solid var(--border-color);
  border-radius: 22px;
  display: flex;
  align-items: flex-end;
  padding: 6px 14px;
  transition: border-color 0.2s;
}
.chat-input-wrap:focus-within { border-color: var(--hit-maroon); }
#hit-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 13.5px;
  font-family: 'Segoe UI', Arial, sans-serif;
  color: var(--text-dark);
  max-height: 90px;
  line-height: 1.5;
  padding: 0;
}
#hit-chat-input::placeholder { color: #AAAAAA; }
#hit-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--hit-maroon);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
#hit-chat-send:hover { background: var(--hit-maroon-light); }
#hit-chat-send:active { transform: scale(0.93); }
#hit-chat-send:disabled { background: #CCCCCC; cursor: not-allowed; }
#hit-chat-send svg { fill: var(--white); width: 18px; height: 18px; }

/* â”€â”€ Footer branding â”€â”€ */
.chat-footer {
  text-align: center;
  padding: 6px 0 8px;
  font-size: 10.5px;
  color: var(--text-muted);
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--white);
  flex-shrink: 0;
}
.chat-footer a {
  color: var(--hit-green);
  text-decoration: none;
  font-weight: 600;
}

/* â”€â”€ Registration form panel â”€â”€ */
.chat-reg-panel {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 12px;
  background: var(--bg-light);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-reg-panel::-webkit-scrollbar { width: 4px; }
.chat-reg-panel::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

.reg-intro p {
  font-size: 13px;
  color: var(--text-muted);
  font-family: 'Segoe UI', Arial, sans-serif;
  margin: 0 0 14px 0;
  line-height: 1.5;
}

#hit-reg-form {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.reg-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.reg-field label {
  font-size: 12px;
  font-weight: 600;
  font-family: 'Segoe UI', Arial, sans-serif;
  color: var(--text-dark);
}
.reg-req { color: #C62828; }
.reg-opt { color: var(--text-muted); font-weight: 400; font-size: 11px; }

.reg-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  font-size: 13px;
  font-family: 'Segoe UI', Arial, sans-serif;
  color: var(--text-dark);
  background: var(--white);
  outline: none;
  transition: border-color 0.18s;
  box-sizing: border-box;
}
.reg-field input:focus { border-color: var(--hit-maroon); }
.reg-field input::placeholder { color: #AAAAAA; }

.reg-error {
  font-size: 12px;
  color: #C62828;
  font-family: 'Segoe UI', Arial, sans-serif;
  min-height: 16px;
  margin: 0;
}

.reg-submit {
  width: 100%;
  padding: 11px;
  background: var(--hit-maroon);
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  font-family: 'Segoe UI', Arial, sans-serif;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.15s, transform 0.1s;
}
.reg-submit:hover   { background: var(--hit-maroon-light); }
.reg-submit:active  { transform: scale(0.98); }
.reg-submit:disabled { background: #AAAAAA; cursor: not-allowed; }

/* â”€â”€ Edit button on user messages â”€â”€ */
.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 5px;
}
.msg-edit-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 12px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 10.5px;
  font-family: 'Segoe UI', Arial, sans-serif;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  transition: background 0.15s;
  white-space: nowrap;
}
.msg-edit-btn:hover { background: rgba(255,255,255,0.30); }
.msg-edit-btn svg { fill: rgba(255,255,255,0.9); width: 10px; height: 10px; }

/* â”€â”€ Inline edit mode â”€â”€ */
.msg-bubble.edit-active {
  /* width is set inline via JS â€” this ensures it never shrinks below original */
  min-width: 200px;
}
.msg-edit-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
.msg-edit-textarea {
  width: 100%;
  min-height: 64px;
  max-height: 140px;
  background: rgba(255,255,255,0.15);
  border: 1.5px solid rgba(255,255,255,0.5);
  border-radius: 8px;
  color: var(--white);
  font-size: 13px;
  font-family: 'Segoe UI', Arial, sans-serif;
  padding: 8px 10px;
  resize: none;
  outline: none;
  line-height: 1.55;
  box-sizing: border-box;
}
.msg-edit-textarea::placeholder { color: rgba(255,255,255,0.55); }
.msg-edit-textarea:focus { border-color: rgba(255,255,255,0.85); }

.msg-edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.msg-edit-hint {
  flex: 1;
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  font-family: 'Segoe UI', Arial, sans-serif;
  font-style: italic;
}
.msg-edit-cancel {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-family: 'Segoe UI', Arial, sans-serif;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.9);
  transition: background 0.15s;
}
.msg-edit-cancel:hover { background: rgba(255,255,255,0.28); }
.msg-edit-cancel svg { width: 11px; height: 11px; fill: currentColor; }

/* â”€â”€ Markdown styles inside bot bubble â”€â”€ */
.msg-bubble .md-p {
  margin: 0 0 6px 0;
  line-height: 1.6;
}
.msg-bubble .md-p:last-child { margin-bottom: 0; }

.msg-bubble .md-ul,
.msg-bubble .md-ol {
  margin: 4px 0 6px 0;
  padding-left: 18px;
  line-height: 1.65;
}
.msg-bubble .md-ul { list-style: disc; }
.msg-bubble .md-ol { list-style: decimal; }
.msg-bubble .md-ul li,
.msg-bubble .md-ol li {
  margin-bottom: 3px;
  font-size: 13.5px;
}

.msg-bubble .md-h {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--hit-maroon);
  margin: 8px 0 4px 0;
  padding-bottom: 3px;
  border-bottom: 1.5px solid rgba(125,26,26,0.15);
}

.msg-bubble .md-code {
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  color: #333;
}

.msg-bubble strong { font-weight: 700; }
.msg-bubble em     { font-style: italic; }

/* sc-question helper */
.sc-question {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* â”€â”€ Error message â”€â”€ */
.msg-error {
  font-size: 12px;
  color: #C62828;
  background: #FFEBEE;
  border: 1px solid #FFCDD2;
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 4px;
}

/* â”€â”€ Responsive â”€â”€ */
@media (max-width: 420px) {
  #hit-chat-window {
    width: calc(100vw - 20px);
    height: calc(100vh - 120px);
    right: 10px;
    bottom: 90px;
  }
  :root { --widget-w: calc(100vw - 20px); }
}