:root {
  --ink: #12261f;
  --ink-muted: #3d564c;
  --mist: #d8e4dc;
  --paper: #eef3ee;
  --panel: rgba(243, 248, 244, 0.72);
  --accent: #0b6b5f;
  --accent-deep: #084f46;
  --saffron: #c3922a;
  --line: rgba(18, 38, 31, 0.14);
  --shadow: 0 18px 50px rgba(18, 38, 31, 0.08);
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Figtree", "Helvetica Neue", sans-serif;
  --radius: 18px;
}

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

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--mist);
  overflow: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 12% 18%, rgba(195, 146, 42, 0.18), transparent 55%),
    radial-gradient(ellipse 70% 55% at 88% 12%, rgba(11, 107, 95, 0.22), transparent 50%),
    radial-gradient(ellipse 90% 70% at 50% 100%, rgba(18, 38, 31, 0.12), transparent 55%),
    linear-gradient(165deg, #cfdcd4 0%, #e7efe9 42%, #d2dfd6 100%);
  pointer-events: none;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  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='4' 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: soft-light;
}

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  height: 100vh;
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem;
  gap: 1rem;
}

.rail,
.workspace {
  backdrop-filter: blur(14px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.rail {
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.9rem;
  min-height: 0;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 0.35rem 0.85rem;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.ghost-btn:hover {
  background: rgba(11, 107, 95, 0.08);
  border-color: rgba(11, 107, 95, 0.35);
  transform: translateY(-1px);
}

.history {
  flex: 1;
  overflow-y: auto;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-right: 0.15rem;
}

.history-empty {
  margin: 1rem 0.35rem;
  color: var(--ink-muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.history-item {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: background 160ms ease, transform 160ms ease;
}

.history-item:hover {
  background: rgba(18, 38, 31, 0.05);
  transform: translateX(3px);
}

.history-item.is-active {
  background: rgba(11, 107, 95, 0.12);
}

.history-title {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  padding: 1.5rem 1.5rem 1.15rem;
}

.brand-block {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  animation: fade-rise 520ms ease both;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.2rem, 4vw, 3.2rem);
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--ink);
}

.lede {
  margin: 0.55rem 0 0;
  max-width: 36ch;
  color: var(--ink-muted);
  font-size: 1.02rem;
  line-height: 1.45;
}

.thread {
  overflow-y: auto;
  padding: 1.25rem 0.15rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 0;
}

.empty-state {
  margin: auto 0;
  padding: 2rem 0.5rem;
  animation: fade-rise 640ms ease both;
}

.empty-kicker {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 500;
}

.empty-copy {
  margin: 0.4rem 0 0;
  color: var(--ink-muted);
}

.msg {
  max-width: min(62ch, 100%);
  animation: fade-rise 380ms ease both;
}

.msg-user {
  align-self: flex-end;
}

.msg-assistant {
  align-self: flex-start;
}

.msg-role {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-muted);
}

.msg-user .msg-role {
  text-align: right;
}

.msg-body {
  margin: 0;
  padding: 0.85rem 1rem;
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-user .msg-body {
  background: var(--accent);
  color: #f4faf8;
  border-bottom-right-radius: 6px;
}

.msg-assistant .msg-body {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: end;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.composer textarea {
  width: 100%;
  resize: none;
  min-height: 3.1rem;
  max-height: 9rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  outline: none;
  transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.composer textarea:focus {
  border-color: rgba(11, 107, 95, 0.55);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 0 3px rgba(11, 107, 95, 0.12);
}

.send-btn {
  appearance: none;
  border: 0;
  background: var(--ink);
  color: #eef6f1;
  font: inherit;
  font-weight: 600;
  padding: 0.9rem 1.2rem;
  border-radius: 14px;
  cursor: pointer;
  min-width: 6.5rem;
  transition: background 160ms ease, transform 160ms ease;
}

.send-btn:hover {
  background: var(--accent-deep);
  transform: translateY(-1px);
}

.htmx-request .send-label {
  display: none;
}

.htmx-request .send-wait {
  display: inline;
}

.send-wait {
  display: none;
}

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

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

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
  }

  .rail {
    max-height: 220px;
  }

  .workspace {
    min-height: 70vh;
  }
}
