:root {
  --primary-color: #2563eb;
  --surface-muted: #f8fafc;
  --border: #dbe3f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --user-bubble: #e0edff;
  --assistant-bubble: #ffffff;
  --error: #b91c1c;
  --widget-font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  --widget-font-size: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.12), transparent 30%),
    linear-gradient(180deg, #f8fbff 0%, #eef4ff 100%);
  color: var(--text);
  font-family: var(--widget-font-family);
  font-size: var(--widget-font-size);
  line-height: 1.5;
}

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.chat-header {
  padding: 18px 20px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  backdrop-filter: blur(10px);
}

.chat-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.chat-reset {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff 0%, var(--surface-muted) 100%);
  color: var(--text);
  min-height: 36px;
  padding: 0 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.chat-reset:hover {
  border-color: color-mix(in srgb, var(--primary-color) 28%, var(--border));
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.chat-icon-button {
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-icon {
  width: 18px;
  height: 18px;
  display: block;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.message-row.user {
  justify-content: flex-end;
}

.message-content {
  display: flex;
  min-width: 0;
  max-width: 88%;
  flex-direction: column;
  align-items: flex-start;
}

.message {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid rgba(219, 227, 240, 0.82);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

.message-content > .message {
  max-width: 100%;
}

.message.user {
  background: var(--user-bubble);
  border-bottom-right-radius: 6px;
}

.message.assistant {
  background: var(--assistant-bubble);
  border-bottom-left-radius: 6px;
}

.message.error {
  background: #fef2f2;
  color: var(--error);
}

.message.markdown {
  white-space: normal;
}

.message.markdown > :first-child {
  margin-top: 0;
}

.message.markdown > :last-child {
  margin-bottom: 0;
}

.message.markdown h1,
.message.markdown h2,
.message.markdown h3,
.message.markdown h4,
.message.markdown h5,
.message.markdown h6 {
  margin: 0.8em 0 0.35em;
  line-height: 1.25;
}

.message.markdown h1 {
  font-size: 1.45em;
}

.message.markdown h2 {
  font-size: 1.3em;
}

.message.markdown h3 {
  font-size: 1.15em;
}

.message.markdown p,
.message.markdown ul,
.message.markdown ol,
.message.markdown blockquote,
.message.markdown pre {
  margin: 0.55em 0;
}

.message.markdown ul,
.message.markdown ol {
  padding-left: 1.4em;
}

.message.markdown blockquote {
  border-left: 3px solid color-mix(in srgb, var(--primary-color) 45%, var(--border));
  padding-left: 0.8em;
  color: var(--text-muted);
}

.message.markdown code {
  border-radius: 5px;
  background: var(--surface-muted);
  padding: 0.12em 0.35em;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.9em;
}

.message.markdown pre {
  overflow-x: auto;
  border-radius: 10px;
  background: #0f172a;
  color: #f8fafc;
  padding: 0.8em;
}

.message.markdown pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.message.markdown a {
  color: var(--primary-color);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message.thinking {
  background: var(--assistant-bubble);
  border-bottom-left-radius: 3px;
  padding: 12px 20px 12px 12px;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  flex: 0 0 32px;
  object-fit: cover;
  border: 1px solid rgba(219, 227, 240, 0.9);
  background: #fff;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.message-feedback {
  display: flex;
  gap: 2px;
  margin: 3px 0 0 8px;
}

.feedback-button {
  display: inline-flex;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0.62;
  transition: color 140ms ease, background 140ms ease, opacity 140ms ease;
}

.feedback-button:hover:not(:disabled),
.feedback-button:focus-visible,
.feedback-button.selected {
  background: color-mix(in srgb, var(--primary-color) 9%, transparent);
  color: var(--primary-color);
  opacity: 1;
}

.feedback-button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary-color) 30%, white);
  outline-offset: 1px;
}

.feedback-button:disabled {
  cursor: wait;
  opacity: 0.38;
}

.feedback-icon {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.feedback-button.negative .feedback-icon {
  transform: rotate(180deg);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
  background: transparent;
}

.chat-suggestions[hidden] {
  display: none;
}

.chat-suggestion {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid color-mix(in srgb, var(--primary-color) 24%, var(--border));
  border-radius: 12px;
  background: color-mix(in srgb, var(--primary-color) 5%, white);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.chat-suggestion::after {
  content: "→";
  flex: 0 0 auto;
  margin-left: 12px;
  color: var(--primary-color);
  font-size: 18px;
  line-height: 1;
}

.chat-suggestion:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--primary-color);
  background: color-mix(in srgb, var(--primary-color) 10%, white);
}

.chat-suggestion:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary-color) 35%, white);
  outline-offset: 2px;
}

.chat-suggestion:disabled {
  cursor: wait;
  opacity: 0.6;
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  justify-content: flex-start;
}

.thinking-dot {
  width: 8px;
  height: 8px;
  border-radius: 500px;
  background: color-mix(in srgb, var(--primary-color) 68%, white);
  opacity: 0.35;
  animation: thinking-bounce 1.1s infinite ease-in-out;
}

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

.thinking-dot:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes thinking-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0) scale(0.9);
    opacity: 0.35;
  }

  40% {
    transform: translateY(-3px) scale(1);
    opacity: 1;
  }
}

.chat-compose {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: transparent;
  backdrop-filter: blur(10px);
}

.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  min-height: 52px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 15px;
  color: var(--text);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
  font: inherit;
}

.chat-input:focus {
  outline: 2px solid color-mix(in srgb, var(--primary-color) 18%, white);
  border-color: var(--primary-color);
}

.chat-submit {
  border: 0;
  border-radius: 18px;
  background: linear-gradient(
    135deg,
    var(--primary-color) 0%,
    color-mix(in srgb, var(--primary-color) 76%, #07111f) 100%
  );
  color: #fff;
  width: 52px;
  flex: 0 0 52px;
  min-height: 52px;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 16px 32px color-mix(in srgb, var(--primary-color) 26%, transparent);
  transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
}

.chat-submit:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: saturate(1.05);
}

.chat-submit:disabled {
  opacity: 0.6;
  cursor: wait;
  box-shadow: none;
}

.chat-submit-icon {
  width: 20px;
  height: 20px;
  display: block;
  margin: 0 auto;
}

.chat-submit.loading .chat-submit-icon {
  opacity: 0.5;
}
