:root {
  color-scheme: light dark;
  --bg: #f6f7fb;
  --fg: #111928;
  --muted: #5b6979;
  --accent: #2563eb;
  --accent-light: rgba(37, 99, 235, 0.1);
  --card: #ffffff;
  --border: #e2e8f0;
  --font-stack: "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-stack);
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app-shell {
  width: min(1200px, 100%);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem 2rem;
  gap: 1.5rem;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.control-group input[type="file"],
.control-group select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--card);
  color: inherit;
  min-width: 170px;
}

.content {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 1.5rem;
}

.column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--card);
  border-radius: 1rem;
  border: 1px solid var(--border);
  padding: 1.25rem;
  min-height: 72vh;
}

.conversation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.conversation-header h2 {
  margin: 0;
}

.session-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  align-items: center;
  flex-wrap: wrap;
}

.conversation-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 0.25rem;
}

.message {
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  display: grid;
  gap: 0.4rem;
}

.message.loading {
  position: relative;
  overflow: hidden;
  color: var(--muted);
}

.message.loading .body {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.message.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(37, 99, 235, 0.12) 50%,
    transparent 100%
  );
  animation: shimmer 1.5s infinite;
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(37, 99, 235, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.message.question {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
}

.message.answer {
  background: #f1f5f9;
  border-left: 4px solid #0f172a;
}

.message h4 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.message .body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
}

.answer-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.answer-form textarea {
  resize: vertical;
  min-height: 120px;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
}

.answer-form textarea:focus {
  outline: 2px solid var(--accent-light);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

button {
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: white;
}

button.secondary {
  background: #0f172a;
  color: #fff;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.insights .panel {
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 1rem;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.topics-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.25rem 0 0.75rem;
}

.topic-tag {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f1f5f9;
  color: var(--muted);
  font-size: 0.85rem;
  transition: all 0.15s ease;
}

.topic-tag.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(37, 99, 235, 0.12);
  font-weight: 600;
}

.panel h3 {
  margin: 0;
  font-size: 1rem;
}

.panel-body {
  font-size: 0.95rem;
  color: var(--fg);
  line-height: 1.6;
}

.panel-body.empty {
  color: var(--muted);
  font-style: italic;
}

.metrics-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.5rem;
}

.metrics-list li {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
}

.metrics-list span {
  color: var(--muted);
}

.metrics-list strong {
  font-weight: 600;
}

.metrics-list li:first-child strong {
  color: var(--accent);
}

#toast-root {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 9999;
}

.toast-message {
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-size: 0.95rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
  animation: toast-in 0.3s ease, toast-out 0.3s ease 3.2s forwards;
}

@keyframes toast-in {
  from {
    transform: translate(-50%, -10px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

@keyframes toast-out {
  to {
    transform: translate(-50%, -20px);
    opacity: 0;
  }
}

@media (max-width: 960px) {
  .content {
    grid-template-columns: 1fr;
  }

  .controls {
    width: 100%;
    justify-content: flex-start;
  }

  .column {
    min-height: auto;
  }
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
