/* ===== Chat FAB ===== */
.chat-fab {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #1a1a2e;
  color: #ffd54f;
  border: 2px solid rgba(255,213,79,0.4);
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px rgba(255,213,79,0.3), 0 4px 12px rgba(0,0,0,0.4);
  transition: opacity .2s, box-shadow .3s;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  animation: chat-fab-glow 2s ease-in-out infinite alternate;
}
@keyframes chat-fab-glow {
  from { box-shadow: 0 0 12px rgba(255,213,79,0.2), 0 4px 12px rgba(0,0,0,0.4); }
  to   { box-shadow: 0 0 24px rgba(255,213,79,0.5), 0 4px 12px rgba(0,0,0,0.4); }
}
.chat-fab:hover { box-shadow: 0 0 28px rgba(255,213,79,0.6), 0 4px 12px rgba(0,0,0,0.4); }
.chat-fab.hidden { transform: scale(0); opacity: 0; pointer-events: none; }

/* ===== Chat Panel (floating window) ===== */
.chat-panel {
  position: fixed;
  width: 420px;
  height: 520px;
  z-index: 100000;
  display: none;
  flex-direction: column;
  background: var(--sf);
  border-radius: 16px;
  box-shadow: 0 8px 40px var(--shadow), 0 0 0 1px var(--bdr);
  overflow: hidden;
}
.chat-panel.open { display: flex; }

/* Mobile: fullscreen takeover */
@media (max-width: 480px) {
  .chat-panel {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
    top: 0 !important;
    left: 0 !important;
  }
  .chat-header {
    cursor: default;
    padding: 14px 16px;
  }
  .chat-input-area {
    padding-bottom: 34px;
  }
}

/* Header — draggable handle */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--cd);
  border-bottom: 1px solid var(--bdr);
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
}
.chat-header:active { cursor: grabbing; }
.chat-header-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--wh);
}
.chat-header-sub {
  font-size: 11px;
  color: var(--dim);
  margin-top: 1px;
}
.chat-close {
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  line-height: 0;
}
.chat-close:hover { background: var(--subtle-bg); color: var(--tx); }
@media (max-width: 480px) {
  .chat-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.08);
    border-radius: 50%;
  }
  .chat-close:active { background: rgba(255,255,255,.15); }
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}

.chat-bubble {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--acc);
  color: var(--text-on-color);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.chat-bubble.ai {
  align-self: flex-start;
  background: var(--cd);
  color: var(--tx);
  border-bottom-left-radius: 4px;
  white-space: normal;
}

/* ===== Markdown inside AI bubbles ===== */
.chat-bubble.ai strong { color: var(--wh); font-weight: 600; }
.chat-bubble.ai em { font-style: italic; opacity: .9; }

.chat-bubble.ai ul,
.chat-bubble.ai ol {
  margin: 4px 0;
  padding-left: 18px;
}
.chat-bubble.ai li {
  margin: 2px 0;
}

.chat-code-block {
  background: var(--bg);
  border: 1px solid var(--bdr);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0;
  overflow-x: auto;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
  color: var(--tx);
}

.chat-inline-code {
  background: var(--subtle-bg);
  border: 1px solid var(--bdr);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  color: var(--cyn);
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--cd);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dim);
  animation: chatDot 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatDot {
  0%, 60%, 100% { opacity: .3; transform: scale(.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* Input area */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--bdr);
  background: var(--cd);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--bdr);
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--tx);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 20px;
  max-height: 80px;
}
.chat-input:focus { border-color: var(--acc); }
.chat-input::placeholder { color: var(--dim); }
.chat-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--acc);
  color: var(--text-on-color);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s;
}
.chat-send:disabled { opacity: .4; cursor: default; }

/* ===== Access Code Gate ===== */
.chat-code-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 24px;
  gap: 8px;
}
.chat-code-icon { color: var(--dim); margin-bottom: 4px; }
.chat-code-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--wh);
}
.chat-code-desc {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 8px;
}
.chat-code-form {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 240px;
}
.chat-code-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--bdr);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--tx);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.chat-code-input:focus { border-color: var(--acc); }
.chat-code-btn {
  background: var(--acc);
  color: var(--text-on-color);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chat-code-btn:hover { background: var(--acc-hover); }
.chat-code-error {
  font-size: 12px;
  color: var(--red);
  min-height: 16px;
  margin-top: 4px;
}
