/* ================================================================
   CCS AI Chat Agent — Stylesheet
   File:    assets/css/chatbot.css
   Version: 2.0
   ================================================================ */

:root {
  --chat-z:           9999;
  --chat-width:       400px;
  --chat-height:      600px;
  --chat-radius:      20px;
  --chat-bg:          #07090f;
  --chat-surface:     #0e1117;
  --chat-surface-3:   #1a2130;
  --chat-orange:      #f97316;
  --chat-orange-dim:  rgba(249,115,22,0.10);
  --chat-border:      rgba(255,255,255,0.07);
  --chat-border-hot:  rgba(249,115,22,0.35);
  --chat-text:        #e8eaf0;
  --chat-text-2:      #a8b0bf;
  --chat-muted:       #56637a;
  --chat-bot-bg:      #0e1520;
  --chat-shadow: 0 32px 96px rgba(0,0,0,0.75), 0 0 0 1px rgba(249,115,22,0.10), 0 0 80px rgba(249,115,22,0.03);
  --chat-ease:        cubic-bezier(0.34,1.56,0.64,1);
  --chat-ease-out:    cubic-bezier(0.22,1,0.36,1);
}

/* ── FAB ─────────────────────────────────────────────────────── */
.ccs-chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: var(--chat-z);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fb923c 0%, #ea580c 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(249,115,22,0.40), 0 2px 6px rgba(0,0,0,0.5);
  transition: transform 0.28s var(--chat-ease), box-shadow 0.28s ease;
  outline: none;
  overflow: visible;
}

/* Pulsing ring */
.ccs-chat-fab::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(249,115,22,0.30);
  animation: fab-ring 2.8s ease-in-out infinite;
  pointer-events: none;
}

@keyframes fab-ring {
  0%,100% { transform: scale(1);    opacity: 0.7; }
  50%      { transform: scale(1.12); opacity: 0;   }
}

.ccs-chat-fab.is-open::before { animation: none; opacity: 0; }

.ccs-chat-fab:hover {
  transform: scale(1.04);
  box-shadow: 0 8px 22px rgba(249,115,22,0.46), 0 2px 8px rgba(0,0,0,0.38);
}

.ccs-chat-fab:active { transform: scale(0.93); }

.ccs-chat-fab .fab-icon-chat,
.ccs-chat-fab .fab-icon-close {
  position: absolute;
  color: #fff;
  transition: opacity 0.2s ease, transform 0.25s var(--chat-ease);
}

.ccs-chat-fab .fab-icon-close           { opacity: 0; transform: rotate(-90deg) scale(0.6); }
.ccs-chat-fab.is-open .fab-icon-chat    { opacity: 0; transform: rotate(90deg)  scale(0.6); }
.ccs-chat-fab.is-open .fab-icon-close   { opacity: 1; transform: rotate(0deg)   scale(1);   }

/* Badge */
.ccs-chat-fab .chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: #ef4444;
  border: 2px solid var(--chat-bg);
  font-size: 9px;
  font-weight: 700;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Window ──────────────────────────────────────────────────── */
.ccs-chat-window {
  position: fixed;
  bottom: 96px;
  right: 18px;
  z-index: var(--chat-z);
  width: var(--chat-width);
  height: var(--chat-height);
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 108px);
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(20px) scale(0.94);
  pointer-events: none;
  transition: opacity 0.3s var(--chat-ease-out), transform 0.38s var(--chat-ease);
}

.ccs-chat-window.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Expand animation — morphs window to fullscreen before navigating */
.ccs-chat-window.is-expanding {
  transition: all 0.36s cubic-bezier(0.4, 0, 0.2, 1) !important;
  border-radius: 0 !important;
  width:  100vw   !important;
  height: 100vh   !important;
  bottom: 0       !important;
  right:  0       !important;
  opacity: 0.6    !important;
  transform: scale(1.03) !important;
  z-index: 99999  !important;
}

/* Top accent line */
.ccs-chat-window::before {
  content: '';
  position: absolute;
  top: 0; left: 8%; right: 8%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(249,115,22,0.55), transparent);
  pointer-events: none;
  z-index: 1;
}

/* ── Header ──────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px 14px;
  background: linear-gradient(180deg, rgba(249,115,22,0.07) 0%, transparent 100%);
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
  position: relative;
}

.chat-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 4px 16px rgba(249,115,22,0.32);
}

.chat-header-avatar svg { width: 20px; height: 20px; color: #fff; }

.chat-header-avatar::after {
  content: '';
  position: absolute;
  bottom: 1px; right: 1px;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--chat-bg);
  animation: online-pulse 2.5s ease-in-out infinite;
}

@keyframes online-pulse {
  0%,100% { box-shadow: 0 0 0 0   rgba(34,197,94,0.4); }
  60%      { box-shadow: 0 0 0 5px rgba(34,197,94,0);   }
}

.chat-header-info { flex: 1; min-width: 0; }

.chat-header-info .chat-name {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--chat-text);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.chat-header-info .chat-status {
  font-size: 11.5px;
  color: var(--chat-text-2);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-header-info .chat-status::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

.chat-header-actions { display: flex; gap: 5px; }

.chat-action-btn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: transparent;
  border: 1px solid var(--chat-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chat-action-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--chat-text-2);
  border-color: rgba(255,255,255,0.12);
}

/* ── Messages ────────────────────────────────────────────────── */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chat-body::-webkit-scrollbar { width: 3px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb { background: rgba(249,115,22,0.25); border-radius: 99px; }
.chat-body::-webkit-scrollbar-thumb:hover { background: rgba(249,115,22,0.45); }

/* ── Message Bubbles ──────────────────────────────────────────── */
.chat-message {
  display: flex;
  gap: 9px;
  animation: msg-in 0.26s var(--chat-ease-out) both;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0);    }
}

.chat-message.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  align-self: flex-end;
  margin-bottom: 2px;
}

.chat-message.bot  .msg-avatar {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  color: #fff;
  box-shadow: 0 3px 10px rgba(249,115,22,0.28);
}

.chat-message.user .msg-avatar {
  background: #141920;
  color: var(--chat-muted);
  border: 1px solid var(--chat-border);
}

.msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: calc(100% - 88px);
}

.chat-message.user .msg-content { align-items: flex-end; }

.msg-bubble {
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.65;
  word-break: break-word;
}

.chat-message.bot .msg-bubble {
  background: var(--chat-bot-bg);
  color: var(--chat-text);
  border-radius: 4px 16px 16px 16px;
  border: 1px solid var(--chat-border);
}

.chat-message.user .msg-bubble {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  color: #fff;
  border-radius: 16px 4px 16px 16px;
  box-shadow: 0 4px 16px rgba(249,115,22,0.20);
}

.msg-time {
  font-size: 10.5px;
  color: var(--chat-muted);
  padding: 0 4px;
}

/* Markdown */
.msg-bubble p             { margin: 0 0 7px; }
.msg-bubble p:last-child  { margin-bottom: 0; }
.msg-bubble strong        { font-weight: 700; color: #fdba74; }
.chat-message.user .msg-bubble strong { color: #ffe8d6; }
.msg-bubble em            { opacity: 0.9; font-style: italic; }
.msg-bubble code {
  background: rgba(249,115,22,0.13);
  color: #fdba74;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  font-size: 12.5px;
}
.chat-message.user .msg-bubble code { background: rgba(0,0,0,0.2); color: #ffe0c2; }
.msg-bubble ul, .msg-bubble ol { padding-left: 18px; margin: 6px 0; }
.msg-bubble li  { margin: 4px 0; }
.msg-bubble a   { color: #fdba74; text-decoration: underline; }
.msg-bubble h1 {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  color: #f97316;
  font-size: 15.5px;
  font-weight: 700;
  margin: 12px 0 5px;
  padding-bottom: 4px;
  border-bottom: 2px solid rgba(249,115,22,0.35);
}
.msg-bubble h2 {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  color: #f97316;
  font-size: 14.5px;
  font-weight: 700;
  margin: 12px 0 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(249,115,22,0.25);
}
.msg-bubble h3, .msg-bubble h4 {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  color: #fdba74;
  font-size: 13px;
  font-weight: 700;
  margin: 10px 0 5px;
}
.msg-bubble pre {
  background: rgba(0,0,0,0.30);
  border: 1px solid rgba(249,115,22,0.20);
  border-radius: 8px;
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
  line-height: 1.6;
}
.msg-bubble pre code {
  background: none;
  padding: 0;
  color: #e2e8f0;
  font-size: 12px;
}
.msg-bubble blockquote {
  border-left: 3px solid #f97316;
  margin: 8px 0;
  padding: 5px 12px;
  background: rgba(249,115,22,0.07);
  border-radius: 0 6px 6px 0;
  color: #cbd5e1;
  font-style: italic;
}
.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12.5px;
}
.msg-bubble th {
  background: rgba(249,115,22,0.15);
  color: #fdba74;
  font-weight: 700;
  text-align: left;
  padding: 6px 10px;
  border: 1px solid rgba(249,115,22,0.25);
}
.msg-bubble td {
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--chat-text);
}
.msg-bubble tr:nth-child(even) td { background: rgba(255,255,255,0.03); }
.msg-bubble hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.10);
  margin: 10px 0;
}

/* ── Typing Indicator ─────────────────────────────────────────── */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--chat-bot-bg);
  border-radius: 4px 16px 16px 16px;
  border: 1px solid var(--chat-border);
  width: fit-content;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-muted);
  display: block;
  animation: dot-bounce 1.4s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.18s; }
.chat-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1;   }
}

/* ── Suggestions ─────────────────────────────────────────────── */
.chat-suggestions {
  display: flex;
  flex-wrap: nowrap;
  gap: 7px;
  padding: 4px 14px 12px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chat-suggestions::-webkit-scrollbar { display: none; }

.chat-suggestion-btn {
  padding: 7px 14px;
  border-radius: 20px;
  background: transparent;
  border: 1px solid rgba(249,115,22,0.28);
  color: var(--chat-orange);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.18s;
  line-height: 1.3;
}

.chat-suggestion-btn:hover {
  background: rgba(249,115,22,0.10);
  border-color: var(--chat-orange);
  color: #fff;
  transform: translateY(-1px);
}

.chat-suggestion-btn:active { transform: translateY(0); }

/* ── Footer / Input ──────────────────────────────────────────── */
.chat-footer {
  padding: 11px 14px 14px;
  flex-shrink: 0;
  border-top: 1px solid var(--chat-border);
  background: #0a0d14;
}

.chat-input-row {
  display: flex;
  gap: 9px;
  align-items: flex-end;
}

.chat-input-wrap {
  flex: 1;
  background: var(--chat-bg);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-wrap:focus-within {
  border-color: rgba(249,115,22,0.45);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.07);
}

.chat-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--chat-text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.55;
  padding: 10px 14px;
  max-height: 110px;
  min-height: 40px;
  overflow-y: auto;
  box-sizing: border-box;
}

.chat-textarea::placeholder { color: var(--chat-muted); }
.chat-textarea::-webkit-scrollbar { width: 3px; }
.chat-textarea::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 99px; }

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f97316, #ea580c);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(249,115,22,0.30);
  transition: transform 0.15s var(--chat-ease), box-shadow 0.15s, opacity 0.15s;
}

.chat-send-btn:hover:not(:disabled) {
  transform: scale(1.07);
  box-shadow: 0 6px 20px rgba(249,115,22,0.48);
}

.chat-send-btn:active:not(:disabled) { transform: scale(0.92); }

.chat-send-btn:disabled {
  opacity: 0.32;
  cursor: not-allowed;
  box-shadow: none;
}

/* ── Powered line ─────────────────────────────────────────────── */
.chat-powered {
  text-align: center;
  font-size: 10px;
  color: var(--chat-muted);
  margin-top: 9px;
  opacity: 0.7;
  letter-spacing: 0.02em;
}

.chat-powered span {
  color: var(--chat-orange);
  font-weight: 600;
}

/* ── Error Banner ─────────────────────────────────────────────── */
.chat-error-banner {
  margin: 0 13px 8px;
  padding: 9px 13px;
  background: rgba(239,68,68,0.09);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: 10px;
  font-size: 12.5px;
  color: #fca5a5;
  display: none;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}

.chat-error-banner.visible { display: flex; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 560px) {
  .ccs-chat-window {
    bottom: 0; right: 0;
    width: 100%; height: 100dvh;
    max-width: 100%; max-height: 100dvh;
    border-radius: 0;
  }
  .ccs-chat-fab { bottom: 16px; right: 16px; }
}

/* ── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ccs-chat-window,
  .chat-message,
  .ccs-chat-fab,
  .ccs-chat-fab::before,
  .chat-header-avatar::after,
  .chat-typing span { animation: none; transition: none; }
}
