daichyai-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9999;
  color: #173247;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, sans-serif;
}

daichyai-chat,
daichyai-chat * {
  box-sizing: border-box;
}

daichyai-chat button,
daichyai-chat textarea {
  font: inherit;
}

daichyai-chat button {
  cursor: pointer;
}

daichyai-chat .d-launch {
  display: block;
  width: 66px;
  height: 66px;
  padding: 4px;
  border: 1px solid #c2d4e3;
  border-radius: 50%;
  background: #edf4fa;
  box-shadow: 0 5px 30px #17324730;
}

daichyai-chat .d-avatar {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

daichyai-chat dialog {
  position: fixed;
  inset: auto 22px 102px auto;
  display: none;
  flex-direction: column;
  width: min(390px, calc(100vw - 32px));
  max-height: calc(100dvh - 124px);
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #c8d8e1;
  border-radius: 22px;
  background: #fbfdff;
  color: inherit;
  box-shadow: 0 14px 60px #102f4640;
}

daichyai-chat dialog[open] {
  display: flex;
}

daichyai-chat dialog::backdrop {
  background: #102f4612;
}

daichyai-chat header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px;
  border-bottom: 1px solid #dde7ed;
}

daichyai-chat header .d-avatar {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
}

daichyai-chat header strong {
  display: block;
}

daichyai-chat header button {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 2px 8px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 24px;
}

daichyai-chat .d-note {
  flex: 0 0 auto;
  margin: 8px 0;
  padding: 0 16px;
  color: #566b7c;
  font-size: 12px;
}

daichyai-chat .d-history {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  padding: 0 16px;
  overflow: auto;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  overscroll-behavior: contain;
}

daichyai-chat .d-history p {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #edf3f7;
}

daichyai-chat .d-history p[data-role="user"] {
  background: #dcebf2;
}

daichyai-chat .d-history p[data-role="sources"] {
  padding: 4px 2px;
  background: transparent;
  color: #566b7c;
  font-size: 12px;
}

daichyai-chat form {
  display: grid;
  flex: 0 0 auto;
  gap: 10px;
  min-width: 0;
  padding: 12px 16px 16px;
  border-top: 1px solid #e5edf1;
}

daichyai-chat label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

daichyai-chat textarea {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 92px;
  max-height: 150px;
  resize: vertical;
  padding: 10px 11px;
  border: 1px solid #b5c9d6;
  border-radius: 11px;
  background: #fff;
  color: #173247;
  line-height: 1.45;
}

daichyai-chat .d-status {
  margin-top: 4px;
}

daichyai-chat .d-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

daichyai-chat .d-actions button {
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid #b5c9d6;
  border-radius: 10px;
  background: #f5f8fa;
  color: #173247;
}

daichyai-chat .d-actions button[type="submit"] {
  border-color: #173247;
  background: #173247;
  color: #fff;
}

daichyai-chat button:disabled {
  cursor: wait;
  opacity: .5;
}

daichyai-chat :focus-visible {
  outline: 3px solid #167d9d;
  outline-offset: 3px;
}

@media (max-width: 500px) {
  daichyai-chat {
    right: 12px;
    bottom: 12px;
  }

  daichyai-chat dialog {
    right: 12px;
    bottom: 88px;
    left: 12px;
    width: auto;
    max-width: none;
    max-height: calc(100dvh - 106px);
    border-radius: 18px;
  }

  daichyai-chat form {
    padding: 10px 12px 12px;
  }
}

@media (max-height: 650px) {
  daichyai-chat dialog {
    max-height: calc(100dvh - 108px);
  }

  daichyai-chat header {
    padding: 10px 14px;
  }

  daichyai-chat .d-note {
    margin: 6px 0;
    font-size: 11px;
  }

  daichyai-chat .d-history {
    min-height: 24px;
  }

  daichyai-chat textarea {
    min-height: 68px;
  }
}

@media (prefers-reduced-motion: reduce) {
  daichyai-chat * {
    scroll-behavior: auto;
  }
}
