/* Minimal, framework-free styling for mp-analytics. Deliberately plain: working
   functionality first, visual polish only after the demo (see CLAUDE.md). */

:root {
  --bg: #f5f4f2;
  --card: #ffffff;
  --ink: #1e1b18;
  --muted: #6b645d;
  --line: #e2ddd6;
  --accent: #6f4e37;      /* coffee brown */
  --ok-bg: #e7f4e8;
  --ok-ink: #1f6b2c;
  --warn-bg: #fdf3d3;
  --warn-ink: #7a5b00;
  --neg: #a23b2c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

.wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 64px; }

header.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 20px;
}
header.topbar h1 { font-size: 20px; margin: 0; }
header.topbar .who { color: var(--muted); font-size: 14px; }
header.topbar nav a, header.topbar form { margin-left: 14px; }
header.topbar a { color: var(--accent); text-decoration: none; }
header.topbar a:hover { text-decoration: underline; }

.period { font-size: 28px; font-weight: 700; margin: 8px 0 20px; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 620px) { .cards { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px;
}
.card .label { color: var(--muted); font-size: 14px; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.card .note { color: var(--muted); font-size: 12px; margin-top: 6px; }

h2.section { font-size: 16px; margin: 28px 0 10px; }

table { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
tr.holdings td { color: var(--muted); font-style: italic; }
.neg { color: var(--neg); }

.banner { border-radius: 12px; padding: 12px 16px; margin-top: 6px; }
.banner.ok { background: var(--ok-bg); color: var(--ok-ink); }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.warn ul { margin: 8px 0 0; padding-left: 20px; }

.muted { color: var(--muted); }
.footer-note { color: var(--muted); font-size: 13px; margin-top: 28px; }

.auth { max-width: 420px; margin: 40px auto; text-align: center; }
.auth .card { text-align: left; }
button {
  font: inherit; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
input[type=text] {
  font: inherit; width: 100%; padding: 10px 12px; margin: 8px 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
}
.status { color: var(--muted); font-size: 14px; margin-top: 10px; min-height: 1.2em; }
.alert { color: var(--neg); }

h3.subsection { font-size: 14px; margin: 20px 0 8px; color: var(--muted); }

/* ===========================================================================
   Chat -- an app screen, not a page. The whole viewport is: a thin top bar, a
   scrollable message feed (the ONLY scroller), and a pinned composer. Height is
   the *visible* viewport (--app-h, set from visualViewport in chat.js) so the
   composer stays above the mobile keyboard.
   =========================================================================== */
:root { --user-bubble: #ece6df; }

body.chat-screen { overflow: hidden; }
body.chat-screen .wrap {
  position: fixed;
  top: var(--app-top, 0px);
  left: 0; right: 0;
  height: 100vh;
  height: 100dvh;
  height: var(--app-h, 100dvh);
  max-width: 820px;
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.chatbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.chatbar-title { font-weight: 700; font-size: 16px; white-space: nowrap; }
.chatbar-model { flex: 1 1 auto; min-width: 0; display: flex; }
.chatbar-model select {
  font: inherit; font-size: 13px; width: 100%; min-width: 0;
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink);
}
.chatbar-nav { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; }
.chatbar-nav form { display: flex; }
.chatbar-nav a, .linkbtn {
  color: var(--accent); text-decoration: none; font-size: 13px;
  background: none; border: none; padding: 0; cursor: pointer; font: inherit;
}
.chatbar-nav a:hover, .linkbtn:hover { text-decoration: underline; }

.chatlog {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px clamp(12px, 4vw, 28px);
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}

.chat-hint { margin: auto; max-width: 460px; text-align: center; color: var(--muted); }
.chat-hint p { margin: 0 0 8px; line-height: 1.5; }
.chat-hint-examples { font-size: 14px; }

.msg { display: flex; max-width: 100%; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }
.msg.user .bubble {
  max-width: 82%;
  background: var(--user-bubble); color: var(--ink);
  padding: 9px 14px; border-radius: 16px; border-bottom-right-radius: 5px;
  white-space: pre-wrap; word-wrap: break-word; line-height: 1.5;
}

/* Assistant reply: full column width, no bubble, just typeset text. */
.msg.assistant { width: 100%; }
.answer { width: 100%; line-height: 1.6; color: var(--ink); }
.answer > *:first-child { margin-top: 0; }
.answer > *:last-child { margin-bottom: 0; }
.answer p { margin: 0 0 10px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer strong { font-weight: 700; }
.answer em { font-style: italic; }
.answer h1, .answer h2, .answer h3 { line-height: 1.3; margin: 16px 0 8px; }
.answer h1 { font-size: 20px; } .answer h2 { font-size: 18px; } .answer h3 { font-size: 16px; }
.answer code {
  background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em;
}
.answer pre {
  background: rgba(0,0,0,.05); padding: 10px 12px; border-radius: 8px;
  overflow-x: auto; margin: 0 0 10px;
}
.answer pre code { background: none; padding: 0; }
.answer blockquote {
  margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--line);
  color: var(--muted);
}
/* Tables scroll horizontally rather than breaking the layout. */
.answer table {
  display: block; width: max-content; max-width: 100%; overflow-x: auto;
  border-collapse: collapse; margin: 4px 0 12px; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.answer th, .answer td {
  border: 1px solid var(--line); padding: 6px 11px; text-align: left; white-space: nowrap;
}
.answer thead th { background: var(--bg); font-weight: 600; }

.msg.assistant.error .answer { color: var(--neg); white-space: pre-wrap; }

/* Waiting indicator: pulsing dots + a timed stage label. */
.pending-body { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: chat-blink 1.2s infinite ease-in-out both;
}
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-blink {
  0%, 80%, 100% { opacity: .25; transform: scale(.7); }
  40% { opacity: 1; transform: scale(1); }
}
.pending-body .stage { font-size: 14px; }

/* Composer: pinned bottom, auto-growing textarea + round send button. */
.chatform {
  flex: 0 0 auto;
  padding: 10px clamp(12px, 4vw, 28px);
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--card);
}
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 22px; padding: 5px 5px 5px 14px;
}
.composer textarea {
  flex: 1 1 auto; min-width: 0;
  font: inherit; line-height: 1.4; color: var(--ink);
  border: none; background: transparent; resize: none; outline: none;
  padding: 7px 0; max-height: 160px; overflow-y: auto;
}
.sendbtn {
  flex: 0 0 auto;
  width: 38px; height: 38px; padding: 0; border: none; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; cursor: pointer;
  transition: opacity .15s;
}
.sendbtn:disabled { opacity: .35; cursor: default; }

.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;
}
