/* ── Chat widget — realcanadiancars.ca ──────────────────────────
   Floating chat bubble bottom-right + slide-up panel. Vanilla CSS,
   no dependencies. Loaded on every page that includes /chat.js. */

:root {
  --chat-red: #C41E3A;
  --chat-red-light: #E8344F;
  --chat-bg: #FFFFFF;
  --chat-fg: #1a1a1a;
  --chat-muted: #777;
  --chat-border: #E0E0E0;
  --chat-bubble-client: #C41E3A;
  --chat-bubble-ai: #F2F2F2;
  --chat-shadow: 0 16px 48px rgba(0,0,0,0.18), 0 4px 12px rgba(0,0,0,0.08);
  --chat-ease: cubic-bezier(.16,1,.3,1);
}

#rcc-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--chat-red);
  color: #fff;
  border: 0;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(196,30,58,0.40), 0 2px 6px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform .25s var(--chat-ease), background .2s;
}
#rcc-chat-toggle:hover { background: var(--chat-red-light); transform: translateY(-2px); }
#rcc-chat-toggle.open { transform: scale(.85); opacity: .35; }
#rcc-chat-toggle svg { width: 26px; height: 26px; }
#rcc-chat-toggle .badge {
  position: absolute;
  top: 4px; right: 4px;
  background: #fff;
  color: var(--chat-red);
  font-size: 11px;
  font-weight: 700;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
#rcc-chat-toggle.has-unread .badge { display: flex; }

#rcc-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 130px);
  background: var(--chat-bg);
  color: var(--chat-fg);
  border-radius: 18px;
  box-shadow: var(--chat-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "DM Sans", sans-serif;
}
#rcc-chat-panel.open {
  display: flex;
  animation: rcc-chat-up .3s var(--chat-ease);
}
@keyframes rcc-chat-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.rcc-chat-header {
  background: linear-gradient(135deg, #0A0A0A 0%, #1a1a1a 100%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.rcc-chat-header .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--chat-red);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  letter-spacing: -0.5px;
}
.rcc-chat-header .info { flex: 1; min-width: 0; }
.rcc-chat-header .name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.rcc-chat-header .status {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  display: flex; align-items: center; gap: 6px;
  margin-top: 1px;
}
.rcc-chat-header .status::before {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 6px rgba(52,211,153,.5);
}
.rcc-chat-header .close-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.10);
  color: #fff;
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rcc-chat-header .close-btn:hover { background: rgba(255,255,255,0.16); }

.rcc-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  background: #FAFAFA;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rcc-chat-body::-webkit-scrollbar { width: 6px; }
.rcc-chat-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.rcc-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.rcc-msg.ai {
  background: var(--chat-bubble-ai);
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.rcc-msg.client {
  background: var(--chat-bubble-client);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.rcc-msg.manager {
  background: #fff;
  border: 1px solid var(--chat-border);
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.rcc-msg.manager::before {
  content: 'Менеджер';
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--chat-red);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.rcc-typing {
  align-self: flex-start;
  background: var(--chat-bubble-ai);
  padding: 12px 16px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
}
.rcc-typing span {
  width: 7px; height: 7px;
  background: #999;
  border-radius: 50%;
  animation: rcc-bounce 1.2s ease-in-out infinite;
}
.rcc-typing span:nth-child(2) { animation-delay: .2s; }
.rcc-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes rcc-bounce {
  0%,80%,100% { transform: scale(0.6); opacity: .5; }
  40%        { transform: scale(1);   opacity: 1; }
}

.rcc-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 0;
  background: #FAFAFA;
}
.rcc-sg {
  background: #fff;
  border: 1px solid var(--chat-border);
  color: var(--chat-red);
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.rcc-sg:hover { background: var(--chat-red); color: #fff; border-color: var(--chat-red); }

.rcc-chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--chat-border);
}
.rcc-chat-form input {
  flex: 1;
  border: 1px solid var(--chat-border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  background: #FAFAFA;
}
.rcc-chat-form input:focus { border-color: var(--chat-red); background: #fff; }
.rcc-chat-form button {
  background: var(--chat-red);
  color: #fff;
  border: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.rcc-chat-form button:hover { background: var(--chat-red-light); }
.rcc-chat-form button:disabled { background: #ccc; cursor: not-allowed; }
.rcc-chat-form button svg { width: 18px; height: 18px; }

.rcc-chat-footer-link {
  text-align: center;
  font-size: 11px;
  color: var(--chat-muted);
  padding: 6px 12px 10px;
  background: #fff;
}
.rcc-chat-footer-link a { color: var(--chat-red); text-decoration: none; }
.rcc-chat-footer-link a:hover { text-decoration: underline; }

@media (max-width: 640px) {
  #rcc-chat-toggle { bottom: 76px; right: 14px; width: 54px; height: 54px; }
  #rcc-chat-panel {
    width: 100vw;
    height: calc(100vh - 60px);
    max-height: none;
    bottom: 60px;
    right: 0;
    border-radius: 18px 18px 0 0;
  }
}
