@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;1,400&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;1,8..60,300&display=swap');

:root {
  --ink: #1a1611;
  --parchment: #f5f0e8;
  --cream: #faf7f2;
  --moss: #4a5e3a;
  --moss-l: #6b8c52;
  --river: #3d6b7a;
  --amber: #c8860a;
  --rust: #8b4513;
  --stone: #8c8070;
  --stone-l: #b8ad9e;
  --div: #d4cbbf;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Source Serif 4', Georgia, serif; background: var(--cream); color: var(--ink); }
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.hdr {
  background: var(--ink);
  padding: 13px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 3px solid var(--amber);
  flex-shrink: 0;
}
.hdr-icon { font-size: 1.4rem; }
.hdr-title { font-family: 'Playfair Display', serif; font-size: 1.25rem; color: var(--parchment); }
.hdr-sub { font-size: 0.68rem; color: var(--stone-l); letter-spacing: .09em; text-transform: uppercase; margin-top: 1px; }
.hdr-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.usage-pill {
  font-size: .65rem;
  color: var(--stone-l);
  border: 1px solid rgba(255,255,255,.15);
  padding: 3px 8px;
  border-radius: 10px;
  font-style: italic;
}
.btn-ghost {
  background: none;
  border: 1px solid rgba(255,255,255,.2);
  color: var(--stone-l);
  padding: 4px 11px;
  font-family: 'Source Serif 4', serif;
  font-size: .7rem;
  cursor: pointer;
  border-radius: 2px;
  transition: all .2s;
  letter-spacing: .04em;
}
.btn-ghost:hover { border-color: var(--amber); color: var(--amber); }

.main { display: flex; flex: 1; overflow: hidden; }

.sb {
  width: 215px;
  min-width: 215px;
  background: var(--parchment);
  border-right: 1px solid var(--div);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sb-sec { padding: 13px 13px 8px; border-bottom: 1px solid var(--div); }
.sb-ttl { font-size: .6rem; text-transform: uppercase; letter-spacing: .13em; color: var(--stone); margin-bottom: 8px; }
.qb {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  padding: 6px 8px;
  font-family: 'Source Serif 4', serif;
  font-size: .75rem;
  color: var(--ink);
  cursor: pointer;
  border-radius: 3px;
  margin-bottom: 3px;
  transition: all .15s;
  line-height: 1.3;
}
.qb:hover { background: var(--cream); border-color: var(--div); color: var(--moss); }

.hatch-box { padding: 12px 13px; }
.h-month { font-family: 'Playfair Display', serif; font-size: .8rem; font-weight: 700; color: var(--moss); margin-bottom: 5px; }
.h-item { font-size: .68rem; color: var(--stone); line-height: 1.65; }
.h-item b { color: var(--ink); font-weight: 400; }

.chat { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.msgs { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }

.welcome { text-align: center; padding: 30px 20px; max-width: 480px; margin: auto; }
.w-icon { font-size: 2.6rem; margin-bottom: 10px; }
.welcome h2 { font-family: 'Playfair Display', serif; font-size: 1.4rem; margin-bottom: 8px; }
.w-div { width: 48px; height: 1px; background: var(--amber); margin: 11px auto; }
.welcome p { font-size: .83rem; color: var(--stone); line-height: 1.72; font-style: italic; }

.msg { display: flex; gap: 9px; max-width: 660px; animation: fu .25s ease; }
@keyframes fu { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.msg.user { margin-left: auto; flex-direction: row-reverse; }
.av { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .85rem; flex-shrink: 0; margin-top: 2px; }
.msg.user .av { background: var(--river); }
.msg.assistant .av { background: var(--moss); }
.bub { padding: 10px 14px; border-radius: 4px; font-size: .83rem; line-height: 1.72; max-width: calc(100% - 42px); }
.msg.user .bub { background: var(--river); color: #fff; border-bottom-right-radius: 1px; white-space: pre-wrap; }
.msg.assistant .bub { background: var(--parchment); border: 1px solid var(--div); border-bottom-left-radius: 1px; }
.msg.user .bub-body { white-space: pre-wrap; }

/* Markdown styling — only on assistant bubbles. Tight spacing to keep replies compact. */
.bub-md .bub-body :first-child { margin-top: 0; }
.bub-md .bub-body :last-child { margin-bottom: 0; }
.bub-md .bub-body p { margin: 0 0 8px 0; }
.bub-md .bub-body h1, .bub-md .bub-body h2, .bub-md .bub-body h3 {
  font-family: 'Playfair Display', serif;
  margin: 10px 0 4px 0;
  color: var(--moss);
}
.bub-md .bub-body h1 { font-size: 1.05rem; }
.bub-md .bub-body h2 { font-size: 0.98rem; }
.bub-md .bub-body h3 { font-size: 0.92rem; }
.bub-md .bub-body strong { color: var(--ink); font-weight: 700; }
.bub-md .bub-body em { color: var(--rust); font-style: italic; }
.bub-md .bub-body ul, .bub-md .bub-body ol { margin: 4px 0 8px 0; padding-left: 22px; }
.bub-md .bub-body li { margin-bottom: 2px; }
.bub-md .bub-body code {
  background: rgba(139, 69, 19, 0.08);
  padding: 1px 5px;
  border-radius: 2px;
  font-size: .78rem;
  font-family: 'Consolas', 'Monaco', monospace;
}
.bub-md .bub-body pre {
  background: rgba(26, 22, 17, 0.04);
  border: 1px solid var(--div);
  padding: 8px 10px;
  border-radius: 3px;
  overflow-x: auto;
  margin: 6px 0;
}
.bub-md .bub-body pre code { background: none; padding: 0; }
.bub-md .bub-body blockquote {
  border-left: 3px solid var(--amber);
  padding-left: 10px;
  color: var(--stone);
  font-style: italic;
  margin: 6px 0;
}
.bub-md .bub-body a { color: var(--river); }
.sys { text-align: center; font-size: .67rem; color: var(--stone); font-style: italic; padding: 2px 0; }
.tool-pill { display: inline-block; font-size: .67rem; color: var(--river); background: rgba(61,107,122,.08); border: 1px solid rgba(61,107,122,.2); padding: 1px 7px; border-radius: 9px; margin-right: 4px; }

.dots { display: flex; gap: 5px; padding: 12px 14px; align-items: center; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--stone-l); animation: b 1.2s infinite; }
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes b { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-6px); } }

.inp-area { padding: 12px 20px 14px; border-top: 1px solid var(--div); background: var(--parchment); flex-shrink: 0; }
.inp-row { display: flex; gap: 8px; align-items: flex-end; }
textarea {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--div);
  border-radius: 3px;
  background: var(--cream);
  font-family: 'Source Serif 4', serif;
  font-size: .83rem;
  color: var(--ink);
  resize: none;
  min-height: 42px;
  max-height: 110px;
  line-height: 1.5;
  transition: border-color .2s;
  overflow-y: auto;
}
textarea:focus { outline: none; border-color: var(--moss); }
textarea::placeholder { color: var(--stone-l); font-style: italic; }
.btn-send {
  background: var(--moss);
  color: #fff;
  border: none;
  padding: 9px 16px;
  font-family: 'Source Serif 4', serif;
  font-size: .8rem;
  cursor: pointer;
  border-radius: 3px;
  transition: background .2s;
  height: 42px;
  flex-shrink: 0;
  letter-spacing: .03em;
}
.btn-send:hover { background: var(--moss-l); }
.btn-send:disabled { background: var(--stone-l); cursor: not-allowed; }

.inp-foot { display: flex; justify-content: space-between; margin-top: 4px; gap: 12px; }
.hint { font-size: .63rem; color: var(--stone-l); font-style: italic; }
#errHint { color: var(--rust); }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--div); border-radius: 3px; }

/* ----- Wizard ----- */
.wiz-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26,22,17,.72);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.wiz {
  background: var(--cream);
  border: 1px solid var(--div);
  border-top: 3px solid var(--amber);
  border-radius: 4px;
  padding: 28px 32px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.wiz-header h2 { font-family: 'Playfair Display', serif; font-size: 1.15rem; margin-bottom: 5px; }
.wiz-header p { font-size: .75rem; color: var(--stone); font-style: italic; }
.wiz-field { display: flex; flex-direction: column; gap: 6px; }
.wiz-label { font-size: .63rem; text-transform: uppercase; letter-spacing: .1em; color: var(--stone); }
.wiz-input, .wiz-select {
  padding: 8px 10px;
  border: 1px solid var(--div);
  border-radius: 3px;
  background: var(--parchment);
  font-family: 'Source Serif 4', serif;
  font-size: .82rem;
  color: var(--ink);
}
.wiz-input:focus, .wiz-select:focus { outline: none; border-color: var(--moss); }
.wiz-check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 16px; }
.wiz-check-grid label, .wiz-radio label, .wiz-toggle {
  font-size: .78rem; color: var(--ink); cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
.wiz-radio { display: flex; flex-direction: column; gap: 5px; }
.wiz-row { display: flex; gap: 20px; }
.wiz-row .wiz-field { flex: 1; }
.wiz-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding-top: 8px; border-top: 1px solid var(--div);
}
.btn-primary {
  background: var(--moss); color: #fff; border: none;
  padding: 8px 18px; font-family: 'Source Serif 4', serif;
  font-size: .8rem; cursor: pointer; border-radius: 3px;
  transition: background .2s; letter-spacing: .03em;
}
.btn-primary:hover { background: var(--moss-l); }
.btn-ghost-dark {
  background: none; border: 1px solid var(--div); color: var(--stone);
  padding: 8px 14px; font-family: 'Source Serif 4', serif;
  font-size: .8rem; cursor: pointer; border-radius: 3px; transition: all .2s;
}
.btn-ghost-dark:hover { border-color: var(--stone); color: var(--ink); }
