*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans',
    'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Meiryo', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #333;
  background: #fff;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#chat-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #fff;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 16px;
  background: linear-gradient(135deg, #1a365d 0%, #2d4a7a 100%);
  color: #fff;
  flex-shrink: 0;
  user-select: none;
  position: relative;
}

.chat-header-close {
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.15s;
  line-height: 1;
  padding: 0;
}

.chat-header-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  line-height: 1;
}

.chat-header-icon-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

.chat-header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.chat-banner-img {
  width: 100%;
  display: block;
  object-fit: cover;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fa;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

.chat-message {
  display: flex;
  max-width: 80%;
  animation: message-fade-in 0.3s ease;
}

@keyframes message-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message-user {
  flex-direction: column;
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message-ai {
  flex-direction: row;
  align-self: flex-start;
  align-items: flex-start;
  gap: 8px;
}

.chat-ai-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  align-self: flex-end;
}

.chat-message-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-message-user .chat-message-content {
  align-items: flex-end;
}

.chat-message-ai .chat-message-content {
  align-items: flex-start;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  word-break: break-word;
  line-height: 1.6;
  font-size: 14px;
  overflow: hidden;
}

.chat-bubble-user {
  background: #3182ce;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble-ai {
  background: #fff;
  color: #333;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.chat-tel-link {
  color: #0066cc;
  text-decoration: underline;
}

.chat-image-container {
  margin: 8px -14px;
  line-height: 0;
}

.chat-inline-image {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
  padding: 0 14px;
}

.chat-inline-image:hover {
  opacity: 0.85;
}

.chat-image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-image-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
}

.chat-image-modal-content {
  position: relative;
  z-index: 1;
  max-width: 90%;
  max-height: 90%;
}

.chat-image-modal-img {
  max-width: 100%;
  max-height: 85vh;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.chat-image-modal-close {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: #333;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-image-modal-close:hover {
  background: #eee;
}

.chat-after-answer {
  margin-top: 8px;
  line-height: 1.6;
}

.chat-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  padding: 0 4px;
}

.chat-feedback-btn {
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  transition: filter 0.15s ease, box-shadow 0.15s ease;
  line-height: 1.4;
}

.chat-feedback-good {
  background: #1a56a0;
}

.chat-feedback-bad {
  background: #c0392b;
}

.chat-feedback-btn:hover {
  filter: brightness(1.15);
}

.chat-feedback-btn.active {
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.25);
  filter: brightness(0.9);
}

.chat-time {
  font-size: 11px;
  color: #a0aec0;
  margin-top: 4px;
  padding: 0 4px;
}

.chat-typing {
  display: flex;
  gap: 5px;
  padding: 4px 0;
  align-items: center;
}

.chat-typing-dot {
  width: 8px;
  height: 8px;
  background: #a0aec0;
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.chat-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.chat-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.chat-typing-dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}

.chat-input-wrapper {
  position: relative;
  margin-bottom: 22px;
}

.chat-input-clear {
  position: absolute;
  top: 8px;
  right: 18px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: #718096;
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 1;
  transition: background 0.2s;
}
.chat-input-clear:hover {
  background: #4a5568;
}
.chat-input-clear.visible {
  display: flex;
}

.chat-input {
  width: 100%;
  padding: 10px 12px;
  padding-bottom: 24px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
  max-height: 100px;
  color: #333;
  background: #fff;
}

.chat-input::placeholder {
  color: #a0aec0;
}

.chat-input:focus {
  border-color: #3182ce;
  box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.15);
}

.chat-input.over-limit {
  border-color: #e53e3e;
  box-shadow: 0 0 0 2px rgba(229, 62, 62, 0.15);
}

.chat-input.over-limit:focus {
  border-color: #e53e3e;
  box-shadow: 0 0 0 2px rgba(229, 62, 62, 0.25);
}

.chat-input:disabled {
  background: #f7fafc;
  color: #a0aec0;
  cursor: not-allowed;
}

.chat-char-count {
  position: absolute;
  bottom: 6px;
  right: 12px;
  font-size: 11px;
  color: #a0aec0;
  pointer-events: none;
  transition: color 0.2s;
}

.chat-char-count.warning {
  color: #e53e3e;
  font-weight: 600;
}

.chat-char-count.over {
  color: #e53e3e;
  font-weight: 700;
}

.chat-input-error {
  position: absolute;
  bottom: -18px;
  left: 4px;
  font-size: 11px;
  color: #e53e3e;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.chat-input-error.visible {
  opacity: 1;
  transform: translateY(0);
}

.chat-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.chat-terms {
  text-align: center;
  padding: 4px 0 2px;
}
.chat-terms a {
  font-size: 11px;
  color: #8a9ab5;
  text-decoration: underline;
}
.chat-terms a:hover {
  text-decoration: underline;
  color: #5a6a85;
}

.chat-btn {
  padding: 8px 20px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, opacity 0.2s;
  border: none;
  line-height: 1.4;
}

.chat-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-btn-send {
  background: #1a365d;
  color: #fff;
  flex: 1;
}

.chat-btn-send:hover:not(:disabled) {
  background: #2d4a7a;
}

.chat-btn-send:active:not(:disabled) {
  background: #15294a;
}

.chat-btn-reset {
  background: #fff;
  color: #718096;
  border: 1px solid #e2e8f0;
}

.chat-btn-reset:hover:not(:disabled) {
  background: #f7fafc;
  border-color: #cbd5e0;
}

.chat-btn-reset:active:not(:disabled) {
  background: #edf2f7;
}

.chat-btn-mic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  color: #718096;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

.chat-btn-mic:hover {
  background: #f7fafc;
  border-color: #cbd5e0;
  color: #4a5568;
}

.chat-btn-mic:active {
  background: #edf2f7;
}

.chat-btn-mic.recording {
  background: #e53e3e;
  color: #fff;
  border-color: #e53e3e;
  animation: mic-pulse 1.5s ease-in-out infinite;
}

.chat-btn-mic.recording:hover {
  background: #c53030;
  border-color: #c53030;
  color: #fff;
}

.mic-icon {
  display: block;
  width: 20px;
  height: 20px;
}

@keyframes mic-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(229, 62, 62, 0);
  }
}

body.theme-dark #chat-app {
  background: #1a202c;
}

body.theme-dark .chat-messages {
  background: #2d3748;
}

body.theme-dark .chat-bubble-ai {
  background: #4a5568;
  color: #e2e8f0;
  border-color: #4a5568;
}

body.theme-dark .chat-time {
  color: #718096;
}

body.theme-dark .chat-feedback-btn:hover {
  filter: brightness(1.2);
}

body.theme-dark .chat-feedback-btn.active {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
  filter: brightness(0.85);
}

body.theme-dark .chat-input-area {
  background: #1a202c;
  border-top-color: #4a5568;
}

body.theme-dark .chat-input {
  background: #2d3748;
  color: #e2e8f0;
  border-color: #4a5568;
}

body.theme-dark .chat-input::placeholder {
  color: #718096;
}

body.theme-dark .chat-input:focus {
  border-color: #63b3ed;
  box-shadow: 0 0 0 2px rgba(99, 179, 237, 0.2);
}

body.theme-dark .chat-btn-reset {
  background: #2d3748;
  color: #a0aec0;
  border-color: #4a5568;
}

body.theme-dark .chat-btn-reset:hover:not(:disabled) {
  background: #4a5568;
}

body.theme-dark .chat-btn-mic {
  background: #2d3748;
  color: #a0aec0;
  border-color: #4a5568;
}

body.theme-dark .chat-btn-mic:hover {
  background: #4a5568;
  color: #e2e8f0;
}

body.theme-dark .chat-btn-mic.recording {
  background: #e53e3e;
  color: #fff;
  border-color: #e53e3e;
}

body.theme-dark .chat-char-count {
  color: #718096;
}

body.theme-dark .chat-input.over-limit {
  border-color: #fc8181;
  box-shadow: 0 0 0 2px rgba(252, 129, 129, 0.2);
}

body.theme-dark .chat-input.over-limit:focus {
  border-color: #fc8181;
  box-shadow: 0 0 0 2px rgba(252, 129, 129, 0.3);
}

body.theme-dark .chat-input-error {
  color: #fc8181;
}

body.theme-dark .chat-image-modal-close {
  background: #4a5568;
  color: #e2e8f0;
}

body.theme-dark .chat-image-modal-close:hover {
  background: #718096;
}

@media (max-width: 480px) {
  .chat-bubble {
    font-size: 13px;
  }

  .chat-message {
    max-width: 88%;
  }

  .chat-input-area {
    padding: 10px 12px;
  }
}
