:root {
  --ink: #1c2a24;
  --ink-soft: #3d4f46;
  --paper: rgba(247, 250, 246, 0.88);
  --paper-solid: #f4f8f3;
  --line: rgba(28, 42, 36, 0.12);
  --sage: #3f6f5a;
  --sage-deep: #2b5242;
  --mint: #9fbfae;
  --accent: #2f6b7a;
  --shadow: 0 18px 50px rgba(28, 42, 36, 0.14);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: #3a2418;
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    url("/static/img/bordeaux-winery-bg.png") center / cover no-repeat;
  filter: sepia(0.18) contrast(1.04) saturate(0.88);
  transform: scale(1.04);
  animation: drift 28s ease-in-out infinite alternate;
  z-index: 0;
}

.veil {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(165deg, rgba(48, 28, 16, 0.38) 0%, rgba(92, 58, 30, 0.16) 42%, rgba(22, 12, 8, 0.48) 100%),
    radial-gradient(ellipse at 55% 35%, rgba(255, 228, 190, 0.08), transparent 58%);
  z-index: 1;
  pointer-events: none;
}

.stage {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 3vw, 1.5rem) 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.brand {
  animation: rise 0.7s ease both;
}

.brand-mark {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 8vw, 4.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 0.95;
  color: var(--sage-deep);
}

.brand-title {
  margin: 0.15rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  font-weight: 500;
  color: var(--ink);
}

.brand-sub {
  margin: 0.55rem 0 0;
  max-width: 34ch;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.status {
  margin: 0.75rem 0 0;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  color: var(--sage);
}

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: min(62vh, 640px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  overflow: hidden;
  animation: rise 0.85s ease 0.08s both;
}

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem 1.15rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

.bubble {
  max-width: min(92%, 560px);
  padding: 0.85rem 1rem;
  border-radius: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  animation: pop 0.35s ease both;
}

.bubble.user {
  align-self: flex-end;
  background: var(--sage-deep);
  color: #f7faf6;
}

.bubble.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  color: var(--ink);
}

.bubble.bot .meta {
  display: block;
  margin-top: 0.55rem;
  font-size: 0.75rem;
  color: var(--ink-soft);
  opacity: 0.85;
}

.chart-gallery {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 0.75rem;
}

.chart-figure {
  margin: 0;
}

.chart-figure img {
  display: block;
  width: 100%;
  max-width: 640px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: zoom-in;
}

.chart-figure figcaption {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.download-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.download-link {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--sage, #2b5242);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.download-link:hover {
  border-color: var(--teal, #2f6b7a);
  color: var(--teal, #2f6b7a);
}

.bubble.typing {
  align-self: flex-start;
  color: var(--ink-soft);
  font-style: italic;
  background: transparent;
  border: 0;
  padding-left: 0.2rem;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  padding: 0.85rem 1rem 0.35rem;
  border-top: 1px solid var(--line);
  background: rgba(244, 248, 243, 0.92);
  align-items: stretch;
}

.composer-actions {
  display: flex;
  gap: 0.5rem;
}

.composer textarea {
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  min-height: 48px;
  max-height: 140px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer textarea:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(63, 111, 90, 0.15);
}

.composer button {
  border: 0;
  border-radius: 12px;
  padding: 0 1.15rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: #f7faf6;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}

.composer button#chart {
  background: var(--sage-deep);
}

.composer button:hover:not(:disabled) {
  background: #245663;
  transform: translateY(-1px);
}

.composer button#chart:hover:not(:disabled) {
  background: #1f3d32;
}

.composer button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.hints {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.55rem 1rem 1rem;
}

.hints button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  border-radius: 10px;
  padding: 0.4rem 0.8rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.hints button:hover {
  background: rgba(63, 111, 90, 0.12);
  color: var(--sage-deep);
  transform: translateY(-1px);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@keyframes drift {
  from { transform: scale(1.04) translate3d(0, 0, 0); }
  to { transform: scale(1.08) translate3d(-1.2%, -0.8%, 0); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
  .chat {
    min-height: 58vh;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .composer button {
    min-height: 46px;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bg,
  .brand,
  .chat,
  .bubble {
    animation: none !important;
  }
}
