/* ============================================
   CACHET COURTESANS — LIVE CHAT WIDGET
   ============================================ */

/* ── Reset for widget scope ── */
.cl-chat *, .cl-chat *::before, .cl-chat *::after { box-sizing: border-box; margin: 0; padding: 0; }
.cl-chat { font-family: 'Raleway', system-ui, -apple-system, sans-serif; font-size: 14px; line-height: 1.5; color: #333; }

/* ── Floating Trigger Button ── */
.cl-chat-trigger {
  position: fixed; bottom: 24px; right: 24px; z-index: 9990;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 22px; background: #ffffff;
  color: #1a1a1a; border: 1px solid #e0e0e0; border-radius: 50px;
  cursor: pointer; font-family: inherit; font-size: .88rem;
  font-weight: 600; letter-spacing: .3px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  transition: all .3s; outline: none;
}
.cl-chat-trigger:hover {
  transform: translateY(-2px);
  background: #f8f8f8;
  border-color: #ccc;
  box-shadow: 0 6px 24px rgba(0,0,0,.16);
}
.cl-chat-trigger svg { flex-shrink: 0; }
.cl-chat-trigger .chat-bubble-icon {
  fill: #dc2626;
  transition: fill .3s;
}
.cl-chat-trigger.is-online .chat-bubble-icon { fill: #22c55e; }
.cl-chat-trigger.is-offline .chat-bubble-icon { fill: #dc2626; }
.cl-chat-trigger .trigger-label { white-space: nowrap; color: #1a1a1a; }
.cl-chat-trigger .status-dot { display: none; }
.cl-chat-trigger .unread-badge {
  display: none; position: absolute; top: -4px; right: -4px;
  min-width: 20px; height: 20px; padding: 0 6px;
  background: #dc2626; color: #fff; border-radius: 50px;
  font-size: .65rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.cl-chat-trigger .unread-badge:empty, .cl-chat-trigger .unread-badge[data-count="0"] { display: none; }

/* ── Chat Panel ── */
.cl-chat-panel {
  position: fixed; bottom: 24px; right: 24px; z-index: 9995;
  width: 380px; max-height: 560px; height: calc(100vh - 120px);
  background: #fff; border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,.18);
  display: none; flex-direction: column; overflow: hidden;
  animation: clChatSlideUp .3s ease;
}
.cl-chat-panel.open { display: flex; }
@keyframes clChatSlideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ── Panel Header ── */
.cl-chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; background: #1a1a1a; color: #fff;
  flex-shrink: 0;
}
.cl-chat-header .ch-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #330066, #220044);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #fff;
  flex-shrink: 0; overflow: hidden;
}
.cl-chat-header .ch-avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.cl-chat-header .ch-info { flex: 1; min-width: 0; }
.cl-chat-header .ch-name { font-weight: 600; font-size: .9rem; }
.cl-chat-header .ch-status {
  display: flex; align-items: center; gap: 5px;
  font-size: .72rem; color: #999; margin-top: 1px;
}
.cl-chat-header .ch-status .status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #6b7280;
  flex-shrink: 0;
}
.cl-chat-header .ch-status .status-dot.online { background: #22c55e; }
.cl-chat-header .ch-status .status-dot.offline { background: #dc2626; }
.cl-chat-header .ch-actions { display: flex; gap: 4px; }
.cl-chat-header .ch-actions button {
  width: 32px; height: 32px; border: none; background: rgba(255,255,255,.1);
  color: #fff; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s; font-size: 0;
}
.cl-chat-header .ch-actions button:hover { background: rgba(255,255,255,.2); }

/* ── Pre-Chat Form ── */
.cl-prechat {
  flex: 1; display: flex; flex-direction: column;
  padding: 28px 22px; overflow-y: auto;
}
.cl-prechat h3 {
  font-family: 'Prata', serif; font-size: 1.1rem; color: #1a1a1a;
  margin-bottom: 6px;
}
.cl-prechat p { font-size: .82rem; color: #999; margin-bottom: 20px; }
.cl-prechat .pc-field { margin-bottom: 14px; }
.cl-prechat .pc-field label {
  display: block; font-size: .72rem; font-weight: 600;
  color: #666; text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 4px;
}
.cl-prechat .pc-field input {
  width: 100%; padding: 10px 12px; border: 1px solid #e0ddd6;
  border-radius: 8px; font-size: .88rem; font-family: inherit;
  background: #faf9f7; color: #333; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.cl-prechat .pc-field input:focus {
  border-color: #330066; box-shadow: 0 0 0 3px rgba(51,0,102,.1);
  background: #fff;
}
.cl-prechat .pc-field .pc-error {
  font-size: .72rem; color: #dc2626; margin-top: 3px; display: none;
}
.cl-prechat .pc-submit {
  width: 100%; padding: 12px; background: #330066; color: #fff;
  border: none; border-radius: 30px; font-size: .88rem;
  font-weight: 600; letter-spacing: .5px; cursor: pointer;
  font-family: inherit; transition: background .2s; margin-top: 6px;
}
.cl-prechat .pc-submit:hover { background: #220044; }
.cl-prechat .pc-offline-note {
  font-size: .78rem; color: #92400e; background: #fffbeb;
  padding: 10px 14px; border-radius: 8px; margin-top: 12px;
  border-left: 3px solid #d97706;
}
.cl-prechat .pc-offline-note.hidden { display: none; }

/* ── Messages Area ── */
.cl-messages {
  flex: 1; overflow-y: auto; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px;
  background: #faf9f7;
}
.cl-messages::-webkit-scrollbar { width: 4px; }
.cl-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.cl-msg {
  max-width: 80%; padding: 10px 14px;
  border-radius: 14px; font-size: .88rem;
  line-height: 1.5; word-wrap: break-word;
  animation: clMsgIn .2s ease;
}
@keyframes clMsgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.cl-msg.visitor {
  align-self: flex-end; background: #330066; color: #fff;
  border-bottom-right-radius: 4px;
}
.cl-msg.admin {
  align-self: flex-start; background: #fff; color: #333;
  border: 1px solid #e8e5de; border-bottom-left-radius: 4px;
}
.cl-msg .msg-sender {
  font-size: .68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .3px; margin-bottom: 2px; opacity: .7;
}
.cl-msg .msg-time {
  font-size: .65rem; opacity: .6; margin-top: 4px;
  text-align: right;
}
.cl-msg.admin .msg-time { text-align: left; }

/* Attachment in message */
.cl-msg .msg-attachment {
  margin-top: 8px; display: block;
}
.cl-msg .msg-attachment img {
  max-width: 100%; max-height: 200px;
  border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(0,0,0,.08);
}
.cl-msg .msg-attachment .file-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: rgba(0,0,0,.05);
  border-radius: 6px; font-size: .78rem; font-weight: 500;
  color: inherit; text-decoration: none;
}
.cl-msg.visitor .msg-attachment .file-link { background: rgba(255,255,255,.2); color: #fff; }

/* System messages */
.cl-msg-system {
  text-align: center; font-size: .72rem; color: #999;
  padding: 4px 0;
}

/* Typing indicator */
.cl-typing {
  display: none; align-self: flex-start;
  padding: 10px 14px; background: #fff; border: 1px solid #e8e5de;
  border-radius: 14px; border-bottom-left-radius: 4px;
}
.cl-typing.visible { display: flex; gap: 4px; align-items: center; }
.cl-typing span {
  width: 6px; height: 6px; background: #bbb; border-radius: 50%;
  animation: clDot 1.4s infinite;
}
.cl-typing span:nth-child(2) { animation-delay: .2s; }
.cl-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes clDot { 0%,60%,100% { opacity: .3; transform: scale(.8); } 30% { opacity: 1; transform: scale(1); } }

/* ── Input Bar ── */
.cl-input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 14px; border-top: 1px solid #f0ede6;
  background: #fff; flex-shrink: 0;
}
.cl-input-bar .attach-btn {
  width: 36px; height: 36px; border: none;
  background: #f5f3ef; color: #999; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; transition: all .2s;
}
.cl-input-bar .attach-btn:hover { background: #ebe8e2; color: #666; }
.cl-input-bar textarea {
  flex: 1; resize: none; border: 1px solid #e0ddd6;
  border-radius: 10px; padding: 8px 12px; font-size: .88rem;
  font-family: inherit; outline: none; background: #faf9f7;
  min-height: 36px; max-height: 100px; line-height: 1.4;
  transition: border-color .2s;
}
.cl-input-bar textarea:focus { border-color: #330066; background: #fff; }
.cl-input-bar .send-btn {
  width: 36px; height: 36px; border: none;
  background: #330066; color: #fff; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; transition: all .2s;
}
.cl-input-bar .send-btn:hover { background: #220044; }
.cl-input-bar .send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Attachment preview in input */
.cl-attach-preview {
  display: none; padding: 8px 14px; border-top: 1px solid #f0ede6;
  background: #faf9f7; flex-shrink: 0;
}
.cl-attach-preview.visible { display: flex; align-items: center; gap: 8px; }
.cl-attach-preview .ap-name { flex: 1; font-size: .78rem; color: #666; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-attach-preview .ap-size { font-size: .72rem; color: #999; }
.cl-attach-preview .ap-remove {
  width: 24px; height: 24px; border: none; background: #fee2e2;
  color: #dc2626; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; flex-shrink: 0;
}

/* ── Model Picker ── */
.cl-model-picker {
  display: none;
  position: absolute;
  bottom: 110px;
  left: 10px;
  right: 10px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  z-index: 10;
  max-height: 280px;
  overflow: hidden;
  flex-direction: column;
}
.cl-mp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #f0ede6;
  font-size: .82rem;
  font-weight: 700;
  color: #1a1a1a;
}
.cl-mp-close {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: #999;
  padding: 2px;
}
.cl-mp-search {
  margin: 8px 12px;
  padding: 7px 10px;
  border: 1px solid #e0ddd6;
  border-radius: 6px;
  font-size: .78rem;
  outline: none;
  font-family: inherit;
  width: calc(100% - 24px);
  box-sizing: border-box;
}
.cl-mp-search:focus { border-color: #330066; }
.cl-mp-list {
  overflow-y: auto;
  max-height: 190px;
  padding: 0 6px 6px;
}
.cl-mp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.cl-mp-item:hover { background: #fffbeb; }
.cl-mp-thumb {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-size: cover;
  background-position: center top;
  background-color: #e8e5de;
  flex-shrink: 0;
}
.cl-mp-info { flex: 1; min-width: 0; }
.cl-mp-name { font-size: .82rem; font-weight: 600; color: #1a1a1a; }
.cl-mp-detail { font-size: .68rem; color: #999; margin-top: 1px; }
.cl-mp-empty { padding: 16px; text-align: center; color: #999; font-size: .82rem; }

/* Model Card in messages */
.cl-model-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(51, 0, 102, .08);
  border: 1px solid rgba(51, 0, 102, .2);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  margin-top: 4px;
  transition: background .15s;
}
.cl-model-card:hover { background: rgba(51, 0, 102, .15); }
.cl-mc-img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-size: cover;
  background-position: center top;
  background-color: #e8e5de;
  flex-shrink: 0;
}
.cl-mc-info { flex: 1; }
.cl-mc-name { font-size: .85rem; font-weight: 700; color: #1a1a1a; }
.cl-mc-link { font-size: .7rem; color: #330066; margin-top: 2px; }

/* Model picker button */
.model-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: #f5f3ef;
  color: #330066;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.model-btn:hover { background: #fffbeb; }

/* ── End Chat Bar ── */
.cl-end-bar {
  display: none;
  padding: 6px 14px 10px;
  justify-content: center;
  background: #fff;
  border-top: 1px solid #f0ede6;
}
.cl-end-btn {
  background: none;
  border: 1px solid #e0ddd6;
  color: #999;
  font-size: .72rem;
  padding: 4px 14px;
  border-radius: 16px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.cl-end-btn:hover {
  border-color: #dc2626;
  color: #dc2626;
  background: #fef2f2;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .cl-chat-panel {
    top: 0; bottom: 0; right: 0; left: 0;
    width: 100%; height: 100%;
    max-height: none;
    border-radius: 0;
    /* Safe area for notch/status bar on modern phones */
    padding-top: env(safe-area-inset-top, 0px);
  }
  /* Ensure header is always visible and not clipped */
  .cl-chat-panel .cl-chat-header {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .cl-chat-trigger {
    bottom: 16px; right: 16px;
    padding: 12px; border-radius: 50%;
  }
  .cl-chat-trigger .trigger-label { display: none; }
  .cl-chat-trigger .status-dot { display: none; }
}
@media (min-width: 481px) and (max-width: 768px) {
  .cl-chat-panel { width: 340px; }
  .cl-chat-trigger { padding: 12px 16px; font-size: .82rem; }
}
