/* Chat Widget v4 — Claude-inspired, centered modal */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --chat-bg: #0a0a1a;
  --chat-surface: #111127;
  --chat-input-bg: #0f0f25;
  --chat-border: rgba(255,255,255,0.06);
  --chat-accent: #2563EB;
  --chat-accent2: #7C3AED;
  --chat-cyan: #00d4ff;
  --chat-text: #e8e8ef;
  --chat-text-muted: rgba(255,255,255,0.4);
  --chat-text-secondary: rgba(255,255,255,0.65);
  --chat-user-msg: linear-gradient(135deg, #2563EB, #7C3AED);
  --chat-highlight: #a78bfa;
  --chat-radius: 24px;
}

/* ===== STICKY BAR — HIDDEN ===== */
.cw-sticky-bar { display: none !important; }

/* ===== INVITE BUBBLE ===== */
.cw-invite {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: 2147483647;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  padding: 16px 20px;
  max-width: 320px;
  color: var(--chat-text);
  font-size: 14px;
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.5;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  cursor: pointer;
}
.cw-invite.cw-show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.cw-invite-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none; color: var(--chat-text-muted);
  font-size: 18px; cursor: pointer; padding: 0; line-height: 1;
}

/* ===== FLOATING BUTTON ===== */
.cw-float-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2147483647;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--chat-user-msg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 28px rgba(37,99,235,0.4);
  transition: transform 0.3s, box-shadow 0.3s;
  animation: cw-float-pulse 3s infinite;
}
.cw-float-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 36px rgba(37,99,235,0.6);
}
.cw-float-btn svg { width: 28px; height: 28px; fill: white; }
@keyframes cw-float-pulse {
  0%, 100% { box-shadow: 0 4px 28px rgba(37,99,235,0.35); }
  50% { box-shadow: 0 4px 36px rgba(37,99,235,0.55); }
}
.cw-overlay.cw-open ~ .cw-float-btn,
body.cw-chat-open .cw-float-btn { display: none; }

/* ===== CHAT OVERLAY — CENTERED MODAL ===== */
.cw-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  font-family: 'Inter', system-ui, sans-serif;
}
.cw-overlay.cw-open {
  opacity: 1;
  pointer-events: auto;
}

/* ===== CHAT WINDOW — LARGE CENTERED ===== */
.cw-chat {
  width: 96%;
  max-width: 860px;
  height: 88vh;
  max-height: 88vh;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(24px) scale(0.97);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.04),
    0 24px 80px rgba(0,0,0,0.6),
    0 0 120px rgba(37,99,235,0.08);
}
.cw-overlay.cw-open .cw-chat {
  transform: translateY(0) scale(1);
}

/* ===== HEADER — MINIMAL CLAUDE STYLE ===== */
.cw-header {
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-bg);
}
.cw-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.cw-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--chat-user-msg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.cw-header-name {
  color: var(--chat-text);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.cw-header-status {
  color: var(--chat-text-secondary);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cw-header-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
}
.cw-header-close {
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--chat-text-muted);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.cw-header-close:hover {
  background: rgba(255,255,255,0.1);
  color: var(--chat-text);
}

/* PDF button */
.cw-header-pdf {
  background: none;
  border: none;
  color: var(--chat-text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.2s;
}
.cw-header-pdf:hover { color: #fff; background: rgba(255,255,255,0.08); }

/* ===== MESSAGES — CLAUDE STYLE ===== */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  scroll-behavior: smooth;
  text-align: left;
}
.cw-messages::-webkit-scrollbar { width: 6px; }
.cw-messages::-webkit-scrollbar-track { background: transparent; }
.cw-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
.cw-messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* Bot messages — clean, spacious, easy to read */
.cw-msg-bot {
  align-self: flex-start;
  max-width: 100%;
  width: 100%;
}
.cw-msg-bot .cw-msg-content {
  color: var(--chat-text);
  font-size: 15.5px;
  line-height: 1.8;
  letter-spacing: -0.01em;
  text-align: left;
}
.cw-msg-bot .cw-msg-content p {
  margin: 0 0 14px 0;
}
.cw-msg-bot .cw-msg-content p:last-child { margin-bottom: 0; }
.cw-msg-bot .cw-msg-content strong {
  color: #fff;
  font-weight: 600;
  background: linear-gradient(135deg, rgba(37,99,235,0.12), rgba(124,58,237,0.12));
  padding: 1px 6px;
  border-radius: 4px;
}
.cw-msg-bot .cw-msg-content em { color: var(--chat-highlight); font-style: normal; }
.cw-msg-bot .cw-msg-content a {
  color: var(--chat-cyan);
  text-decoration: none;
  border-bottom: 1px solid rgba(0,212,255,0.3);
  transition: border-color 0.2s;
}
.cw-msg-bot .cw-msg-content a:hover { border-bottom-color: var(--chat-cyan); }

.cw-msg-bot .cw-msg-content .section-header {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  margin: 20px 0 10px 0;
  padding: 8px 14px;
  background: linear-gradient(135deg, rgba(37,99,235,0.1), rgba(124,58,237,0.08));
  border-left: 3px solid var(--chat-accent);
  border-radius: 0 8px 8px 0;
}
.cw-msg-bot .cw-msg-content .section-header:first-child { margin-top: 0; }
.cw-msg-bot .cw-msg-content .price-highlight {
  color: var(--chat-cyan);
  font-weight: 700;
  font-size: 17px;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  margin: 10px 0;
  padding: 10px 16px;
  background: rgba(0,212,255,0.06);
  border: 1px solid rgba(0,212,255,0.12);
  border-radius: 10px;
  display: inline-block;
}

.cw-msg-bot .cw-msg-content ul {
  list-style: none;
  padding: 0;
  margin: 10px 0 18px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cw-msg-bot .cw-msg-content ul li {
  padding: 8px 14px 8px 28px;
  position: relative;
  color: var(--chat-text);
  line-height: 1.65;
  background: rgba(255,255,255,0.02);
  border-radius: 8px;
  transition: background 0.2s;
}
.cw-msg-bot .cw-msg-content ul li:hover {
  background: rgba(255,255,255,0.04);
}
.cw-msg-bot .cw-msg-content ul li::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 16px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent2));
}

.cw-msg-bot .cw-msg-content code {
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  background: rgba(255,255,255,0.06);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 13px;
}
.cw-msg-bot .cw-msg-content hr {
  border: none;
  border-top: 1px solid var(--chat-border);
  margin: 24px 0;
}

/* User messages — subtle gradient bubble */
.cw-msg-user {
  align-self: flex-end;
  max-width: 80%;
}
.cw-msg-user .cw-msg-content {
  background: var(--chat-user-msg);
  color: #fff;
  padding: 14px 20px;
  border-radius: 20px 20px 6px 20px;
  font-size: 15px;
  line-height: 1.6;
}

/* Time */
.cw-msg-time {
  font-size: 11px;
  color: var(--chat-text-muted);
  margin-top: 8px;
}
.cw-msg-user .cw-msg-time { text-align: right; }

/* ===== TYPING INDICATOR ===== */
.cw-typing {
  display: none;
  padding: 0 48px 20px;
  gap: 6px;
  align-items: center;
}
.cw-typing.cw-show { display: flex; }
.cw-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chat-accent);
  animation: cw-wave 1.4s ease-in-out infinite;
}
.cw-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.cw-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes cw-wave {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== INPUT AREA — CLAUDE STYLE ===== */
.cw-input-area {
  padding: 20px 48px 24px;
  background: var(--chat-bg);
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}
.cw-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--chat-surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 6px 6px 6px 20px;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.cw-input-row:focus-within {
  border-color: rgba(37,99,235,0.4);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.cw-input-row textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--chat-text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  padding: 12px 0;
  max-height: 140px;
  line-height: 1.5;
}
.cw-input-row textarea::placeholder { color: var(--chat-text-muted); }

.cw-icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  flex-shrink: 0;
  color: var(--chat-text-muted);
  background: transparent;
}
.cw-icon-btn:hover { background: rgba(255,255,255,0.06); }
.cw-send-btn {
  background: var(--chat-user-msg);
  color: #fff;
  border-radius: 12px;
}
.cw-send-btn:hover { transform: scale(1.05); }
.cw-voice-btn.cw-recording {
  background: #ef4444;
  color: #fff;
  animation: cw-pulse-red 1.5s infinite;
}
@keyframes cw-pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

.cw-input-hint {
  font-size: 11px;
  color: var(--chat-text-muted);
  text-align: center;
  margin-top: 10px;
}
.cw-input-hint a { color: var(--chat-text-muted); text-decoration: underline; }

/* ===== QUICK REPLIES ===== */
.cw-quick-replies {
  flex-wrap: wrap;
  display: flex;
  gap: 8px;
  padding: 4px 0;
}
.cw-quick-replies::-webkit-scrollbar { display: none; }
.cw-quick-btn {
  flex-shrink: 0;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--chat-highlight);
  border: 1px solid rgba(167,139,250,0.25);
  transition: all 0.3s ease;
  white-space: nowrap;
}
.cw-quick-btn:hover {
  background: var(--chat-user-msg);
  color: #fff;
  border-color: transparent;
}

/* ===== CALENDAR BUTTON ===== */
.cw-calendar-btn {
  display: inline-block;
  padding: 12px 24px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--chat-user-msg);
  color: #fff;
  border: none;
  transition: transform 0.2s, box-shadow 0.2s;
  margin-top: 8px;
}
.cw-calendar-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(37,99,235,0.3);
}

/* ===== TYPEWRITER CURSOR ===== */
.cw-typewriter-cursor::after {
  content: '▊';
  color: var(--chat-accent);
  animation: cw-blink 0.8s step-end infinite;
  margin-left: 1px;
}
@keyframes cw-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ===== MOBILE FULLSCREEN ===== */
@media (max-width: 768px) {
  .cw-overlay {
    background: var(--chat-bg) !important;
    backdrop-filter: none !important;
  }
  .cw-chat {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
  }
  .cw-messages { padding: 24px 16px; gap: 24px; }
  .cw-msg-bot { max-width: 95%; }
  .cw-msg-user { max-width: 85%; }
  .cw-input-area { padding: 12px 16px 16px; }
  .cw-header { padding: 14px 16px; }
  .cw-typing { padding: 0 16px 16px; }
}

/* ===== iOS Safari Fix ===== */
@media (max-width: 768px) {
  .cw-overlay {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    right: 0 !important; bottom: 0 !important;
    width: 100% !important; height: 100% !important;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
  }
  .cw-chat {
    position: absolute !important;
    top: 0 !important; left: 0 !important;
    right: 0 !important; bottom: 0 !important;
    display: flex !important;
    flex-direction: column !important;
  }
  .cw-header {
    flex-shrink: 0 !important;
    padding-top: calc(env(safe-area-inset-top, 20px) + 16px) !important;
    min-height: 70px;
    z-index: 10;
  }
  .cw-messages {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .cw-quick-replies { flex-shrink: 0 !important; }
  .cw-input-area {
    flex-shrink: 0 !important;
    padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
    z-index: 10;
  }
  .cw-footer { flex-shrink: 0 !important; padding-bottom: env(safe-area-inset-bottom) !important; }
}

/* iOS safe area */
@supports (padding-top: env(safe-area-inset-top)) {
  @media (max-width: 768px) {
    .cw-header { padding-top: calc(env(safe-area-inset-top) + 16px) !important; }
  }
}
@media (max-width: 768px) and (min-height: 700px) {
  .cw-header { padding-top: max(50px, calc(env(safe-area-inset-top, 44px) + 12px)) !important; }
}

/* Text size */
.cw-chat, .cw-chat * { -webkit-text-size-adjust: 100%; }
.cw-send-btn, .cw-voice-btn, .cw-header-close { min-width: 44px; min-height: 44px; }

/* Body lock when chat open */
body.cw-chat-open { overflow: hidden; position: fixed; width: 100%; height: 100%; }

/* Hide sticky bar with audit-bar */
body.has-audit-bar .cw-sticky-bar { display: none !important; }
