:root{
  --bg0:#f7f8fc;
  --bg1:#eef1f8;

  --card:#ffffff;
  --card2:#f4f6fb;

  --text:#1a1d29;
  --muted:#6b7280;

  --accentA:#4f46e5;
  --accentB:#06b6d4;
  --accentC:#10b981;

  --user1:#4f46e5;
  --user2:#06b6d4;
  --bot1:#f9fafb;
  --bot2:#eef1f8;

  --border: rgba(26,29,41,0.10);
  --shadow: 0 18px 50px rgba(26,29,41,0.10);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

*{ box-sizing:border-box; }

html, body{ height:100%; }

body{
  margin:0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px circle at 8% 6%, rgba(79,70,229,0.08), transparent 45%),
    radial-gradient(900px circle at 92% 12%, rgba(6,182,212,0.08), transparent 40%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  background-attachment: fixed;
}

.sub{ color: var(--muted); }

main{
  max-width: 980px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding-top: 20px;
  padding-bottom: 28px;
}

@media (max-width: 520px){
  main{ padding-top: 10px; padding-bottom: 18px; min-height: auto; }
}

header .h3{ letter-spacing: -0.02em; font-weight: 780; }

/* Chat card */
.chat-card{
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-card::before{
  content:"";
  position:absolute;
  inset:0;
  background: linear-gradient(120deg, rgba(79,70,229,0.06), rgba(6,182,212,0.05));
  pointer-events:none;
}

.chat-card > *{ position: relative; }

#controls{ margin-top: 0.9rem !important; }

/* Messages */
.messages{
  flex: 1;
  min-height: 280px;
  max-height: 520px;
  overflow:auto;

  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--card2);
  scroll-behavior:smooth;
}

.messages::-webkit-scrollbar{ width: 10px; }
.messages::-webkit-scrollbar-thumb{
  background: rgba(26,29,41,0.16);
  border: 2px solid rgba(0,0,0,0);
  background-clip: padding-box;
  border-radius: 999px;
}
.messages::-webkit-scrollbar-thumb:hover{
  background: rgba(26,29,41,0.28);
}

.msg{ margin: 10px 0; display:flex; }
.msg.user{ justify-content:flex-end; }

.bubble{
  position: relative;
  max-width: min(76%, 640px);
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  font-weight: 400;
  font-size: 0.98rem;

  transform: translateY(6px);
  opacity: 0;
  animation: bubbleIn 220ms ease forwards;
}

@keyframes bubbleIn{
  to{ transform: translateY(0); opacity:1; }
}

.msg.user .bubble{
  color: #fff;
  background: linear-gradient(135deg, var(--user1) 0%, var(--user2) 100%);
  border-bottom-right-radius: 8px;
  box-shadow: 0 10px 24px rgba(79,70,229,0.22);
}

.msg.user .bubble::after{
  content:"";
  position:absolute;
  right: -8px;
  bottom: 0px;
  width: 16px;
  height: 16px;
  background: inherit;
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.msg.bot{ justify-content:flex-start; }

.msg.bot .bubble{
  color: var(--text);
  background: linear-gradient(135deg, var(--bot1) 0%, var(--bot2) 100%);
  border: 1px solid var(--border);
  border-bottom-left-radius: 8px;
  box-shadow: 0 8px 20px rgba(26,29,41,0.06);
}

.msg.bot .bubble::after{
  content:"";
  position:absolute;
  left: -8px;
  bottom: 0px;
  width: 16px;
  height: 16px;
  background: inherit;
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}

/* Composer */
.composer{ width: 100%; }
.composer-top{ gap: 12px; }
.send-wrap{ width: 100%; }
.composer-footer{ margin-top: 8px; }

.hint{
  font-size: 0.85rem;
  color: var(--muted);
  -webkit-user-select: none;
  user-select: none;
}

#clearBtn{
  border-radius: 12px;
  padding: 6px 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: transparent;
  transition: all 160ms ease;
}
#clearBtn:hover{
  background: var(--card2);
  color: var(--text);
}

/* Controls */
.controls .form-control{
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.controls input.form-control{ height: 46px; padding: 0 14px; }

.controls textarea.form-control{
  resize: none;
  min-height: 74px;
  padding: 12px 14px;
  line-height: 1.35;
}

.controls .form-control::placeholder{ color: rgba(26,29,41,0.45); }

.controls .form-control:focus{
  outline: none;
  border-color: rgba(79,70,229,0.5);
  box-shadow: 0 0 0 4px rgba(79,70,229,0.12);
  transform: translateY(-1px);
}

.controls .btn{
  height: 46px;
  border-radius: 14px;
  font-weight: 700;
  border: none;
  background: linear-gradient(135deg, var(--accentA), var(--accentB));
  color: #fff;
  box-shadow: 0 12px 26px rgba(79,70,229,0.22);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.controls .btn:hover{
  filter: brightness(1.05) saturate(1.1);
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(79,70,229,0.28);
}

.controls .btn:active{ transform: translateY(0); }

.controls .btn:disabled{
  opacity: 0.62;
  cursor:not-allowed;
  filter: grayscale(0.2);
  transform:none;
}

.footer-link{
  text-decoration:none;
  color: var(--muted);
}

.footer-link:hover{ text-decoration: underline; color: var(--accentA); }

@media (max-width: 768px){
  .messages{ max-height: 420px; min-height: 240px; }
  .bubble{ font-size: 0.95rem; max-width: 86%; }
}

@media (max-width: 520px){
  main{ padding-left: 14px; padding-right: 14px; }
  .messages{ max-height: 360px; min-height: 220px; padding: 12px; }
  .controls input.form-control{ height: 44px; }
  .controls .btn{ height: 44px; }
  .controls textarea.form-control{ min-height: 64px; }
}
