:root {
  --chat-primary: #0d5c63;
  --chat-primary-dark: #084c52;
  --chat-accent: #e35d2f;
  --chat-text: #1f2937;
  --chat-muted: #59687a;
  --chat-border: #dfe8e6;
  --chat-radius: 14px;
}

[data-chat-widget] {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1200;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Roboto, Arial, sans-serif;
}

.chat-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 22px;
  color: #fff;
  background: var(--chat-primary);
  border: none;
  border-radius: 999px;
  box-shadow: 0 8px 26px rgba(13, 92, 99, .32);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.chat-launcher:hover {
  background: var(--chat-primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(13, 92, 99, .4);
}
.chat-launcher-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.chat-launcher-icon svg { display: block; }
.chat-launcher b { font-weight: 700; }
.chat-launcher-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--chat-accent);
  box-shadow: 0 0 0 3px rgba(227, 93, 47, .3);
  animation: chat-pulse 2s ease-in-out infinite;
}
@keyframes chat-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

.chat-panel {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 370px;
  max-width: calc(100vw - 32px);
  max-height: 560px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: 0 20px 60px rgba(13, 92, 99, .22);
  overflow: hidden;
}
.chat-panel[hidden] { display: none; }

.chat-panel header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--chat-primary);
  color: #fff;
}
.chat-panel header strong {
  display: block;
  font-size: 1rem;
  font-weight: 750;
  color: #fff;
}
.chat-panel header small {
  display: block;
  color: rgba(255, 255, 255, .8);
  font-size: .82rem;
}
.chat-agent-avatar { flex: 0 0 auto; }
.chat-agent-avatar svg { display: block; border-radius: 50%; }
.chat-panel header > div { flex: 1; min-width: 0; }
.chat-panel header button {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: #fff;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease;
}
.chat-panel header button:hover { background: rgba(255, 255, 255, .15); }

.chat-messages {
  flex: 1;
  min-height: 180px;
  max-height: 320px;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f9fbfa;
}

.chat-message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: .92rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat-message-admin,
.chat-message.admin {
  align-self: flex-start;
  color: var(--chat-text);
  background: #e8f5f2;
  border: 1px solid #d0e8e3;
  border-bottom-left-radius: 4px;
}
.chat-message.visitor {
  align-self: flex-end;
  color: #fff;
  background: var(--chat-primary);
  border-bottom-right-radius: 4px;
}
.chat-message-admin, .chat-message.admin { color: var(--chat-text); }

.chat-panel form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 18px 16px;
  background: #fff;
  border-top: 1px solid var(--chat-border);
}
.chat-panel form .hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.chat-panel form input[type="text"],
.chat-panel form textarea {
  width: 100%;
  padding: 10px 12px;
  color: var(--chat-text);
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  font: inherit;
  font-size: .92rem;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.chat-panel form input[type="text"]:focus,
.chat-panel form textarea:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px rgba(13, 92, 99, .1);
}
.chat-panel form textarea {
  resize: vertical;
  min-height: 60px;
  max-height: 120px;
}
.chat-panel form > div {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-panel form > div textarea { flex: 1; }
.chat-panel form button[type="submit"] {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--chat-accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.chat-panel form button[type="submit"]:hover {
  background: #d04d22;
  transform: translateY(-1px);
}
.chat-panel form button[type="submit"]:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}
.chat-panel form button[type="submit"] svg { display: block; }

.chat-panel form [data-chat-status] {
  margin: 0;
  min-height: 0;
  color: var(--chat-accent);
  font-size: .85rem;
  font-weight: 600;
}
.chat-panel form [data-chat-status]:empty { display: none; }

@media (max-width: 640px) {
  [data-chat-widget] {
    bottom: max(16px, env(safe-area-inset-bottom));
    right: max(16px, env(safe-area-inset-right));
    left: auto;
  }
  .chat-launcher {
    width: 48px;
    height: 48px;
    justify-content: center;
    min-height: 48px;
    padding: 0;
    border-radius: 50%;
    font-size: .9rem;
  }
  .chat-launcher b { display: none; }
  .chat-launcher-icon svg { width: 20px; height: 20px; }
  .chat-panel {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(76px, calc(env(safe-area-inset-bottom) + 64px));
    left: max(12px, env(safe-area-inset-left));
    width: auto;
    max-width: none;
    max-height: none;
  }
  .chat-panel header { padding: 13px 14px; }
  .chat-messages { min-height: 0; max-height: none; padding: 13px 14px; }
  .chat-panel form { padding: 12px 14px 14px; }
}
