/* Monkeys and Peanut Butter brand palette (official colour codes).
   Variable names describe the role, values come from the brand sheet. */
:root {
  --canopy: #17320b;        /* header: deep forest */
  --canopy-text: #fef6cd;   /* header text: cream */
  --paper: #f2eedd;         /* page background: cream */
  --surface: #fffdf7;       /* input boxes and cards */
  --leaf: #b4d8b0;          /* member message bubbles: sage */
  --peanut: #6683bc;        /* buttons: brand button blue */
  --peanut-hover: #5873b0;
  --peanut-soft: #faed8f;   /* highlights: butter yellow */
  --heading: #236896;       /* headings and assistant name: brand text blue */
  --ink: #2d3031;           /* body text */
  --mist: #5f5b4c;          /* secondary text */
  --line: #dad8a5;          /* borders: khaki */
  --danger: #3d0000;        /* error text: maroon */
  --focus: #236896;
  --on-button: #ffffff;
  --radius-lg: 18px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canopy: #17320b;
    --canopy-text: #fef6cd;
    --paper: #0f1c0a;
    --surface: #17320b;
    --leaf: #2a4720;
    --peanut: #9fb2dc;
    --peanut-hover: #b4c4e6;
    --peanut-soft: #3a3a1c;
    --heading: #9cc7d2;
    --ink: #fef6cd;
    --mist: #c9d3b8;
    --line: #2f4a25;
    --danger: #ffb4a8;
    --focus: #faed8f;
    --on-button: #0f1c0a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --canopy: #17320b;
  --canopy-text: #fef6cd;
  --paper: #0f1c0a;
  --surface: #17320b;
  --leaf: #2a4720;
  --peanut: #9fb2dc;
  --peanut-hover: #b4c4e6;
  --peanut-soft: #3a3a1c;
  --heading: #9cc7d2;
  --ink: #fef6cd;
  --mist: #c9d3b8;
  --line: #2f4a25;
  --danger: #ffb4a8;
  --focus: #faed8f;
  --on-button: #0f1c0a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* ---------- Header ---------- */
.topbar {
  background: var(--canopy);
  color: var(--canopy-text);
}
.topbar-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.mark { width: 40px; height: 40px; flex: none; border-radius: 10px; }
.wordmark { display: flex; flex-direction: column; line-height: 1.15; }
.wordmark strong { font-size: 19px; font-weight: 600; letter-spacing: 0.01em; }
.wordmark span { font-size: 13px; opacity: 0.82; }
.topbar .spacer { flex: 1; }
.link-button {
  background: none;
  border: 1px solid rgba(254, 246, 205, 0.5);
  color: var(--canopy-text);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
}
.link-button:hover { background: rgba(254, 246, 205, 0.12); }

/* ---------- Sign-in ---------- */
.signin {
  max-width: 460px;
  margin: 0 auto;
  padding: 48px 16px 64px;
}
.signin-logo {
  display: block;
  width: 150px;
  height: auto;
  margin: 0 0 18px;
}
.signin h1 {
  color: var(--heading);
  font-size: 30px;
  line-height: 1.2;
  font-weight: 700;
  margin: 0 0 10px;
}
.signin p.lead { color: var(--mist); margin: 0 0 28px; }
.field { display: block; margin-bottom: 16px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 17px;
}
.field input:focus { border-color: var(--peanut); outline: none; box-shadow: 0 0 0 3px var(--peanut-soft); }
.code-input { letter-spacing: 0.4em; font-size: 22px !important; text-align: center; }

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--peanut);
  color: var(--on-button);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-weight: 700;
  font-size: 19px;
  cursor: pointer;
}
.primary:hover { background: var(--peanut-hover); }
.primary:disabled { opacity: 0.6; cursor: wait; }

.text-button {
  background: none;
  border: none;
  color: var(--peanut);
  font-weight: 700;
  padding: 8px 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.status { min-height: 1.6em; margin: 14px 0 0; color: var(--mist); font-size: 15px; }
.status.error { color: var(--danger); }
.help { margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--mist); font-size: 15px; }
.help a { color: inherit; }

/* ---------- Chat ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}
#chatView { flex: 1; min-height: 0; height: auto; }
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.chat {
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 16px 12px;
}

.welcome h1 {
  color: var(--heading);
  font-size: 28px;
  line-height: 1.25;
  font-weight: 700;
  margin: 8px 0 8px;
}
.welcome p { color: var(--mist); margin: 0 0 20px; max-width: 60ch; }
.starters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.starter {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
}
.starter:hover { border-color: var(--heading); background: var(--peanut-soft); }

.msg { margin: 0 0 22px; }
.msg.me { display: flex; justify-content: flex-end; }
.msg.me .bubble {
  background: var(--leaf);
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  padding: 11px 16px;
  max-width: min(80%, 60ch);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.ai .who {
  font-size: 13px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 2px;
}
.msg.ai .body { max-width: 68ch; overflow-wrap: anywhere; }
.msg.ai .body p { margin: 0 0 12px; }
.msg.ai .body p:last-child { margin-bottom: 0; }
.msg.ai .body ul, .msg.ai .body ol { margin: 0 0 12px; padding-left: 1.4em; }
.msg.ai .body li { margin-bottom: 4px; }
.msg.notice .body { color: var(--danger); }

.thinking { display: inline-flex; gap: 5px; padding: 8px 0; }
.thinking i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--mist);
  animation: bob 1.2s infinite ease-in-out;
}
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bob {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .thinking i { animation: none; opacity: 0.7; }
  .chat-scroll { scroll-behavior: auto; }
}

/* ---------- Composer ---------- */
.composer-wrap {
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.composer {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 16px 10px;
}
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 6px 6px 6px 14px;
}
.composer-box:focus-within { border-color: var(--peanut); box-shadow: 0 0 0 3px var(--peanut-soft); }
.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  padding: 8px 0;
  max-height: 180px;
  min-height: 24px;
  line-height: 1.5;
}
.send {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: var(--peanut);
  color: var(--on-button);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.send:hover { background: var(--peanut-hover); }
.send:disabled { opacity: 0.45; cursor: default; }
.send svg { width: 20px; height: 20px; }
.fineprint {
  margin: 8px 2px 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--mist);
}
.fineprint strong { color: var(--ink); }

/* ---------- Admin ---------- */
.admin { max-width: 980px; margin: 0 auto; padding: 28px 16px 64px; }
.admin h1 { font-size: 26px; margin: 0 0 4px; }
.admin h2 { font-size: 20px; margin: 32px 0 10px; }
.admin .sub { color: var(--mist); margin: 0 0 18px; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin: 18px 0 20px; }
.tab {
  background: none; border: none; padding: 10px 14px; cursor: pointer;
  font-weight: 700; color: var(--mist); border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--peanut); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.row input[type="month"], .row input[type="text"], .admin textarea {
  padding: 9px 12px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.admin textarea { width: 100%; min-height: 96px; }
.small-button {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 14px; cursor: pointer; font-weight: 700; font-size: 15px;
  color: var(--ink); text-decoration: none; display: inline-block;
}
.small-button:hover { border-color: var(--peanut); }
.small-button.solid { background: var(--peanut); border-color: var(--peanut); color: var(--on-button); }
.small-button.danger { color: var(--danger); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 13px; color: var(--mist); font-weight: 700; background: var(--paper); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.tag.on { background: var(--leaf); }
.tag.off { background: var(--peanut-soft); }
.tag.none { background: var(--peanut-soft); color: var(--danger); }
.summary { display: flex; flex-wrap: wrap; gap: 24px; margin: 4px 0 16px; color: var(--mist); }
.summary b { color: var(--ink); font-size: 20px; display: block; }

@media (max-width: 560px) {
  .signin-logo { width: 120px; }
  body { font-size: 16px; }
  .wordmark span { display: none; }
  .welcome h1 { font-size: 24px; }
  .msg.me .bubble { max-width: 88%; }
}
