:root {
  color-scheme: light;
  --bg: #eef3f7;
  --panel: #ffffff;
  --text: #10212f;
  --muted: #647383;
  --line: #dbe4ec;
  --primary: #176b87;
  --primary-dark: #0f5067;
  --bot: #f4f7fa;
  --user: #176b87;
  --shadow: 0 24px 70px rgba(16, 33, 47, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(23, 107, 135, 0.12), rgba(236, 248, 243, 0.94)),
    var(--bg);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

.chat-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.chat-card {
  width: min(100%, 780px);
  height: min(760px, calc(100vh - 48px));
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(219, 228, 236, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.chat-avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.chat-header h1 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.2;
}

.chat-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  overflow-y: auto;
  scroll-behavior: smooth;
  background: linear-gradient(180deg, #fbfdff, #f6f9fb);
}

.message {
  display: flex;
}

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

.message-bubble {
  max-width: min(78%, 560px);
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.45;
  font-size: 0.97rem;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.bot .message-bubble {
  background: var(--bot);
  border: 1px solid var(--line);
  color: var(--text);
}

.message.user .message-bubble {
  background: var(--user);
  color: #fff;
}

.message.error .message-bubble {
  background: #fff2f1;
  border: 1px solid #f0c8c4;
  color: #92251e;
}

.typing .message-bubble {
  color: var(--muted);
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  display: block;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.4;
  animation: pulse 1s infinite ease-in-out;
}

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

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

.chat-form {
  display: grid;
  grid-template-columns: 1fr 48px 48px;
  align-items: end;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.composer {
  min-width: 0;
}

.chat-form textarea {
  width: 100%;
  max-height: 130px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  color: var(--text);
  background: #fff;
  outline: none;
  line-height: 1.4;
}

.chat-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

.chat-form button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}

.chat-form .secondary {
  background: #edf3f7;
  color: var(--primary);
  border: 1px solid var(--line);
}

.chat-form .secondary:hover {
  background: #dfeaf1;
}

.chat-form button:hover:not(.secondary) {
  background: var(--primary-dark);
}

.chat-form button:active {
  transform: translateY(1px);
}

.chat-form button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.chat-form svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.file-chip {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
  color: var(--muted);
  font-size: 0.82rem;
}

.file-chip span {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.28;
    transform: translateY(0);
  }

  40% {
    opacity: 0.9;
    transform: translateY(-2px);
  }
}

@media (max-width: 640px) {
  .chat-page {
    padding: 0;
  }

  .chat-card {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .chat-header {
    padding: 15px 16px;
  }

  .chat-messages {
    padding: 16px;
  }

  .message-bubble {
    max-width: 88%;
    font-size: 0.95rem;
  }

  .chat-form {
    grid-template-columns: 1fr 46px 46px;
    padding: 12px;
  }

  .chat-form button {
    width: 46px;
    height: 46px;
  }

  .file-chip span {
    max-width: 160px;
  }
}
