/* ============================================================
   Leafnet Assistant — styles (no image files: logo, avatar and
   icons are CSS + inline SVG)
   Palette:
     --ink     #1f2a24   (deep green-black)
     --accent  #137a4b   (leaf green)
     --mist    #f4f7f5   (soft green-white)
   Type: Bricolage Grotesque (display) / Inter (body)
   ============================================================ */

:root {
  --ink: #1f2a24;
  --ink-soft: #37443d;
  --accent: #137a4b;
  --accent-dark: #0e5f3a;
  --accent-soft: #e6f3ec;
  --paper: #ffffff;
  --mist: #f4f7f5;
  --line: #e1e8e4;
  --muted: #68756e;
  --danger: #c0392b;
  --shadow-sm: 0 1px 3px rgba(31, 42, 36, 0.06);
  --shadow-lg: 0 12px 40px rgba(31, 42, 36, 0.10);
  --font-display: "Bricolage Grotesque", "Inter", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --col: 740px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--mist);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

:focus-visible {
  outline: 3px solid rgba(19, 122, 75, 0.35);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ============ BRAND MARK (replaces logo images) ============ */

.mark {
  display: grid;
  place-items: center;
  flex: none;
  color: #fff;
  background: linear-gradient(145deg, #1a9a5f 0%, var(--accent) 55%, var(--accent-dark) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 8px rgba(19, 122, 75, 0.25);
}

.mark svg {
  width: 58%;
  height: 58%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mark-sm { width: 32px; height: 32px; border-radius: 10px; }
.mark-md { width: 38px; height: 38px; border-radius: 11px; }
.mark-lg { width: 64px; height: 64px; border-radius: 19px; margin: 0 auto 18px; }

/* ============ CHAT LAYOUT ============ */

.chat-body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background:
    radial-gradient(720px 360px at 50% -80px, rgba(26, 154, 95, 0.14), transparent 70%),
    var(--mist);
}

/* --- header --- */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 32px);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.brand-tag { color: var(--muted); font-size: 0.74rem; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.84rem;
  font-weight: 500;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-ghost svg {
  width: 15px; height: 15px;
  fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round;
}

.btn-ghost:hover { border-color: var(--accent); color: var(--accent-dark); }

/* --- thread --- */

.chat-scroll { flex: 1; overflow-y: auto; }

.chat-thread {
  width: min(var(--col), 100%);
  margin: 0 auto;
  padding: 32px clamp(16px, 4vw, 24px) 24px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* welcome */

.welcome { text-align: center; padding: 8vh 8px 12px; }

.welcome-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 4vw, 2rem);
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}

.welcome-sub {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 50ch;
  margin: 0 auto 26px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.suggestion {
  padding: 10px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

.suggestion:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(31, 42, 36, 0.08);
}

/* messages */

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg { animation: msg-in 0.25s ease both; }

.msg-user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--ink);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 11px 16px;
  font-size: 0.94rem;
  line-height: 1.55;
  box-shadow: var(--shadow-sm);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.msg-bot {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  max-width: 100%;
}

.msg-content { min-width: 0; flex: 1; padding-top: 4px; }

/* answer text */

.msg-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--ink-soft);
  overflow-wrap: break-word;
}

.msg-text p { margin: 0 0 12px; }
.msg-text p:last-child { margin-bottom: 0; }

.msg-text ul {
  margin: 0 0 12px;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-text ul li::marker { color: var(--accent); }

/* numbered steps: green step badges instead of plain numbers */
.msg-text ol {
  list-style: none;
  counter-reset: step;
  margin: 4px 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-text ol > li {
  counter-increment: step;
  position: relative;
  padding-left: 38px;
  min-height: 26px;
  color: var(--ink);
}

.msg-text ol > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
}

.msg-text ol > li:not(:last-child)::after {   /* connector line between steps */
  content: "";
  position: absolute;
  left: 12.5px;
  top: 30px;
  bottom: -8px;
  width: 1px;
  background: var(--line);
}

.msg-text ol > li > ul {
  color: var(--ink-soft);
  margin: 6px 0 2px;
  padding-left: 18px;
}

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

.msg-text code {
  background: #edf2ef;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.85em;
}

.msg-text .md-h {
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin: 16px 0 8px;
}

.msg-text .md-h:first-child { margin-top: 0; }

/* typing dots */

.typing { display: inline-flex; gap: 5px; padding: 8px 0; }

.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: bounce 1.1s infinite;
}

.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* sources (guide file + slides) */

.sources-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 16px 0 8px;
}

.msg-sources { display: flex; flex-wrap: wrap; gap: 8px; }

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 12px 6px 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: 0.79rem;
  box-shadow: var(--shadow-sm);
}

.file-badge {          /* PDF / PPT tag drawn in CSS */
  flex: none;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--accent);
}

.file-badge.pdf  { background: #b8423a; }
.file-badge.pptx { background: #c4622d; }
.file-badge.web  { background: #2f6fb3; }

a.source-chip { text-decoration: none; }
a.source-chip:hover { border-color: var(--accent); }

.source-name {
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}

.source-pages { color: var(--muted); white-space: nowrap; }

/* follow-ups */

.followups {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.followups-label {
  font-weight: 600;
  color: var(--ink);
  font-size: 0.92rem;
  margin-bottom: 12px;
}

.followups-list { display: flex; flex-wrap: wrap; gap: 10px; }

.followup {
  padding: 9px 18px;
  background: var(--paper);
  border: 1px solid #d3ddd7;
  border-radius: 999px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.followup:hover { border-color: var(--accent); background: var(--accent-soft); }

/* error */

.msg-error .msg-text {
  color: var(--danger);
  background: #fdf2f1;
  border: 1px solid rgba(192, 57, 43, 0.3);
  border-radius: 12px;
  padding: 10px 14px;
}

/* --- input bar --- */

.chat-inputbar {
  padding: 8px clamp(16px, 4vw, 24px) 14px;
  background: linear-gradient(to top, var(--mist) 60%, transparent);
}

.chat-form {
  width: min(var(--col), 100%);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 26px;
  padding: 8px 8px 8px 20px;
  box-shadow: var(--shadow-lg);
  transition: border-color 0.15s ease;
}

.chat-form:focus-within { border-color: var(--accent); }

#chat-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--ink);
  background: transparent;
  max-height: 140px;
  padding: 8px 0;
}

#chat-input::placeholder { color: var(--muted); }

.btn-send {
  flex: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.btn-send:hover { background: var(--accent-dark); }
.btn-send:active { transform: scale(0.95); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

.inputbar-note {
  width: min(var(--col), 100%);
  margin: 8px auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 520px) {
  .brand-tag { display: none; }
  .btn-ghost span { display: none; }
  .btn-ghost { padding: 9px; }
  .msg-user { max-width: 92%; }
  .mark-sm { width: 28px; height: 28px; border-radius: 9px; }
  .welcome { padding-top: 5vh; }
  .source-name { max-width: 170px; }
}
