.chat-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 300px;
  height: 400px;
  background: var(--surface, #ffffff);
  border-radius: var(--radius-lg, 18px);
  box-shadow: var(--shadow-soft, 0 18px 40px rgba(15, 23, 42, 0.12));
  display: flex;
  flex-direction: column;
  z-index: 1000;
  border: 1px solid var(--border, #e5e7eb);
  font-family: var(--font-sans, "Segoe UI", sans-serif);
}

.chat-header {
  background: var(--primary, #2563eb);
  color: #fff;
  padding: 10px;
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  letter-spacing: 0.01em;
}

.chat-header span {
  font-weight: bold;
}

#chat-toggle {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  border-radius: 999px;
  padding: 2px 8px;
  transition: background-color 180ms ease;
}

#chat-toggle:hover,
#chat-toggle:focus-visible {
  background: rgba(255, 255, 255, 0.28);
}

.chat-messages {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  background: var(--surface-muted, #eef1f7);
}

.chat-input {
  display: flex;
  padding: 10px;
  gap: 0.5rem;
  border-top: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #ffffff);
}

#chat-input {
  flex: 1;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-sm, 8px);
  font-size: 14px;
}

#chat-send {
  padding: 0.6rem 1.1rem;
  background: var(--primary, #2563eb);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(37, 99, 235, 0.25);
  transition: transform 160ms ease, box-shadow 160ms ease,
    background-color 200ms ease;
}

#chat-send:hover,
#chat-send:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.3);
}

#chat-send:focus-visible,
#chat-input:focus-visible,
#chat-toggle:focus-visible,
#chat-open-btn:focus-visible {
  outline: 2px solid var(--primary, #2563eb);
  outline-offset: 2px;
}

.message {
  margin: 5px 0;
  padding: 8px;
  border-radius: var(--radius-sm, 8px);
  white-space: pre-line;
  max-width: 80%;
  font-size: 0.95rem;
  letter-spacing: 0.005em;
  line-height: 1.55;
}

.message.user {
  background: var(--primary, #2563eb);
  color: #fff;
  margin-left: 20%;
  margin-right: 5px;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.22);
}

.message.bot {
  background: var(--surface, #ffffff);
  color: var(--text, #1f2937);
  margin-right: 20%;
  margin-left: 5px;
  border: 1px solid var(--border, #e5e7eb);
}

.message.loading {
  background: var(--surface, #ffffff);
  color: var(--text-muted, #6b7280);
  margin-right: 20%;
  margin-left: 5px;
  font-style: italic;
}

.chat-image {
  max-width: 80%;
  max-height: 150px;
  margin: 5px 0;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--border, #e5e7eb);
}

#chat-open-container {
  z-index: 1000;
}

#chat-open-btn img {
  width: 60px;
  height: 60px;
  transition: transform 0.3s;
}

#chat-open-btn img:hover {
  transform: scale(1.1);
}

#chat-note {
  color: #fff;
  font-size: 14px;
  margin-bottom: 5px;
}

.hidden {
  display: none;
}

.message.bot a {
  color: var(--primary, #2563eb);
  text-decoration: underline;
}

/* Mobile devices (phones, <500px) */
@media (max-width: 500px) {
  .chat-container.chat-phone {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90vw;
    max-width: 400px;
    height: 70vh;
    max-height: 80vh;
    min-height: 300px;
    font-size: 14px;
    border-radius: 10px;
    background: white;
    z-index: 1000;
  }

  .chat-header {
    padding: 8px;
    font-size: 14px;
  }

  .chat-messages {
    padding: 8px;
    overflow-y: auto;
  }

  .message {
    max-width: 85%;
    font-size: 14px;
    padding: 6px 10px;
  }

  .chat-input {
    padding: 8px;
  }

  #chat-input {
    font-size: 14px;
    padding: 6px;
  }

  #chat-send {
    padding: 6px 10px;
    font-size: 14px;
    margin-left: 5px;
  }

  #chat-open-container.container-phone {
    bottom: 10px;
    right: 10px;
  }

  #chat-open-btn img {
    width: 50px;
    height: 50px;
  }

  #chat-note {
    font-size: 12px;
    margin-bottom: 3px;
  }

  .chat-image {
    max-width: 90%;
    max-height: 120px;
  }
}

/* Tablets (600px - 1024px) */
@media (min-width: 601px) and (max-width: 1024px) {
  .chat-container.chat-tablet {
    width: 80vw;
    height: 60vh;
    bottom: 15px;
    right: 15px;
    font-size: 15px;
  }

  .chat-header {
    padding: 9px;
    font-size: 15px;
  }

  .chat-messages {
    padding: 9px;
  }

  .message {
    max-width: 82%;
    font-size: 15px;
    padding: 7px 11px;
  }

  .chat-input {
    padding: 9px;
  }

  #chat-input {
    font-size: 15px;
    padding: 6px;
  }

  #chat-send {
    padding: 6px 11px;
    font-size: 15px;
    margin-left: 8px;
  }

  #chat-open-container.container-tablet {
    bottom: 15px;
    right: 15px;
  }

  #chat-open-btn img {
    width: 55px;
    height: 55px;
  }

  .chat-image {
    max-width: 85%;
    max-height: 140px;
  }
}

/* PCs (>1024px) */
@media (min-width: 1025px) {
  .chat-container.chat-pc {
    width: 300px;
    height: 400px;
    bottom: 20px;
    right: 20px;
    font-size: 16px;
  }

  .chat-image {
    max-width: 80%;
    max-height: 150px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #chat-open-btn img,
  #chat-send,
  nav a,
  .message,
  .chat-container,
  #chat-toggle {
    transition-duration: 0.001ms !important;
    transition-property: none !important;
  }
}
