/* PHC Chatbot v3.8.0 — Frontend Chat Widget Styles */

/* ── Variables ────────────────────────────────────────────────────────────── */
#phc-widget {
  --phc-blue       : #0a7cff;
  --phc-blue-dark  : #0060cc;
  --phc-bg         : #ffffff;
  --phc-bg-user    : #0a7cff;
  --phc-bg-bot     : #f2f3f5;
  --phc-text-user  : #ffffff;
  --phc-text-bot   : #2d3748;
  --phc-text-muted : #718096;
  --phc-border     : #e4e6ea;
  --phc-shadow     : 0 20px 60px rgba(0, 0, 0, 0.18);
  --phc-radius     : 16px;
  --phc-font       : -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --phc-panel-w    : 360px;
  --phc-panel-h    : 520px;
  --phc-z          : 99999;

  all: initial;
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: var(--phc-z);
  font-family: var(--phc-font);
  line-height: 1.5;
  pointer-events: auto;
}

/* ── Bubble ───────────────────────────────────────────────────────────────── */
#phc-bubble {
  all: initial;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--phc-blue);
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: 0 6px 24px rgba(10, 124, 255, 0.45);
  transition: transform .2s ease, box-shadow .2s ease;
  position: relative;
  border: none;
}

#phc-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 30px rgba(10, 124, 255, 0.55);
}

#phc-bubble svg {
  width: 24px;
  height: 24px;
  stroke: #fff;
  display: block;
}

/* Unread dot */
#phc-unread-dot {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #e74c3c;
  border-radius: 50%;
  border: 2px solid #fff;
  animation: phc-pulse 2s infinite;
}

@keyframes phc-pulse {
  0%   { transform: scale(1);   opacity: 1;   }
  50%  { transform: scale(1.3); opacity: 0.7; }
  100% { transform: scale(1);   opacity: 1;   }
}

/* ── Panel ────────────────────────────────────────────────────────────────── */
#phc-panel {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: var(--phc-panel-w);
  height: var(--phc-panel-h);
  background: var(--phc-bg);
  border-radius: var(--phc-radius);
  box-shadow: var(--phc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  transition: opacity .22s ease, transform .22s ease, visibility .22s ease;
  transform-origin: bottom right;
}

#phc-panel.phc-panel--open {
  opacity: 1 !important;
  pointer-events: auto !important;
  transform: translateY(0) scale(1) !important;
  visibility: visible !important;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#phc-header {
  background: var(--phc-blue);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#phc-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

#phc-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: .03em;
  flex-shrink: 0;
}

#phc-header-name {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}

#phc-header-sub {
  color: rgba(255,255,255,0.75);
  font-size: 11px;
  margin-top: 1px;
}

#phc-close-btn {
  all: initial;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#phc-close-btn:hover { background: rgba(255,255,255,0.28); }

#phc-close-btn svg {
  width: 16px;
  height: 16px;
  stroke: #fff;
  display: block;
}

/* ── Messages ─────────────────────────────────────────────────────────────── */
#phc-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

#phc-messages::-webkit-scrollbar { width: 4px; }
#phc-messages::-webkit-scrollbar-track { background: transparent; }
#phc-messages::-webkit-scrollbar-thumb { background: #dde; border-radius: 2px; }

.phc-msg-wrap {
  display: flex;
  max-width: 88%;
}

.phc-msg-wrap--user { align-self: flex-end; justify-content: flex-end; }
.phc-msg-wrap--bot  { align-self: flex-start; }

.phc-msg {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.phc-msg--user {
  background: var(--phc-bg-user);
  color: var(--phc-text-user);
  border-radius: 18px 18px 4px 18px;
}

.phc-msg--bot {
  background: var(--phc-bg-bot);
  color: var(--phc-text-bot);
  border-radius: 18px 18px 18px 4px;
}

.phc-msg a.phc-url {
  color: var(--phc-blue);
  word-break: break-all;
  text-decoration: underline;
  cursor: pointer;
}

.phc-msg--user a.phc-url { color: rgba(255,255,255,0.9); }

/* ── Typing indicator ─────────────────────────────────────────────────────── */
#phc-typing {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 8px 18px 2px;
  flex-shrink: 0;
}

#phc-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--phc-text-muted);
  opacity: 0.5;
  animation: phc-bounce .9s infinite ease-in-out;
}

#phc-typing span:nth-child(1) { animation-delay: 0s;    }
#phc-typing span:nth-child(2) { animation-delay: 0.18s; }
#phc-typing span:nth-child(3) { animation-delay: 0.36s; }

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

/* ── Disclaimer strip ─────────────────────────────────────────────────────── */
#phc-disclaimer {
  flex-shrink: 0;
  padding: 5px 14px;
  font-family: var(--phc-font);
  font-size: 11px;
  color: var(--phc-text-muted);
  text-align: center;
  line-height: 1.4;
  opacity: 1;
  max-height: 44px;
  overflow: hidden;
  transition: opacity .4s ease, max-height .4s ease, padding .4s ease;
}

#phc-disclaimer.phc-disclaimer--hidden {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
}

/* ── Input area ───────────────────────────────────────────────────────────── */
#phc-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--phc-border);
  flex-shrink: 0;
  background: var(--phc-bg);
}

#phc-input {
  all: initial;
  flex: 1;
  font-family: var(--phc-font);
  /* 16px prevents iOS Safari auto-zoom when input is focused */
  font-size: 16px;
  color: var(--phc-text-bot);
  background: #f6f7f9;
  border: 1px solid transparent;
  border-radius: 22px;
  padding: 9px 14px;
  outline: none;
  transition: border-color .15s;
  min-width: 0;
  -webkit-appearance: none;
  touch-action: manipulation;
}

#phc-input:focus {
  border-color: var(--phc-blue);
  background: #fff;
}

#phc-input::placeholder { color: var(--phc-text-muted); }

#phc-send-btn {
  all: initial;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 44×44 minimum tap target (Apple HIG / WCAG 2.5.5) */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--phc-blue);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#phc-send-btn:hover {
  background: var(--phc-blue-dark);
  transform: scale(1.05);
}

#phc-send-btn svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
  display: block;
  margin-left: 2px;
}

/* ── Quick-reply chips ───────────────────────────────────────────────────── */
.phc-chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 12px 12px 12px;
  animation: phc-chips-in .2s ease;
}

@keyframes phc-chips-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.phc-chip {
  all: initial;
  font-family: var(--phc-font);
  font-size: 13px;
  line-height: 1.4;
  color: var(--phc-blue);
  background: transparent;
  border: 1.5px solid var(--phc-blue);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  display: inline-block;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Mobile — chips can wrap on narrow screens */
@media (max-width: 480px) {
  .phc-chip { white-space: normal; word-break: break-word; }
}

/* Desktop — no wrap needed */
@media (min-width: 481px) {
  .phc-chip { white-space: nowrap; }
}

.phc-chip:hover,
.phc-chip:focus {
  background: var(--phc-blue);
  color: #fff;
  outline: none;
}

/* ── Mobile layout ────────────────────────────────────────────────────────── */
@media (max-width: 480px) {

  /* Widget becomes a full-width base so children can stretch */
  #phc-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
  }

  /* Panel: fixed (not absolute) on mobile — absolute inside fixed breaks on iOS zoom.
     dvh (dynamic viewport height) shrinks when the keyboard is open — input stays visible.
     Falls back to 85vh for browsers that don't support dvh. */
  #phc-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 85vh;
    height: 85dvh;
    border-radius: 16px 16px 0 0;
    transform-origin: bottom center;
  }

  /* Input bar: pad for iPhone home indicator */
  #phc-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }

  /* Bubble: fixed, above theme scroll-to-top + iPhone home bar */
  #phc-bubble {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }

  /* Larger send button on mobile */
  #phc-send-btn {
    width: 48px;
    height: 48px;
  }
}
