/* ============================================================ *
 * APX LiveChat — Comm100 Pixel-Perfect Theme                    *
 * ============================================================ */

:root {
  --primary-color: #1f1f1f;
  --accent-color: #d4af37;
  --comm100-dark: #1e1e1e;
  --comm100-dark-hover: #000000;
  --comm100-text: #1a1a1a;
  --comm100-mute: #71717a;
  --comm100-border: #e2e2e8;
  --comm100-input-border: #d5d5dc;
  --comm100-card-bg: #ffffff;
  --comm100-card-shadow: 0 4px 18px rgba(0, 0, 0, 0.05);
  --comm100-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--comm100-font);
  color: var(--comm100-text);
  font-size: 14px;
  line-height: 1.45;
  background: transparent;
}

.hidden {
  display: none !important;
}

/* ============================================================ *
 * Outer Container with Geometric Low-Poly Mesh Watermark        *
 * ============================================================ */
.widget-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
  background-color: #f8f9fa;
  background-image: url("comm100-bg.svg");
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center top;
  overflow: hidden;
  border-radius: 14px;
}

/* ============================================================ *
 * Comm100 Window Top Bar / Controls                             *
 * ============================================================ */
#widget-header {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 20;
  background: transparent;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

/* When chat is active, header transitions to solid clean Comm100 agent bar */
#widget-header.active-chat-header {
  height: 60px;
  background: #ffffff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.avatar-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #eef0f3;
  color: #1e1e1e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.status-dot {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 11px;
  height: 11px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid #ffffff;
}

.header-info h1 {
  font-size: 14.5px;
  font-weight: 700;
  color: #18181b;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-info p {
  font-size: 11px;
  color: #71717a;
  margin-top: 2px;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.comm100-ctrl-btn {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #71717a;
  transition: all 0.15s ease;
}

.comm100-ctrl-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #18181b;
}

.comm100-ctrl-btn svg {
  display: block;
}

/* ============================================================ *
 * Main Content Area                                             *
 * ============================================================ */
#widget-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.view {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Scrollbar */
.view::-webkit-scrollbar,
#messages-container::-webkit-scrollbar {
  width: 5px;
}
.view::-webkit-scrollbar-thumb,
#messages-container::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

/* ============================================================ *
 * VIEW 1: PRE-CHAT (COMM100 REPLICA)                           *
 * ============================================================ */
#view-prechat {
  padding: 0 18px 8px;
  display: flex;
  flex-direction: column;
}

/* Top Brand Logo */
.comm100-brand-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0 14px;
  min-height: 52px;
}

.comm100-logo {
  max-height: 48px;
  max-width: 220px;
  object-fit: contain;
  display: block;
}

.comm100-brand-fallback {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #1e1e1e;
  text-align: center;
}

/* Floating White Announcement Card */
.comm100-card {
  background: var(--comm100-card-bg);
  border-radius: 12px;
  box-shadow: var(--comm100-card-shadow);
  border: 1px solid rgba(0, 0, 0, 0.04);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.announcement-welcome {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 10px;
  line-height: 1.4;
}

.announcement-items {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 12px;
}

.announcement-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #262626;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, color 0.15s ease;
}

.announcement-row:hover {
  color: #0284c7;
  transform: translateX(2px);
}

.row-icon {
  font-size: 14px;
  display: inline-block;
  line-height: 1;
}

.row-text {
  font-size: 13px;
  line-height: 1.3;
}

.announcement-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #27272a;
  font-weight: 500;
  padding-top: 10px;
  border-top: 1px solid #f1f1f4;
}

.status-indicator {
  font-size: 13px;
  line-height: 1;
}

.status-text {
  font-size: 13px;
  color: #222222;
}

/* Pre-chat Form */
.comm100-form-wrap {
  display: flex;
  flex-direction: column;
}

.comm100-req-legend {
  font-size: 12px;
  color: #71717a;
  margin-bottom: 10px;
}

.comm100-prechat-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.comm100-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.comm100-field label {
  font-size: 13.5px;
  font-weight: 700;
  color: #18181b;
}

.req-star {
  color: #ef4444;
  font-weight: 700;
  margin-left: 2px;
}

.comm100-field input,
.comm100-field select,
.comm100-field textarea {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--comm100-input-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  color: #18181b;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.comm100-field input:focus,
.comm100-field select:focus,
.comm100-field textarea:focus {
  border-color: #18181b;
  box-shadow: 0 0 0 2px rgba(24, 24, 27, 0.08);
}

.comm100-field textarea {
  resize: none;
  min-height: 70px;
  line-height: 1.4;
}

/* Comm100 Solid Black Full-Width Button */
.comm100-submit-btn {
  width: 100%;
  height: 44px;
  background: var(--comm100-dark);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.1s ease;
  margin-top: 4px;
}

.comm100-submit-btn:hover {
  background: var(--comm100-dark-hover);
}

.comm100-submit-btn:active {
  transform: scale(0.99);
}

/* Bottom Watermark: Powered by comm100 */
.comm100-bottom-bar {
  padding: 10px 0 4px;
  text-align: right;
  margin-top: auto;
}

.comm100-watermark-text {
  font-size: 11px;
  color: #888888;
  font-family: inherit;
  letter-spacing: 0.2px;
  user-select: none;
}

/* ============================================================ *
 * VIEW 2: QUEUE WAITING VIEW                                   *
 * ============================================================ */
#view-queue {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.comm100-queue-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--comm100-card-shadow);
  border: 1px solid rgba(0, 0, 0, 0.05);
  max-width: 330px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.comm100-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid #f1f1f4;
  border-top-color: var(--comm100-dark);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.comm100-queue-card h3 {
  font-size: 16px;
  font-weight: 700;
  color: #18181b;
  margin-bottom: 8px;
}

.comm100-queue-card p {
  font-size: 13.5px;
  color: #52525b;
  margin-bottom: 16px;
}

.comm100-progress {
  width: 100%;
  height: 5px;
  background: #e4e4e7;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 14px;
}

.comm100-progress-bar {
  height: 100%;
  width: 45%;
  background: var(--comm100-dark);
  border-radius: 3px;
  animation: progressPulse 1.6s ease-in-out infinite;
}

@keyframes progressPulse {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
  100% { transform: translateX(250%); }
}

.comm100-queue-hint {
  font-size: 11.5px !important;
  color: #a1a1aa !important;
  line-height: 1.4;
  margin-bottom: 0 !important;
}

/* ============================================================ *
 * VIEW 3: ACTIVE CHAT CONVERSATION VIEW                        *
 * ============================================================ */
#view-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #ffffff;
}

.messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  position: relative;
  animation: msgFadeIn 0.2s ease-out;
}

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-row.visitor {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.agent {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-row.system {
  align-self: center;
  align-items: center;
  max-width: 95%;
  margin: 6px 0;
}

/* Visitor Bubble (Dark Comm100 style) */
.msg-row.visitor .msg-bubble {
  background: var(--comm100-dark);
  color: #ffffff;
  border-radius: 14px 14px 2px 14px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* Agent Bubble (Clean White with subtle border) */
.msg-agent-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.msg-agent-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e2e8f0;
  flex-shrink: 0;
  overflow: hidden;
  margin-top: 2px;
}

.msg-agent-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg-row.agent .msg-bubble {
  background: #f4f4f6;
  color: #18181b;
  border-radius: 14px 14px 14px 2px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
  border: 1px solid #e8e8ed;
}

.msg-time {
  font-size: 10.5px;
  color: #a1a1aa;
  margin-top: 3px;
  padding: 0 4px;
}

.system-badge {
  background: #f1f1f4;
  color: #52525b;
  font-size: 11.5px;
  padding: 4px 12px;
  border-radius: 12px;
  text-align: center;
  line-height: 1.3;
}

/* Typing notice */
.typing-notice {
  padding: 6px 16px;
  font-size: 12px;
  color: #71717a;
  display: flex;
  align-items: center;
  gap: 8px;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  background: #71717a;
  border-radius: 50%;
  animation: typingDot 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Chat Input Area */
#chat-input-area {
  padding: 10px 14px;
  background: #ffffff;
  border-top: 1px solid #ebebf0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.file-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #71717a;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.file-btn:hover {
  background: #f4f4f5;
  color: #18181b;
}

.file-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

#chat-textarea {
  flex: 1;
  background: #f4f4f6;
  border: 1px solid #e4e4e7;
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: inherit;
  color: #18181b;
  outline: none;
  resize: none;
  max-height: 100px;
  min-height: 38px;
  line-height: 1.4;
  transition: border-color 0.15s ease;
}

#chat-textarea:focus {
  border-color: #18181b;
  background: #ffffff;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--comm100-dark);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.send-btn:hover {
  background: #000000;
}

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

.send-btn svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
  margin-left: 2px;
}

/* Chat Footer Watermark */
.chat-watermark-row {
  background: #ffffff;
  padding: 2px 14px 6px;
  text-align: right;
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 14px;
}

/* ============================================================ *
 * VIEW 4: RATING SURVEY VIEW                                    *
 * ============================================================ */
#view-rating {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.rating-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--comm100-card-shadow);
  border: 1px solid rgba(0,0,0,0.05);
  max-width: 340px;
  width: 100%;
}

.rating-icon {
  font-size: 38px;
  margin-bottom: 12px;
}

.rating-card h2 {
  font-size: 17px;
  font-weight: 700;
  color: #18181b;
  margin-bottom: 6px;
}

.rating-card p {
  font-size: 13px;
  color: #71717a;
  margin-bottom: 18px;
}

.star-rating {
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 28px;
  color: #d1d5db;
  cursor: pointer;
  margin-bottom: 16px;
  user-select: none;
}

.star.active {
  color: #f59e0b;
}

#rating-comment {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--comm100-input-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: #18181b;
  outline: none;
  resize: none;
  margin-bottom: 16px;
}

#rating-comment:focus {
  border-color: #18181b;
}

.secondary-btn {
  width: 100%;
  height: 40px;
  background: #f4f4f5;
  color: #27272a;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-top: 8px;
}

.secondary-btn:hover {
  background: #e4e4e7;
}

/* Mobile full-screen adjustments */
@media (max-width: 600px) {
  .widget-container {
    border-radius: 0;
  }
}
