/* ─────────────────────────────────────────────────────────────────────────────
   WP Chat Server – Frontend Widget Styles
   Design: clean, accessible, mobile-first. Uses CSS custom properties so the
   primary colour can be overridden via the --wpcs-primary variable.
───────────────────────────────────────────────────────────────────────────── */

:root {
  --wpcs-primary:        #4f46e5;
  --wpcs-primary-dark:   #4338ca;
  --wpcs-primary-light:  #eef2ff;
  --wpcs-bg:             #ffffff;
  --wpcs-surface:        #f9fafb;
  --wpcs-border:         #e5e7eb;
  --wpcs-text:           #111827;
  --wpcs-text-muted:     #6b7280;
  --wpcs-bubble-self:    var(--wpcs-primary);
  --wpcs-bubble-other:   #f3f4f6;
  --wpcs-radius:         16px;
  --wpcs-shadow:         0 8px 32px rgba(0,0,0,.14);
  --wpcs-z:              9999;
  --wpcs-w:              360px;
  --wpcs-h:              520px;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
.wpcs-widget *,
.wpcs-widget *::before,
.wpcs-widget *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Widget container ────────────────────────────────────────────────────── */
.wpcs-widget {
  position: fixed;
  z-index: var(--wpcs-z);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--wpcs-text);
}

.wpcs-widget[data-wpcs-inline] {
  position: relative;
}

/* Positions */
.wpcs-bottom-right { bottom: 24px; right: 24px; }
.wpcs-bottom-left  { bottom: 24px; left: 24px;  }
.wpcs-top-right    { top: 24px;    right: 24px; }
.wpcs-top-left     { top: 24px;    left: 24px;  }

/* ── Launcher Button ─────────────────────────────────────────────────────── */
.wpcs-launcher {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--wpcs-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.24);
  transition: transform .2s ease, background .2s ease;
  outline: none;
}
.wpcs-launcher:hover  { background: var(--wpcs-primary-dark); transform: scale(1.08); }
.wpcs-launcher:focus-visible { outline: 3px solid var(--wpcs-primary); outline-offset: 3px; }

.wpcs-launcher svg {
  width: 24px;
  height: 24px;
  transition: opacity .2s, transform .2s;
  position: absolute;
}
.wpcs-icon-chat  { opacity: 1;  transform: scale(1); }
.wpcs-icon-close { opacity: 0;  transform: scale(.6); }

.wpcs-open .wpcs-icon-chat  { opacity: 0;  transform: scale(.6); }
.wpcs-open .wpcs-icon-close { opacity: 1;  transform: scale(1); }

/* ── Unread Badge ────────────────────────────────────────────────────────── */
.wpcs-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  pointer-events: none;
}
.wpcs-hidden { display: none !important; }

/* ── Chat Window ─────────────────────────────────────────────────────────── */
.wpcs-window {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: var(--wpcs-w);
  max-width: calc(100vw - 32px);
  height: var(--wpcs-h);
  max-height: calc(100vh - 100px);
  background: var(--wpcs-bg);
  border-radius: var(--wpcs-radius);
  box-shadow: var(--wpcs-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: wpcs-pop .22s cubic-bezier(.34,1.56,.64,1);
}
.wpcs-bottom-left .wpcs-window { right: auto; left: 0; transform-origin: bottom left; }
.wpcs-top-right   .wpcs-window { bottom: auto; top: 68px; transform-origin: top right; }
.wpcs-top-left    .wpcs-window { bottom: auto; top: 68px; right: auto; left: 0; transform-origin: top left; }

@keyframes wpcs-pop {
  from { opacity: 0; transform: scale(.85); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.wpcs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  background: var(--wpcs-primary);
  color: #fff;
  flex-shrink: 0;
}
.wpcs-header-info { display: flex; align-items: center; gap: 10px; }
.wpcs-title       { display: block; font-weight: 600; font-size: 15px; }
.wpcs-subtitle    { display: block; font-size: 12px; opacity: .8; }

.wpcs-status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.wpcs-status-online  { background: #4ade80; box-shadow: 0 0 0 2px rgba(74,222,128,.35); }
.wpcs-status-offline { background: #9ca3af; }

.wpcs-btn-icon {
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.wpcs-btn-icon:hover { background: rgba(255,255,255,.25); }
.wpcs-btn-icon svg   { width: 16px; height: 16px; }

/* ── Pre-chat Form ───────────────────────────────────────────────────────── */
.wpcs-prechat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 16px;
  overflow-y: auto;
}
.wpcs-greeting {
  font-size: 14px;
  color: var(--wpcs-text-muted);
  line-height: 1.6;
}
.wpcs-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--wpcs-border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  background: var(--wpcs-surface);
}
.wpcs-input:focus { border-color: var(--wpcs-primary); background: #fff; }

.wpcs-gdpr {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--wpcs-text-muted);
  cursor: pointer;
}
.wpcs-gdpr input { margin-top: 2px; accent-color: var(--wpcs-primary); }

.wpcs-btn-primary {
  padding: 11px 16px;
  background: var(--wpcs-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.wpcs-btn-primary:hover { background: var(--wpcs-primary-dark); }

/* ── Messages Area ───────────────────────────────────────────────────────── */
.wpcs-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  scroll-behavior: smooth;
}
.wpcs-messages-inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 12px;
  min-height: 100%;
  justify-content: flex-end;
}

/* ── Message Bubbles ─────────────────────────────────────────────────────── */
.wpcs-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: wpcs-fade-up .18s ease;
}
@keyframes wpcs-fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.wpcs-msg-self  { align-self: flex-end;  flex-direction: row-reverse; }
.wpcs-msg-other { align-self: flex-start; }

.wpcs-msg-system {
  align-self: center;
  font-size: 12px;
  color: var(--wpcs-text-muted);
  padding: 4px 10px;
  background: var(--wpcs-surface);
  border-radius: 20px;
  margin: 4px 0;
  max-width: 80%;
  text-align: center;
}

.wpcs-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--wpcs-primary-light);
  color: var(--wpcs-primary);
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.wpcs-msg-body  { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wpcs-msg-name  { font-size: 11px; font-weight: 600; color: var(--wpcs-text-muted); padding: 0 4px; }

.wpcs-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.5;
}
.wpcs-msg-other .wpcs-bubble {
  background: var(--wpcs-bubble-other);
  color: var(--wpcs-text);
  border-bottom-left-radius: 4px;
}
.wpcs-msg-self .wpcs-bubble {
  background: var(--wpcs-bubble-self);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Links inside bubbles */
.wpcs-bubble a         { color: inherit; text-decoration: underline; }
.wpcs-msg-self .wpcs-bubble a { color: rgba(255,255,255,.9); }

.wpcs-msg-time {
  font-size: 10px;
  color: var(--wpcs-text-muted);
  padding: 0 4px;
  white-space: nowrap;
}
.wpcs-msg-self .wpcs-msg-time { text-align: right; }

/* ── Typing Indicator ────────────────────────────────────────────────────── */
.wpcs-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 20px;
  flex-shrink: 0;
}
.wpcs-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--wpcs-text-muted);
  animation: wpcs-bounce .9s infinite;
}
.wpcs-typing span:nth-child(2) { animation-delay: .15s; }
.wpcs-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes wpcs-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-5px); }
}

/* ── Input Form ──────────────────────────────────────────────────────────── */
.wpcs-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--wpcs-border);
  background: var(--wpcs-bg);
  flex-shrink: 0;
}
.wpcs-textarea {
  flex: 1;
  border: 1px solid var(--wpcs-border);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
  background: var(--wpcs-surface);
  transition: border-color .15s;
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
}
.wpcs-textarea:focus { border-color: var(--wpcs-primary); background: #fff; }

.wpcs-btn-send {
  width: 38px; height: 38px;
  border: none; border-radius: 50%;
  background: var(--wpcs-primary);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.wpcs-btn-send:hover   { background: var(--wpcs-primary-dark); }
.wpcs-btn-send:active  { transform: scale(.9); }
.wpcs-btn-send:disabled { opacity: .5; cursor: default; transform: none; }
.wpcs-btn-send svg     { width: 18px; height: 18px; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
.wpcs-messages::-webkit-scrollbar { width: 4px; }
.wpcs-messages::-webkit-scrollbar-track { background: transparent; }
.wpcs-messages::-webkit-scrollbar-thumb { background: var(--wpcs-border); border-radius: 2px; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .wpcs-widget { bottom: 12px; right: 12px; }
  .wpcs-bottom-left { bottom: 12px; left: 12px; }
  .wpcs-window {
    position: fixed;
    bottom: 80px;
    left: 8px;
    right: 8px;
    width: auto;
    height: calc(100vh - 110px);
    max-height: calc(100vh - 110px);
    border-radius: 16px;
  }
  .wpcs-bottom-left .wpcs-window,
  .wpcs-bottom-right .wpcs-window {
    left: 8px;
    right: 8px;
  }
}

/* ── Dark Mode ───────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  .wpcs-widget {
    --wpcs-bg:           #1f2937;
    --wpcs-surface:      #111827;
    --wpcs-border:       #374151;
    --wpcs-text:         #f9fafb;
    --wpcs-text-muted:   #9ca3af;
    --wpcs-bubble-other: #374151;
    --wpcs-primary-light:#312e81;
  }
}
