/* CSG Chat widget — embeddable styles
 * CSG red + black brand palette.
 * All selectors are namespaced under #csg-chat-root.
 */

#csg-chat-root {
  --csg-red: #D71920;
  --csg-red-dark: #A8121A;
  --csg-black: #0A0A0A;
  --csg-bg: #F5F5F7;
  --csg-border: #E5E5E5;
  --csg-text: #0A0A0A;
  --csg-muted: #6B6B6B;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--csg-text);
}

#csg-chat-root * { box-sizing: border-box; }

#csg-chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 30px;
  background: var(--csg-red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(215, 25, 32, 0.35);
  z-index: 2147483646;
  transition: transform 0.15s ease;
  border: none;
}
#csg-chat-bubble:hover { transform: scale(1.06); }
#csg-chat-bubble svg { width: 28px; height: 28px; }

#csg-chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--csg-black);
  color: #fff;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  min-width: 20px;
  text-align: center;
  display: none;
  border: 2px solid #fff;
}
#csg-chat-unread.show { display: block; }

#csg-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 360px;
  height: 540px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.30);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483647;
  border: 1px solid var(--csg-border);
}
#csg-chat-window.open { display: flex; }

.csg-chat-header {
  background: var(--csg-black);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--csg-red);
}
.csg-chat-title {
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.csg-chat-title .csg-mark {
  background: var(--csg-red);
  color: #fff;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 10px;
  letter-spacing: -0.04em;
}
.csg-chat-sub { font-size: 11px; opacity: 0.75; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.csg-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: #4ade80;
  display: inline-block;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
}

.csg-chat-close {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 13px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.csg-chat-pretext {
  padding: 16px;
  background: #fff;
  border-bottom: 1px solid var(--csg-border);
  overflow-y: auto;
}
.csg-pretext-intro {
  font-size: 13px;
  color: var(--csg-muted);
  margin-bottom: 12px;
}
.csg-pretext-intro strong { color: var(--csg-text); }
.csg-pretext-field {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--csg-border);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 8px;
  font-family: inherit;
  outline: none;
}
.csg-pretext-field:focus { border-color: var(--csg-red); }
.csg-pretext-row { display: flex; gap: 8px; }
.csg-pretext-row .csg-pretext-field { flex: 1; }
.csg-pretext-start {
  width: 100%;
  background: var(--csg-red);
  color: #fff;
  border: none;
  padding: 11px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  margin-top: 6px;
  font-family: inherit;
}
.csg-pretext-start:hover { background: var(--csg-red-dark); }
.csg-dept-select { display: flex; gap: 8px; margin-bottom: 12px; }
.csg-dept-btn {
  flex: 1;
  background: #fff;
  border: 1.5px solid var(--csg-border);
  padding: 10px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--csg-text);
  font-family: inherit;
}
.csg-dept-btn.active {
  background: var(--csg-black);
  color: #fff;
  border-color: var(--csg-black);
}

.csg-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #fafafa;
}
.csg-msg {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  word-wrap: break-word;
  line-height: 1.4;
}
.csg-msg.system {
  align-self: center;
  background: transparent;
  color: var(--csg-muted);
  font-size: 11px;
  font-style: italic;
  padding: 2px 0;
}
.csg-msg.agent {
  align-self: flex-start;
  background: #ECECEC;
  color: var(--csg-text);
  border-bottom-left-radius: 4px;
}
.csg-msg.visitor {
  align-self: flex-end;
  background: var(--csg-red);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.csg-typing {
  align-self: flex-start;
  background: #ECECEC;
  padding: 12px 14px;
  border-radius: 14px;
  display: none;
  gap: 4px;
}
.csg-typing.show { display: flex; }
.csg-typing span {
  width: 6px; height: 6px;
  background: var(--csg-muted);
  border-radius: 3px;
  animation: csg-bounce 1.2s infinite;
}
.csg-typing span:nth-child(2) { animation-delay: 0.15s; }
.csg-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes csg-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.csg-chat-input {
  border-top: 1px solid var(--csg-border);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  background: #fff;
}
.csg-chat-input input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--csg-border);
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.csg-chat-input input:focus { border-color: var(--csg-red); }
.csg-chat-send {
  background: var(--csg-red);
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 19px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 480px) {
  #csg-chat-window {
    width: 100vw;
    height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }
}
