:root {
  --paper: #f3f5f2;
  --paper-2: #e8ece6;
  --ink: #1a1f1c;
  --muted: #5c6b63;
  --line: #c9d2cb;
  --accent: #2f6f5e;
  --accent-soft: #d7ebe3;
  --accent-ink: #f4fbf8;
  --danger: #9b2f2f;
  --danger-soft: #f7e4e4;
  --shadow: 0 18px 50px rgba(26, 31, 28, 0.08);
  --radius: 14px;
  --font-display: "Syne", system-ui, sans-serif;
  --font-body: "DM Sans", system-ui, sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.02rem;
  line-height: 1.5;
  background:
    radial-gradient(ellipse 70% 45% at 100% 0%, rgba(47, 111, 94, 0.12), transparent 55%),
    radial-gradient(ellipse 50% 40% at 0% 100%, rgba(90, 110, 140, 0.1), transparent 50%),
    linear-gradient(180deg, #f7f8f5 0%, var(--paper) 40%, var(--paper-2) 100%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  z-index: 0;
}

a { color: var(--accent); }

.shell {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.shell-narrow { width: min(440px, calc(100% - 2rem)); }

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  letter-spacing: -0.04em;
  line-height: 0.95;
  margin: 0;
}

.lede {
  color: var(--muted);
  margin: 0.85rem 0 0;
  max-width: 36ch;
  font-size: 1.05rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 2rem;
  animation: rise 0.55s ease both;
}

.topbar .meta-line {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--muted);
  background: rgba(255,255,255,0.55);
}

.pill strong { color: var(--ink); font-weight: 600; }

.workspace {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 860px) {
  .workspace {
    grid-template-columns: 1.35fr 0.9fr;
    align-items: start;
  }
  .ask-panel { grid-column: 1; grid-row: 1 / span 2; }
  .docs-panel { grid-column: 2; }
}

.panel {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(201, 210, 203, 0.85);
  border-radius: var(--radius);
  padding: 1.25rem 1.3rem 1.4rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 0.6s ease both;
}

.docs-panel { animation-delay: 0.06s; }
.ask-panel { animation-delay: 0.02s; }

.panel h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

.panel .hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

label {
  display: block;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

input[type="password"],
input[type="text"],
textarea {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  min-height: 7.5rem;
  resize: vertical;
  line-height: 1.45;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.9rem; }

button, .btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.2rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

button:hover:not(:disabled), .btn:hover { transform: translateY(-1px); background: #275c4e; }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.65; cursor: wait; }

button.ghost, .ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
button.ghost:hover { background: rgba(255,255,255,0.7); color: var(--ink); }

.dropzone {
  position: relative;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  padding: 1.25rem 1rem;
  text-align: center;
  background: rgba(255,255,255,0.5);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
  cursor: pointer;
}

.dropzone:hover, .dropzone.is-drag {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.dropzone.is-uploading {
  pointer-events: none;
  opacity: 0.75;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone .dz-title { font-weight: 600; margin: 0; }
.dropzone .dz-sub { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.88rem; }
.dropzone .dz-file {
  margin: 0.6rem 0 0;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 1.2em;
}

.docs { list-style: none; padding: 0; margin: 1rem 0 0; }
.docs li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
}
.docs li:first-child { border-top: 0; padding-top: 0; }
.docs .name { overflow-wrap: anywhere; }
.docs .meta { color: var(--muted); font-size: 0.82rem; }
.docs button.ghost { padding: 0.35rem 0.7rem; font-size: 0.8rem; margin: 0; }

.answer {
  margin-top: 1.1rem;
  padding: 1rem 1.15rem 1.15rem;
  border-left: 3px solid var(--accent);
  background: linear-gradient(90deg, var(--accent-soft), rgba(255,255,255,0.4));
  border-radius: 0 12px 12px 0;
  line-height: 1.55;
  animation: fadeSlide 0.45s ease both;
}
.answer.md-body:not(.md-ready) { white-space: pre-wrap; }
.answer.md-ready { white-space: normal; }
.answer p { margin: 0 0 0.7rem; }
.answer p:last-child { margin-bottom: 0; }
.answer h1, .answer h2, .answer h3 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  margin: 1rem 0 0.45rem;
  line-height: 1.2;
}
.answer h1 { font-size: 1.25rem; }
.answer h2 { font-size: 1.12rem; }
.answer h3 { font-size: 1.02rem; }
.answer ul, .answer ol { margin: 0.35rem 0 0.8rem; padding-left: 1.25rem; }
.answer li { margin: 0.25rem 0; }
.answer strong { font-weight: 700; }
.answer code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: rgba(26, 31, 28, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.answer pre {
  margin: 0.6rem 0 0.9rem;
  padding: 0.75rem 0.85rem;
  overflow-x: auto;
  background: rgba(26, 31, 28, 0.08);
  border-radius: 8px;
  font-size: 0.86rem;
}
.answer pre code { background: none; padding: 0; }

.retrieved {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  animation: fadeSlide 0.5s ease 0.05s both;
}

.err {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.92rem;
}

.login-stage {
  min-height: calc(100svh - 4rem);
  display: grid;
  align-content: center;
  animation: rise 0.55s ease both;
}

.login-stage form { margin-top: 1.5rem; }
.login-stage .foot {
  margin-top: 2rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.busy-bar {
  display: none;
  height: 3px;
  width: 100%;
  margin: 0.85rem 0 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--paper-2);
}
.busy-bar.on { display: block; }
.busy-bar span {
  display: block;
  height: 100%;
  width: 40%;
  background: var(--accent);
  animation: slide 0.9s ease-in-out infinite;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(280%); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
