* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  font-family: 'Inter', sans-serif;
  background: #0a0713;
  background-image:
    radial-gradient(ellipse at 15% 10%, #2b1a3f 0%, transparent 50%),
    radial-gradient(ellipse at 85% 90%, #1e2a3f 0%, transparent 45%),
    radial-gradient(ellipse at 50% 50%, #130f1f 0%, #07040e 100%);
  color: #f0e9e0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.2rem;
  min-height: 100vh;
}

.app {
  max-width: 1200px;
  width: 100%;
  height: 92vh;
  max-height: 900px;
  background: rgba(12, 8, 22, 0.7);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(220, 180, 120, 0.18);
  border-radius: 2.5rem;
  padding: 1.5rem 1.8rem 1.8rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 215, 150, 0.08);
  display: flex;
  flex-direction: column;
}

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(220, 180, 120, 0.12);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.crest {
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 0 8px #d4a37355);
  background: radial-gradient(circle at 30% 30%, #f5e3c1, #b4884b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 900;
}

.brand h1 {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, #f6e3c5, #dbb07b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand p {
  font-size: 0.7rem;
  color: #b9a9c0;
  letter-spacing: 0.08em;
  margin-top: 2px;
  font-weight: 500;
  -webkit-text-fill-color: #b9a9c0;
}

.connection {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.3rem 0.6rem 0.3rem 1rem;
  border-radius: 60px;
  border: 1px solid rgba(220, 180, 120, 0.15);
}

.connection input {
  background: transparent;
  border: none;
  color: #ece3d7;
  font-size: 0.8rem;
  font-weight: 500;
  width: 180px;
  padding: 0.3rem 0;
  outline: none;
  font-family: 'Inter', sans-serif;
}

.connection input::placeholder {
  color: #6b5f72;
}

.connection input:focus {
  border-bottom: 1px solid #dbb07b;
}

.ping {
  background: rgba(220, 180, 120, 0.08);
  border: 1px solid rgba(220, 180, 120, 0.25);
  border-radius: 40px;
  padding: 0.3rem 1rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: #e6d6c0;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
}

.ping:hover {
  background: rgba(220, 180, 120, 0.2);
  border-color: #dbb07b;
  color: #f5e3c5;
}

.dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #4a3f4f;
  transition: 0.25s;
}

.dot.idle {
  background: #5a4e5e;
}

.dot.ok {
  background: #6fcf97;
  box-shadow: 0 0 14px #6fcf9766;
}

.dot.error {
  background: #eb8a8a;
  box-shadow: 0 0 14px #eb8a8a66;
}

/* ---------- CHAT LAYOUT ---------- */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-top: 1rem;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding-right: 0.3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 200px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 5px;
}

.messages::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 10px;
}

.messages::-webkit-scrollbar-thumb {
  background: #5f4d5f;
  border-radius: 10px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeUp 0.3s ease;
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message .bubble {
  padding: 0.9rem 1.3rem;
  border-radius: 1.6rem;
  font-size: 0.9rem;
  line-height: 1.6;
  word-break: break-word;
  background: rgba(30, 22, 44, 0.7);
  backdrop-filter: blur(2px);
  border: 1px solid rgba(220, 180, 120, 0.06);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.message.user .bubble {
  background: linear-gradient(145deg, #dbb07b, #b4884b);
  color: #0f0b17;
  border: none;
  box-shadow: 0 6px 18px rgba(187, 142, 78, 0.25);
}

.message .meta {
  font-size: 0.6rem;
  color: #7d6b84;
  margin: 0.2rem 0.5rem 0;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.message .sources-inline {
  margin-top: 0.4rem;
  font-size: 0.65rem;
  color: #b9a9c0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.6rem;
  background: rgba(0, 0, 0, 0.15);
  padding: 0.3rem 0.8rem;
  border-radius: 30px;
  border: 1px solid rgba(220, 180, 120, 0.05);
}

.message .sources-inline span {
  opacity: 0.8;
}

.message .sources-inline .page {
  color: #e3cfa8;
  font-weight: 600;
}

.empty-chat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  height: 100%;
  color: #887b8f;
  gap: 0.4rem;
}

.empty-chat .icon {
  font-size: 3rem;
  opacity: 0.4;
  filter: drop-shadow(0 0 20px #dbb07b22);
}

.empty-chat h3 {
  font-family: 'Cinzel', serif;
  font-weight: 600;
  color: #ded0ca;
  font-size: 1.2rem;
}

.empty-chat p {
  max-width: 280px;
  font-size: 0.85rem;
  color: #8f7d96;
}

/* ---------- INPUT AREA ---------- */
.input-area {
  display: flex;
  gap: 0.7rem;
  align-items: flex-end;
  padding-top: 1rem;
  border-top: 1px solid rgba(220, 180, 120, 0.08);
  flex-shrink: 0;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.input-area textarea {
  flex: 1;
  min-height: 52px;
  max-height: 130px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(220, 180, 120, 0.12);
  border-radius: 1.8rem;
  padding: 0.9rem 1.4rem;
  color: #f2ece6;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: 0.2s;
}

.input-area textarea:focus {
  border-color: #dbb07b;
  box-shadow: 0 0 0 3px rgba(219, 176, 123, 0.1);
}

.input-area textarea::placeholder {
  color: #6b5a70;
}

.input-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.ask-btn {
  background: linear-gradient(145deg, #dbb07b, #b4884b);
  border: none;
  border-radius: 60px;
  padding: 0.8rem 1.8rem;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: #0f0b17;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(187, 142, 78, 0.25);
  white-space: nowrap;
}

.ask-btn:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 28px rgba(187, 142, 78, 0.4);
}

.ask-btn:disabled {
  opacity: 0.5;
  transform: none;
  box-shadow: none;
  cursor: wait;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
  flex-shrink: 0;
  width: 100%;
}

.chip {
  background: rgba(220, 180, 120, 0.06);
  border: 1px solid rgba(220, 180, 120, 0.12);
  border-radius: 40px;
  padding: 0.2rem 1rem;
  font-size: 0.65rem;
  font-weight: 500;
  color: #ccbfcd;
  cursor: pointer;
  transition: 0.2s;
  font-family: 'Inter', sans-serif;
}

.chip:hover {
  background: rgba(220, 180, 120, 0.15);
  border-color: #dbb07b;
  color: #f2e3d0;
}

.error-bar {
  display: none;
  padding: 0.5rem 1.2rem;
  background: rgba(180, 60, 60, 0.12);
  border: 1px solid rgba(235, 120, 120, 0.2);
  border-radius: 60px;
  color: #f4cfcf;
  font-size: 0.8rem;
  margin-top: 0.5rem;
  flex-shrink: 0;
}

.error-bar.show {
  display: block;
}

@keyframes fadeUp {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* responsive */
@media (max-width: 700px) {
  .app {
    padding: 1rem;
    height: 96vh;
    max-height: none;
    border-radius: 1.8rem;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .connection {
    justify-content: flex-start;
  }
  .connection input {
    width: 100%;
  }
  .message {
    max-width: 95%;
  }
  .input-area {
    flex-direction: column;
    align-items: stretch;
  }
  .input-actions {
    justify-content: flex-end;
  }
}