/*
 * chat-widget.css
 * Place at: /assets/css/chat-widget.css
 * Zero conflicts with main.css
 */

/* ═══ CSS VARIABLES (scoped to chat) ═════════════════════════ */
:root {
  --ch-accent:    #FF6B00;
  --ch-accent2:   #7C3AED;
  --ch-bg:        #0d1117;
  --ch-surface:   #161b22;
  --ch-card:      #1c2230;
  --ch-border:    rgba(255,255,255,.09);
  --ch-ink:       #e6edf3;
  --ch-ink50:     rgba(230,237,243,.5);
  --ch-ink30:     rgba(230,237,243,.3);
  --ch-green:     #23c55e;
  --ch-red:       #ef4444;
  --ch-yellow:    #f59e0b;
  --ch-r:         12px;
  --ch-r-lg:      18px;
}

/* ═══ FLOATING WIDGET BUTTON ═════════════════════════════════ */
#ch-widget-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 99990;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ch-accent), #c2410c);
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(255,107,0,.45), 0 2px 8px rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s, box-shadow .25s;
  outline: none;
}
#ch-widget-btn:hover { transform: scale(1.08); box-shadow: 0 12px 40px rgba(255,107,0,.55); }
#ch-widget-btn.open  { background: linear-gradient(135deg, #374151, #1f2937); }
.ch-btn-icon { font-size: 1.5rem; line-height: 1; color: #fff; transition: transform .3s; }
#ch-widget-btn.open .ch-btn-icon { transform: rotate(90deg); }
/* Unread badge */
#ch-unread-badge {
  position: absolute;
  top: -3px; right: -3px;
  min-width: 20px; height: 20px;
  background: var(--ch-red);
  border: 2px solid #fff;
  border-radius: 100px;
  font-size: .65rem;
  font-weight: 800;
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
/* Online pulse ring */
#ch-widget-btn::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--ch-green);
  animation: ch-pulse-ring 2.5s ease-out infinite;
  opacity: 0;
}
@keyframes ch-pulse-ring {
  0%   { opacity: .7; transform: scale(.95); }
  80%  { opacity: 0;  transform: scale(1.25); }
  100% { opacity: 0;  transform: scale(1.25); }
}

/* ═══ CHAT WINDOW ════════════════════════════════════════════ */
#ch-window {
  position: fixed;
  bottom: 104px;
  right: 28px;
  z-index: 99989;
  width: 370px;
  max-height: 600px;
  background: var(--ch-bg);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-r-lg);
  box-shadow: 0 24px 80px rgba(0,0,0,.55), 0 4px 16px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(.92) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform .28s cubic-bezier(.34,1.56,.64,1), opacity .22s ease;
}
#ch-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
.ch-header {
  background: linear-gradient(135deg, #0f0c29, #1a1040, #0a0a1e);
  padding: 1rem 1.1rem .85rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  border-bottom: 1px solid var(--ch-border);
  flex-shrink: 0;
  position: relative;
}
.ch-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,107,0,.12), rgba(124,58,237,.08));
  pointer-events: none;
}
.ch-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ch-accent), #c2410c);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(255,107,0,.35);
  position: relative;
  z-index: 1;
}
.ch-avatar-status {
  position: absolute; bottom: 1px; right: 1px;
  width: 11px; height: 11px;
  background: var(--ch-green);
  border: 2px solid var(--ch-bg);
  border-radius: 50%;
}
.ch-header-info { flex: 1; position: relative; z-index: 1; }
.ch-header-title {
  font-size: .9rem; font-weight: 700;
  color: #fff; letter-spacing: -.01em;
}
.ch-header-sub {
  font-size: .7rem; color: rgba(255,255,255,.5);
  margin-top: .1rem;
  display: flex; align-items: center; gap: .3rem;
}
.ch-online-dot {
  width: 6px; height: 6px;
  background: var(--ch-green);
  border-radius: 50%;
  animation: ch-blink 1.8s ease-in-out infinite;
}
@keyframes ch-blink { 0%,100%{opacity:1} 50%{opacity:.4} }
.ch-header-close {
  background: rgba(255,255,255,.08);
  border: none;
  color: rgba(255,255,255,.6);
  width: 28px; height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
  position: relative; z-index: 1;
  flex-shrink: 0;
}
.ch-header-close:hover { background: rgba(255,255,255,.15); color: #fff; }

/* Security badge */
.ch-security-bar {
  background: rgba(35,197,94,.07);
  border-bottom: 1px solid rgba(35,197,94,.12);
  padding: .28rem 1.1rem;
  font-size: .63rem;
  color: var(--ch-green);
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 0;
}

/* ── SCREENS ─────────────────────────────────────────────────── */
.ch-screen { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.ch-screen.active { display: flex; }

/* Start screen */
.ch-start { padding: 1.25rem 1.1rem; overflow-y: auto; }
.ch-start-intro {
  text-align: center;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--ch-border);
}
.ch-start-intro h3 {
  font-size: 1rem; font-weight: 800;
  color: var(--ch-ink); margin-bottom: .3rem;
}
.ch-start-intro p { font-size: .78rem; color: var(--ch-ink50); line-height: 1.55; }
.ch-form-group { margin-bottom: .75rem; }
.ch-form-label {
  display: block; font-size: .72rem;
  font-weight: 600; color: var(--ch-ink50);
  margin-bottom: .3rem; letter-spacing: .03em;
}
.ch-form-input {
  width: 100%;
  padding: .55rem .75rem;
  background: var(--ch-surface);
  border: 1px solid var(--ch-border);
  border-radius: 8px;
  color: var(--ch-ink);
  font-size: .84rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  box-sizing: border-box;
}
.ch-form-input:focus {
  border-color: var(--ch-accent);
  box-shadow: 0 0 0 3px rgba(255,107,0,.14);
}
.ch-form-input::placeholder { color: var(--ch-ink30); }
.ch-form-select {
  width: 100%;
  padding: .55rem .75rem;
  background: var(--ch-surface);
  border: 1px solid var(--ch-border);
  border-radius: 8px;
  color: var(--ch-ink);
  font-size: .84rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  box-sizing: border-box;
}
.ch-start-btn {
  width: 100%;
  padding: .7rem;
  background: linear-gradient(135deg, var(--ch-accent), #c2410c);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: .5rem;
  transition: opacity .2s, transform .15s;
  font-family: inherit;
}
.ch-start-btn:hover { opacity: .9; transform: translateY(-1px); }
.ch-start-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.ch-quick-links {
  margin-top: 1rem;
  padding-top: .85rem;
  border-top: 1px solid var(--ch-border);
}
.ch-quick-title { font-size: .68rem; font-weight: 700; color: var(--ch-ink30); letter-spacing: .06em; text-transform: uppercase; margin-bottom: .5rem; }
.ch-quick-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.ch-quick-chip {
  padding: .25rem .7rem;
  background: var(--ch-surface);
  border: 1px solid var(--ch-border);
  border-radius: 100px;
  font-size: .7rem;
  font-weight: 500;
  color: var(--ch-ink50);
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}
.ch-quick-chip:hover { border-color: var(--ch-accent); color: var(--ch-accent); }

/* Chat messages screen */
.ch-msgs-wrap {
  flex: 1;
  overflow-y: auto;
  padding: .85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  scroll-behavior: smooth;
}
.ch-msgs-wrap::-webkit-scrollbar { width: 4px; }
.ch-msgs-wrap::-webkit-scrollbar-track { background: transparent; }
.ch-msgs-wrap::-webkit-scrollbar-thumb { background: var(--ch-border); border-radius: 4px; }

/* Message bubbles */
.ch-msg { display: flex; flex-direction: column; max-width: 85%; }
.ch-msg-visitor { align-self: flex-end; align-items: flex-end; }
.ch-msg-agent, .ch-msg-system { align-self: flex-start; align-items: flex-start; }
.ch-msg-name { font-size: .62rem; color: var(--ch-ink30); margin-bottom: .2rem; font-weight: 600; }
.ch-bubble {
  padding: .55rem .85rem;
  border-radius: 16px;
  font-size: .84rem;
  line-height: 1.55;
  word-break: break-word;
}
.ch-msg-visitor .ch-bubble {
  background: linear-gradient(135deg, var(--ch-accent), #c2410c);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}
.ch-msg-agent .ch-bubble {
  background: var(--ch-card);
  color: var(--ch-ink);
  border: 1px solid var(--ch-border);
  border-radius: 16px 16px 16px 4px;
}
.ch-msg-system .ch-bubble {
  background: rgba(124,58,237,.12);
  border: 1px solid rgba(124,58,237,.2);
  color: rgba(196,181,253,.85);
  font-size: .75rem;
  font-style: italic;
  border-radius: 8px;
  text-align: center;
  max-width: 100%;
  align-self: center;
}
.ch-msg-time { font-size: .6rem; color: var(--ch-ink30); margin-top: .2rem; }
.ch-bubble a { color: #93c5fd; text-decoration: underline; }

/* Typing indicator */
.ch-typing { display: flex; align-items: center; gap: .4rem; padding: .4rem 0; }
.ch-typing-dots { display: flex; gap: 3px; }
.ch-typing-dots span {
  width: 6px; height: 6px;
  background: var(--ch-ink30);
  border-radius: 50%;
  animation: ch-typing-bounce .8s ease-in-out infinite;
}
.ch-typing-dots span:nth-child(2) { animation-delay: .15s; }
.ch-typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes ch-typing-bounce { 0%,100%{transform:translateY(0)} 40%{transform:translateY(-5px)} }
.ch-typing-label { font-size: .7rem; color: var(--ch-ink30); }

/* Waiting indicator */
.ch-waiting-bar {
  background: rgba(245,158,11,.07);
  border-top: 1px solid rgba(245,158,11,.15);
  padding: .45rem 1rem;
  font-size: .7rem;
  color: var(--ch-yellow);
  display: flex; align-items: center; gap: .4rem;
  flex-shrink: 0;
}
.ch-waiting-spin {
  width: 12px; height: 12px;
  border: 2px solid rgba(245,158,11,.3);
  border-top-color: var(--ch-yellow);
  border-radius: 50%;
  animation: ch-spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes ch-spin { to { transform: rotate(360deg); } }

/* Input area */
.ch-input-wrap {
  border-top: 1px solid var(--ch-border);
  padding: .65rem .85rem;
  background: var(--ch-surface);
  flex-shrink: 0;
}
.ch-input-row { display: flex; gap: .5rem; align-items: flex-end; }
.ch-msg-input {
  flex: 1;
  background: var(--ch-card);
  border: 1px solid var(--ch-border);
  border-radius: 10px;
  padding: .6rem .85rem;
  color: var(--ch-ink);
  font-size: .84rem;
  font-family: inherit;
  outline: none;
  resize: none;
  max-height: 100px;
  line-height: 1.45;
  transition: border-color .2s;
  scrollbar-width: none;
}
.ch-msg-input::-webkit-scrollbar { display: none; }
.ch-msg-input:focus { border-color: var(--ch-accent); }
.ch-msg-input::placeholder { color: var(--ch-ink30); }
.ch-send-btn {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--ch-accent), #c2410c);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .2s, transform .15s;
  flex-shrink: 0;
}
.ch-send-btn:hover { opacity: .9; transform: scale(1.05); }
.ch-send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.ch-input-tools {
  display: flex; gap: .4rem; margin-top: .4rem;
  align-items: center; flex-wrap: wrap;
}
.ch-tool-btn {
  font-size: .65rem; font-weight: 600;
  color: var(--ch-ink30);
  background: none;
  border: 1px solid var(--ch-border);
  border-radius: 6px;
  padding: .18rem .55rem;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}
.ch-tool-btn:hover { color: var(--ch-accent); border-color: var(--ch-accent); }

/* Rating screen */
.ch-rating-wrap {
  padding: 1.5rem 1.25rem;
  text-align: center;
  overflow-y: auto;
}
.ch-rating-title { font-size: 1.1rem; font-weight: 800; color: var(--ch-ink); margin-bottom: .4rem; }
.ch-rating-sub { font-size: .8rem; color: var(--ch-ink50); margin-bottom: 1.25rem; line-height: 1.55; }
.ch-stars { display: flex; gap: .35rem; justify-content: center; margin-bottom: 1rem; }
.ch-star {
  font-size: 1.75rem;
  cursor: pointer;
  filter: grayscale(1) opacity(.4);
  transition: filter .15s, transform .15s;
}
.ch-star:hover, .ch-star.active { filter: grayscale(0) opacity(1); transform: scale(1.15); }
.ch-rating-note {
  width: 100%;
  padding: .6rem .85rem;
  background: var(--ch-surface);
  border: 1px solid var(--ch-border);
  border-radius: 8px;
  color: var(--ch-ink);
  font-size: .82rem;
  font-family: inherit;
  resize: none;
  outline: none;
  margin-bottom: .75rem;
  box-sizing: border-box;
}
.ch-rating-submit {
  padding: .6rem 1.75rem;
  background: linear-gradient(135deg, var(--ch-accent), #c2410c);
  color: #fff; border: none; border-radius: 8px;
  font-size: .875rem; font-weight: 700;
  cursor: pointer; font-family: inherit;
  transition: opacity .2s;
}
.ch-rating-submit:hover { opacity: .9; }

/* Error state */
.ch-error-msg {
  font-size: .72rem;
  color: var(--ch-red);
  margin-top: .35rem;
  padding: .3rem .55rem;
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.15);
  border-radius: 6px;
  display: none;
}

/* Toast notification */
#ch-toast {
  position: fixed;
  bottom: 106px;
  right: 28px;
  z-index: 99988;
  background: var(--ch-card);
  border: 1px solid var(--ch-border);
  border-radius: 12px;
  padding: .85rem 1.1rem .85rem .9rem;
  max-width: 300px;
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
  transform: translateY(20px);
  opacity: 0;
  transition: all .3s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}
#ch-toast.show { transform: translateY(0); opacity: 1; pointer-events: all; }
.ch-toast-icon { font-size: 1.25rem; flex-shrink: 0; }
.ch-toast-body { flex: 1; }
.ch-toast-title { font-size: .8rem; font-weight: 700; color: var(--ch-ink); margin-bottom: .1rem; }
.ch-toast-msg { font-size: .72rem; color: var(--ch-ink50); }
.ch-toast-close {
  background: none; border: none;
  color: var(--ch-ink30); cursor: pointer;
  font-size: .85rem; padding: 0;
  flex-shrink: 0;
}

/* ═══ RESPONSIVE ═════════════════════════════════════════════ */
@media (max-width: 480px) {
  #ch-window { width: calc(100vw - 16px); right: 8px; bottom: 90px; max-height: calc(100vh - 110px); }
  #ch-widget-btn { right: 16px; bottom: 16px; }
  #ch-toast { right: 8px; bottom: 100px; max-width: calc(100vw - 24px); }
}
