.ditano-chat {
  position: fixed;
  z-index: 40;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
}

.chat-launcher,
.chat-icon-btn,
.chat-send {
  font: inherit;
}

.chat-launcher {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: #141414;
  color: #ffffff;
  cursor: pointer;
}

.chat-launcher:hover {
  border-color: rgba(255, 255, 255, 0.45);
}

.ditano-chat:not([data-state="closed"]) .chat-launcher {
  display: none;
}

.ditano-chat .chat-panel[hidden],
.chat-panel [hidden] {
  display: none;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(640px, calc(100dvh - 32px));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  background: #121212;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  transform-origin: bottom right;
  animation: chat-in 220ms ease;
}

.ditano-chat[data-state="open"] .chat-panel {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
}

.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 8px 16px;
}

.chat-head-copy h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
}

.chat-head-copy p {
  margin: 2px 0 0;
  color: #a8a8a8;
  font-size: 12px;
  line-height: 1.5;
}

.chat-icon-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #d6d6d6;
  cursor: pointer;
}

.chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.chat-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  height: 1.4em;
  padding: 4px 0;
}

.chat-dots i {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #d6d6d6;
  animation: chat-dot 1.05s infinite ease-in-out;
}

.chat-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.chat-empty {
  margin: 8px 0 0;
  color: #a8a8a8;
  font-size: 16px;
}

.chat-msg {
  margin: 0 0 14px;
  max-width: 100%;
}

.chat-msg p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-msg-user {
  display: flex;
  justify-content: flex-end;
}

.chat-msg-user p {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 18px;
  background: #2a2a2a;
  color: #f2f2f2;
}

.chat-msg-assistant p {
  color: #ffffff;
}

.chat-form {
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
}

.chat-pill {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 4px 6px 4px 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 28px;
  background: #1c1c1c;
}

.chat-pill textarea {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  margin: 0;
  padding: 10px 0;
  border: 0;
  resize: none;
  background: transparent;
  color: #ffffff;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  caret-color: #ffffff;
}

.chat-pill textarea::placeholder {
  color: #a8a8a8;
}

.chat-pill textarea:focus {
  outline: none;
}

.chat-send {
  background: #f4f4f4;
  color: #111111;
}

.chat-send:disabled {
  background: transparent;
  color: #a8a8a8;
  cursor: default;
}

.chat-send:disabled:hover {
  background: transparent;
}

.chat-icon-btn.is-listening {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.chat-launcher:focus-visible,
.chat-icon-btn:focus-visible,
.chat-pill:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.chat-pill:focus-within {
  outline-offset: 2px;
}

@keyframes chat-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 700px) {
  .ditano-chat[data-state="open"] .chat-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(92dvh, 100%);
    border-radius: 20px 20px 0 0;
    transform-origin: bottom center;
  }
}

@keyframes chat-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel,
  .chat-dots i {
    animation: none;
    transition: none;
  }
}

@media (forced-colors: active) {
  .chat-panel,
  .chat-launcher,
  .chat-pill {
    border: 1px solid CanvasText;
  }
}
