/* =========================================================
   MarketIQ — design tokens
   A quiet "financial report / ledger" look: warm paper,
   deep navy ink, pine-green accent, copper for highlights.
   ========================================================= */
:root {
  --paper: #EFEBDD;
  --surface: #FFFFFF;
  --line: #D9D3BF;

  --ink: #1A2333;
  --ink-soft: #55607A;

  --pine: #1B4B43;
  --pine-dark: #123832;
  --pine-tint: #E1EAE6;

  --copper: #B5651D;
  --copper-tint: #F6E7D6;

  --leaf: #2F7D5C;
  --brick: #A8412F;
  --brick-tint: #F5E1DC;

  --radius-s: 8px;
  --radius-m: 14px;

  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
  --font-body: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; }

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1.4rem 1.2rem 0;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.8rem; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--pine);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
}
.brand h1 { font-family: var(--font-display); font-size: 1.4rem; margin: 0; font-weight: 600; }
.tagline { margin: 0.1rem 0 0; font-size: 0.82rem; color: var(--ink-soft); }

.status-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--ink-soft); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brick); display: inline-block; }
.status-dot.is-ready { background: var(--leaf); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  width: 34px; height: 34px;
  font-size: 1rem;
  color: var(--ink);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--pine); }

/* ---------- Chat area ---------- */
.chat-area { flex: 1; display: flex; flex-direction: column; padding: 1.2rem 0 1.4rem; min-height: 0; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 0.2rem 0.1rem 1rem;
}

.msg {
  max-width: 88%;
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-m);
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: var(--pine);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg.assistant .tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--pine);
  background: var(--pine-tint);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin-bottom: 0.45rem;
}
.msg.system {
  align-self: center;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
  max-width: 100%;
  background: transparent;
  padding: 0.4rem 0.6rem;
}
.msg.error {
  align-self: flex-start;
  background: var(--brick-tint);
  border: 1px solid #E1BCB2;
  color: var(--brick);
}

/* ---------- Input row ---------- */
.chat-form {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-m);
  padding: 0.5rem 0.6rem;
}
.chat-form textarea {
  flex: 1;
  border: none;
  resize: none;
  font-size: 0.95rem;
  padding: 0.5rem 0.4rem;
  max-height: 120px;
  background: transparent;
  color: var(--ink);
}
.chat-form textarea:focus { outline: none; }

.send-btn {
  background: var(--pine);
  color: #fff;
  border: none;
  border-radius: var(--radius-s);
  padding: 0.65rem 1.15rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.send-btn:hover { background: var(--pine-dark); }
.send-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.disclaimer { text-align: center; font-size: 0.75rem; color: var(--ink-soft); margin: 0.7rem 0 1.2rem; }

/* ---------- Settings drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(26,35,51,0.42);
  display: none;
  align-items: stretch;
  justify-content: flex-end;
  z-index: 50;
}
.drawer-backdrop.is-open { display: flex; }

.drawer {
  width: 380px;
  max-width: 92vw;
  background: var(--paper);
  border-left: 1px solid var(--line);
  padding: 1.3rem 1.4rem 1.6rem;
  overflow-y: auto;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.4rem; }
.drawer-head h2 { font-family: var(--font-display); font-size: 1.15rem; margin: 0; font-weight: 600; }

.field-label { display: block; margin-top: 1rem; margin-bottom: 0.35rem; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); }
input[type="text"], input[type="password"] {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  padding: 0.65rem 0.8rem;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--ink);
}
input:focus { outline: 2px solid var(--pine); outline-offset: 1px; }
.hint { font-size: 0.78rem; color: var(--ink-soft); margin: 0.35rem 0 0; line-height: 1.5; }
.hint code { background: var(--pine-tint); padding: 0.05rem 0.3rem; border-radius: 4px; }

.drawer-actions { display: flex; justify-content: space-between; gap: 0.6rem; margin-top: 1.3rem; }
.primary-btn {
  background: var(--pine); color: #fff; border: none;
  border-radius: var(--radius-s); padding: 0.65rem 1.1rem;
  font-weight: 600; font-size: 0.88rem; cursor: pointer;
}
.primary-btn:hover { background: var(--pine-dark); }
.ghost-btn {
  background: transparent; border: 1.5px solid var(--line); color: var(--ink);
  border-radius: var(--radius-s); padding: 0.6rem 1rem; font-size: 0.85rem; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--pine); color: var(--pine-dark); }
.save-note { margin-top: 0.7rem; font-size: 0.82rem; color: var(--ink-soft); }
.save-note.is-good { color: var(--leaf); }
.save-note.is-bad { color: var(--brick); }

@media (max-width: 640px) {
  .app { padding: 1rem 0.8rem 0; }
  .brand h1 { font-size: 1.2rem; }
  .tagline { display: none; }
}

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