/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Page background */
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #020617 0, #020617 45%, #020617 55%, #000 100%);
  color: #e5e7eb;
  min-height: 100vh;
}

/* Shell */
.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.75rem 1rem 2rem;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.app-title-block {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.app-logo-circle {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 0, #4ade80, #16a34a, #14532d);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  color: #ecfdf5;
  box-shadow: 0 12px 30px rgba(16, 185, 129, 0.45);
}

.app-title {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.app-subtitle {
  font-size: 0.9rem;
  color: #9ca3af;
}

.app-header-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid rgba(163, 230, 53, 0.4);
  background: rgba(22, 163, 74, 0.1);
  color: #bbf7d0;
}

.badge-soft {
  border-color: rgba(148, 163, 184, 0.5);
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
}

/* Layout */
.app-main {
  display: grid;
  grid-template-columns: minmax(0, 1.85fr) minmax(260px, 1fr);
  gap: 1.1rem;
}

/* Panels */
.panel {
  background: radial-gradient(circle at top left, rgba(30, 64, 175, 0.3), transparent 55%),
    rgba(15, 23, 42, 0.96);
  border-radius: 1.1rem;
  padding: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.85);
}

.panel-chat {
  display: flex;
  flex-direction: column;
}

.panel-sources {
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.6rem;
}

.panel-title {
  font-size: 1.05rem;
  font-weight: 600;
}

.panel-subtitle {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-top: 0.15rem;
}

/* Chat window */
.chat-window {
  height: 460px;
  overflow-y: auto;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border-radius: 0.9rem;
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.98));
  border: 1px solid rgba(55, 65, 81, 0.7);
}

/* Messages */
.message {
  margin-bottom: 0.85rem;
  padding: 0.55rem 0.8rem;
  border-radius: 0.9rem;
  max-width: 92%;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.45;
}

.message.user {
  margin-left: auto;
  border-radius: 0.9rem 0.9rem 0.1rem 0.9rem;
  background: linear-gradient(to right, #1d4ed8, #2563eb);
  color: #e5e7eb;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.6);
}

.message.ai {
  border-radius: 0.9rem 0.9rem 0.9rem 0.1rem;
  background: #020617;
  border: 1px solid rgba(148, 163, 184, 0.6);
}

/* Markdown styling inside AI messages */
.message.ai h1,
.message.ai h2,
.message.ai h3 {
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.message.ai p {
  margin-bottom: 0.35rem;
}

.message.ai ul,
.message.ai ol {
  margin-left: 1.25rem;
  margin-bottom: 0.35rem;
}

.message.ai li {
  margin-bottom: 0.15rem;
}

.message.ai code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.85rem;
  background: #020617;
  padding: 0.1rem 0.25rem;
  border-radius: 0.25rem;
}

.message.ai pre {
  background: #020617;
  padding: 0.6rem 0.75rem;
  border-radius: 0.6rem;
  overflow-x: auto;
  font-size: 0.85rem;
}

.message.ai pre code {
  background: transparent;
  padding: 0;
}

/* Controls */
.controls-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.control-label {
  font-size: 0.75rem;
  color: #9ca3af;
}

.control-select {
  background: #020617;
  color: #e5e7eb;
  border-radius: 999px;
  border: 1px solid #4b5563;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
  outline: none;
}

.control-select:focus {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.5);
}

/* Input row */
.input-row {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

#user-input {
  flex: 1;
  min-height: 78px;
  resize: vertical;
  padding: 0.6rem 0.75rem;
  border-radius: 0.9rem;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
  font-size: 0.9rem;
  outline: none;
}

#user-input::placeholder {
  color: #6b7280;
}

#user-input:focus {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.4);
}

#send-btn {
  padding: 0.75rem 1.2rem;
  border-radius: 0.9rem;
  border: none;
  background: linear-gradient(to bottom right, #22c55e, #16a34a);
  color: #022c22;
  font-weight: 600;
  cursor: pointer;
  min-width: 80px;
  transition: transform 0.06s ease-out, box-shadow 0.06s ease-out, filter 0.12s;
  box-shadow: 0 12px 25px rgba(22, 163, 74, 0.7);
}

#send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

#send-btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 8px 18px rgba(22, 163, 74, 0.7);
}

#send-btn:disabled {
  opacity: 0.6;
  cursor: default;
  box-shadow: none;
}

/* Sources panel */
.sources-list {
  max-height: 520px;
  overflow-y: auto;
  font-size: 0.83rem;
  padding-right: 0.2rem;
  margin-top: 0.2rem;
}

.source-item {
  border-radius: 0.8rem;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.5rem;
  background: #020617;
  border: 1px solid rgba(148, 163, 184, 0.45);
}

.source-item-header {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}

.source-name {
  font-weight: 500;
}

.source-meta {
  text-align: right;
  font-size: 0.75rem;
  color: #9ca3af;
}

.source-type-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  font-size: 0.7rem;
}

.source-score {
  font-size: 0.75rem;
  color: #a3e635;
}

.source-preview {
  color: #9ca3af;
  margin-top: 0.2rem;
}

/* Loader */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: #9ca3af;
}

.status-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #22c55e;
  animation: bounce 0.8s infinite alternate;
}

.status-indicator .dot:nth-child(2) {
  animation-delay: 0.12s;
}
.status-indicator .dot:nth-child(3) {
  animation-delay: 0.24s;
}

.status-indicator .status-text {
  opacity: 0.9;
}

.hidden {
  display: none !important;
}

@keyframes bounce {
  from {
    transform: translateY(0);
    opacity: 0.5;
  }
  to {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Scrollbars (WebKit) */
.chat-window::-webkit-scrollbar,
.sources-list::-webkit-scrollbar {
  width: 6px;
}

.chat-window::-webkit-scrollbar-track,
.sources-list::-webkit-scrollbar-track {
  background: transparent;
}

.chat-window::-webkit-scrollbar-thumb,
.sources-list::-webkit-scrollbar-thumb {
  background-color: #4b5563;
  border-radius: 999px;
}

/* Responsive */
@media (max-width: 960px) {
  .app-main {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 0.9rem;
  }

  .chat-window {
    height: 380px;
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .app-header-meta {
    align-self: flex-start;
  }

  .input-row {
    flex-direction: column;
  }

  #send-btn {
    width: 100%;
  }
}
