.ai-chat-widget {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 140;
  display: flex;
  align-items: center;
  width: 424px;
  height: min(560px, 78vh);
  color: var(--text-light);
  transform: translate(360px, -50%);
  transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
  overscroll-behavior: contain;
}

.ai-chat-widget:hover,
.ai-chat-widget.is-open,
.ai-chat-widget:focus-within {
  transform: translate(0, -50%);
}

.ai-chat-tab {
  position: relative;
  z-index: 2;
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  flex: 0 0 auto;
  color: var(--black);
  background: var(--gold);
  border: 2px solid var(--black);
  border-right: 2px solid var(--black);
  border-radius: 8px 0 0 8px;
  box-shadow: -10px 14px 34px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

.ai-chat-face {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
}

.ai-chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 368px;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgba(0, 0, 0, 0.96);
  border: 2px solid var(--gold);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  box-shadow: -20px 24px 70px rgba(0, 0, 0, 0.42);
}

.ai-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 215, 0, 0.24);
  background: linear-gradient(180deg, rgba(255, 215, 0, 0.12), rgba(0, 0, 0, 0));
}

.ai-chat-title {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
}

.ai-chat-title strong {
  display: block;
  color: var(--gold);
  font-size: 15px;
  line-height: 1.2;
}

.ai-chat-title span {
  display: block;
  margin-top: 2px;
  color: rgba(255, 215, 0, 0.68);
  font-size: 11px;
  line-height: 1.2;
}

.ai-chat-key,
.ai-chat-human,
.ai-chat-end-human {
  min-width: 52px;
  min-height: 34px;
  padding: 0 10px;
  flex: 0 0 auto;
  color: var(--gold);
  background: rgba(255, 215, 0, 0.08);
  border: 1px solid rgba(255, 215, 0, 0.34);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
}

.ai-chat-end-human {
  color: #ff9b92;
  border-color: rgba(255, 119, 105, 0.55);
}

.ai-chat-close {
  display: none;
  width: 34px;
  height: 34px;
  place-items: center;
  flex: 0 0 auto;
  color: var(--gold);
  background: transparent;
  border: 1px solid rgba(255, 215, 0, 0.34);
  border-radius: 6px;
  cursor: pointer;
}

.ai-chat-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 215, 0, 0.55) transparent;
}

.ai-chat-body::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-body::-webkit-scrollbar-thumb {
  background: rgba(255, 215, 0, 0.45);
  border-radius: 999px;
}

.ai-chat-message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

.ai-chat-message.is-user {
  flex-direction: row-reverse;
}

.ai-chat-avatar {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  flex: 0 0 auto;
  color: var(--black);
  background: var(--gold);
  border-radius: 8px;
  font-size: 10px;
  font-weight: 900;
}

.ai-chat-message.is-user .ai-chat-avatar {
  color: var(--gold);
  background: rgba(255, 215, 0, 0.12);
  border: 1px solid rgba(255, 215, 0, 0.35);
}

.ai-chat-bubble {
  max-width: min(270px, 78%);
  padding: 10px 12px;
  color: rgba(255, 255, 255, 0.88);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 215, 0, 0.18);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.55;
  white-space: normal;
  overflow-wrap: anywhere;
}

.ai-chat-message.is-user .ai-chat-bubble {
  color: var(--black);
  background: var(--gold);
  border-color: var(--gold);
  font-weight: 700;
}

.ai-chat-bubble p {
  margin: 0 0 8px;
}

.ai-chat-bubble p:last-child,
.ai-chat-bubble ul:last-child,
.ai-chat-bubble ol:last-child,
.ai-chat-bubble blockquote:last-child,
.ai-chat-bubble pre:last-child,
.ai-chat-table-wrap:last-child {
  margin-bottom: 0;
}

.ai-chat-bubble h3,
.ai-chat-bubble h4,
.ai-chat-bubble h5,
.ai-chat-bubble h6 {
  margin: 8px 0 6px;
  color: var(--gold);
  font-size: 13px;
  line-height: 1.35;
}

.ai-chat-message.is-user .ai-chat-bubble h3,
.ai-chat-message.is-user .ai-chat-bubble h4,
.ai-chat-message.is-user .ai-chat-bubble h5,
.ai-chat-message.is-user .ai-chat-bubble h6 {
  color: var(--black);
}

.ai-chat-bubble ul,
.ai-chat-bubble ol {
  margin: 6px 0 8px;
  padding-left: 18px;
}

.ai-chat-bubble li + li {
  margin-top: 4px;
}

.ai-chat-bubble blockquote {
  margin: 8px 0;
  padding-left: 10px;
  color: rgba(255, 255, 255, 0.74);
  border-left: 2px solid rgba(255, 215, 0, 0.45);
}

.ai-chat-message.is-user .ai-chat-bubble blockquote {
  color: rgba(0, 0, 0, 0.72);
  border-left-color: rgba(0, 0, 0, 0.42);
}

.ai-chat-bubble code {
  padding: 1px 4px;
  color: #fff4a8;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 4px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.ai-chat-message.is-user .ai-chat-bubble code {
  color: var(--black);
  background: rgba(0, 0, 0, 0.12);
}

.ai-chat-bubble pre {
  max-width: 100%;
  margin: 8px 0;
  padding: 9px 10px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 215, 0, 0.18);
  border-radius: 7px;
}

.ai-chat-bubble pre code {
  display: block;
  padding: 0;
  color: rgba(255, 255, 255, 0.86);
  background: transparent;
  white-space: pre;
}

.ai-chat-table-wrap {
  max-width: 100%;
  margin: 8px 0;
  overflow: auto;
}

.ai-chat-bubble table {
  width: 100%;
  min-width: 220px;
  border-collapse: collapse;
  font-size: 12px;
}

.ai-chat-bubble th,
.ai-chat-bubble td {
  padding: 6px 7px;
  text-align: left;
  border: 1px solid rgba(255, 215, 0, 0.22);
}

.ai-chat-bubble th {
  color: var(--gold);
  background: rgba(255, 215, 0, 0.08);
}

.ai-chat-message.is-user .ai-chat-bubble th,
.ai-chat-message.is-user .ai-chat-bubble td {
  border-color: rgba(0, 0, 0, 0.28);
}

.ai-chat-message.is-user .ai-chat-bubble th {
  color: var(--black);
  background: rgba(0, 0, 0, 0.08);
}

.ai-chat-bubble a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-chat-message.is-user .ai-chat-bubble a {
  color: var(--black);
}

.ai-chat-foot {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255, 215, 0, 0.24);
  background: rgba(0, 0, 0, 0.72);
}

.ai-chat-file {
  display: none;
}

.ai-chat-image-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  color: rgba(255, 215, 0, 0.82);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 215, 0, 0.22);
  border-radius: 8px;
}

.ai-chat-image-preview[hidden] {
  display: none;
}

.ai-chat-image-preview img {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 6px;
}

.ai-chat-image-preview.is-document img {
  display: none;
}

.ai-chat-image-preview.is-document::before {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  flex: 0 0 auto;
  color: var(--black);
  content: "FILE";
  background: var(--gold);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 900;
}

.ai-chat-image-preview span {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-image-remove,
.ai-chat-attach {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--gold);
  background: rgba(255, 215, 0, 0.08);
  border: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: 8px;
  cursor: pointer;
}

.ai-chat-image-remove {
  width: 28px;
  height: 28px;
  font-size: 14px;
  font-weight: 900;
}

.ai-chat-attach {
  width: 42px;
  height: 42px;
  color: var(--black);
  background: var(--gold);
  border-color: var(--gold);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.ai-chat-attach:disabled {
  cursor: wait;
  opacity: 0.62;
}

.ai-chat-input {
  width: 100%;
  min-height: 42px;
  max-height: 108px;
  resize: none;
  flex: 1 1 auto;
  padding: 10px 12px;
  color: var(--text-light);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 215, 0, 0.28);
  border-radius: 8px;
  outline: none;
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
}

.ai-chat-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.12);
}

.ai-chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 42px;
  flex: 0 0 auto;
  color: var(--black);
  background: var(--gold);
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.ai-chat-send:disabled {
  cursor: wait;
  opacity: 0.62;
}

.ai-chat-proposal {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid rgba(24, 105, 224, 0.2);
  border-radius: 12px;
  background: rgba(24, 105, 224, 0.06);
  padding: 12px;
}

.ai-chat-proposal p,
.ai-chat-proposal label {
  margin: 0;
}

.ai-chat-proposal-actions {
  display: flex;
  gap: 8px;
}

.ai-chat-proposal-actions button {
  border: 1px solid rgba(24, 105, 224, 0.35);
  border-radius: 8px;
  background: #fff;
  color: #1769e0;
  padding: 7px 10px;
}

@media (max-width: 640px) {
  .ai-chat-widget {
    width: calc(100vw - 16px);
    height: min(560px, 76vh);
    transform: translate(calc(100vw - 80px), -50%);
  }

  .ai-chat-widget:focus-within {
    transform: translate(calc(100vw - 80px), -50%);
  }

  .ai-chat-widget.is-open,
  .ai-chat-widget.is-open:focus-within {
    transform: translate(0, -50%);
  }

  .ai-chat-panel {
    width: calc(100vw - 72px);
  }

  .ai-chat-tab {
    width: 56px;
    height: 56px;
  }

  .ai-chat-close {
    display: grid;
  }

  .ai-chat-bubble {
    max-width: min(240px, 78%);
  }
}
