#chat-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

#chat-toggle {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: none;
  border: none;
  box-shadow: 0 4px 20px rgba(184,168,130,0.3);
  transition: background var(--transition), transform var(--transition-fast), box-shadow var(--transition);
  flex-shrink: 0;
}
#chat-toggle:hover {
  background: #ccc0a0;
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(184,168,130,0.4);
}
#chat-toggle:active { transform: scale(0.97); }
#chat-toggle svg { width: 20px; height: 20px; }

#chat-toggle.has-unread::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  animation: pulse 2s ease-in-out infinite;
  opacity: 0;
}

@keyframes pulse {
  0%   { transform: scale(1);    opacity: 0.8; }
  70%  { transform: scale(1.3);  opacity: 0; }
  100% { transform: scale(1.3);  opacity: 0; }
}

#chat-toggle-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--danger);
  color: var(--white);
  font-family: var(--font-main);
  font-size: 10px;
  font-weight: 700;
  border-radius: 100px;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#chat-panel {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  width: 320px;
  height: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
#chat-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.chat-panel-header {
  padding: 14px 18px;
  background: var(--deep);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.chat-panel-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-panel-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(46,204,113,0.5);
}
.chat-panel-status-dot.offline { background: var(--dim); box-shadow: none; }

.chat-panel-title {
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--white);
}

.chat-panel-subtitle {
  font-family: var(--font-body);
  font-size: 10px;
  color: var(--dim);
  margin-top: 2px;
}

.chat-panel-close {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--subtle);
  font-size: 16px;
  line-height: 1;
  cursor: none;
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.chat-panel-close:hover { color: var(--white); background: var(--mid); }

.chat-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.chat-bubble {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 3px;
}
.chat-bubble.visitor { align-self: flex-end; }
.chat-bubble.support { align-self: flex-start; }

.chat-bubble-text {
  padding: 9px 13px;
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  border-radius: 10px;
}
.visitor .chat-bubble-text {
  background: var(--gold);
  color: var(--black);
  border-radius: 10px 10px 4px 10px;
}
.support .chat-bubble-text {
  background: var(--muted);
  border: 1px solid var(--border);
  color: var(--white);
  border-radius: 10px 10px 10px 4px;
}

.chat-bubble-time {
  font-family: var(--font-body);
  font-size: 9px;
  color: var(--dim);
  padding: 0 2px;
}
.visitor .chat-bubble-time { text-align: right; }

.chat-start-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px 14px;
}

.chat-start-welcome {
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  color: var(--white);
  line-height: 1.4;
}
.chat-start-desc {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--dim);
  line-height: 1.6;
  margin-top: -6px;
}

.chat-start-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 13px;
  transition: border-color var(--transition);
}
.chat-start-input::placeholder { color: var(--dim); }
.chat-start-input:focus { border-color: var(--dim); outline: none; }

.chat-start-textarea {
  width: 100%;
  min-height: 72px;
  resize: none;
  padding: 9px 12px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  transition: border-color var(--transition);
}
.chat-start-textarea::placeholder { color: var(--dim); }
.chat-start-textarea:focus { border-color: var(--dim); outline: none; }

.chat-start-submit {
  padding: 10px 16px;
  background: var(--gold);
  color: var(--black);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: var(--radius);
  transition: background var(--transition), transform var(--transition-fast);
  cursor: none;
  width: 100%;
}
.chat-start-submit:hover { background: #ccc0a0; }
.chat-start-submit:active { transform: scale(0.99); }

.chat-start-error {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--danger);
  display: none;
}
.chat-start-error.visible { display: block; }

.chat-panel-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--deep);
  flex-shrink: 0;
}

.chat-panel-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 13px;
  transition: border-color var(--transition);
}
.chat-panel-input::placeholder { color: var(--dim); }
.chat-panel-input:focus { border-color: var(--dim); outline: none; }

.chat-panel-send {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: var(--black);
  border-radius: var(--radius);
  cursor: none;
  transition: background var(--transition), transform var(--transition-fast);
  flex-shrink: 0;
}
.chat-panel-send:hover { background: #ccc0a0; }
.chat-panel-send:active { transform: scale(0.95); }
.chat-panel-send svg { width: 16px; height: 16px; }

.chat-closed-notice {
  padding: 12px 16px;
  background: rgba(192,57,43,0.08);
  border-top: 1px solid rgba(192,57,43,0.2);
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--danger);
  text-align: center;
  flex-shrink: 0;
  line-height: 1.5;
}
.chat-closed-new-btn {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--subtle);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: none;
  transition: color var(--transition);
}
.chat-closed-new-btn:hover { color: var(--white); }

.chat-system-msg {
  align-self: center;
  padding: 4px 10px;
  background: var(--muted);
  border-radius: 100px;
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--dim);
  font-style: italic;
}

@media (max-width: 420px) {
  #chat-widget { bottom: 16px; right: 16px; }
  #chat-panel { width: calc(100vw - 32px); height: calc(100vh - 100px); }
}
