/* ── reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:        #ffffff;
  --sidebar:   #f9f9f9;
  --bubble-u:  #10a37f;
  --bubble-a:  #ffffff;
  --accent:    #10a37f;
  --accent-dk: #0d8c6d;
  --text:      #0d0d0d;
  --text-dim:  #6e6e80;
  --text-tool: #b45309;
  --text-cite: #0369a1;
  --code-bg:   #f4f4f5;
  --border:    #e5e5e5;
  --font:      'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Consolas', 'Courier New', monospace;
}
html, body { height: 100%; min-height: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100dvh; /* use dvh on mobile so address bar doesn't eat space */
}

/* ── username modal ────────────────────────────────────────────────── */
#username-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
#username-modal.hidden { display: none; }
#username-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem 2.2rem;
  max-width: 380px; width: 90%;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
}
#username-box h2 { font-size: 1.25rem; margin-bottom: .4rem; color: var(--text); }
#username-box p  { font-size: .85rem; color: var(--text-dim); margin-bottom: 1.2rem; }
#username-input {
  width: 100%; padding: .55rem .75rem;
  background: #fff; color: var(--text);
  border: 1px solid #d1d5db; border-radius: 7px;
  font-size: .95rem; font-family: var(--font);
  outline: none; margin-bottom: .9rem;
}
#username-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(16,163,127,.15); }
#username-submit {
  width: 100%; padding: .55rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: 7px;
  font-size: .95rem; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
#username-submit:hover { background: var(--accent-dk); }
.username-note { font-size: .75rem; color: var(--text-dim); margin-top: .7rem; }

/* ── loading overlay ───────────────────────────────────────────────── */
#splash {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 1000;
  transition: opacity .4s ease;
}
#splash.hidden { opacity: 0; pointer-events: none; }
#splash-icon { font-size: 4rem; margin-bottom: .5rem; animation: pulse 1.4s ease-in-out infinite; }
#splash h1   { font-size: 1.4rem; font-weight: 700; color: var(--text); margin-bottom: .25rem; }
#splash p    { font-size: .85rem; color: var(--text-dim); margin-bottom: 1.8rem; }
#splash-track {
  width: 340px; height: 6px;
  background: #e5e7eb; border-radius: 4px; overflow: hidden;
}
#splash-bar {
  height: 100%; width: 15%;
  background: var(--accent); border-radius: 4px;
  transition: width .35s ease;
}
#splash-status {
  font-size: .8rem; color: var(--text-dim); margin-top: .75rem;
  font-style: italic; min-height: 1.2em;
}
@keyframes pulse {
  0%,100% { transform: scale(1);   opacity: 1;   }
  50%      { transform: scale(1.1); opacity: .7; }
}

/* ── banner ────────────────────────────────────────────────────────── */
#banner {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: .65rem 1rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;  /* never let the banner compress */
}
#banner h1 { font-size: .95rem; font-weight: 600; color: var(--text); }
#banner-right { display: flex; align-items: center; gap: .75rem; }
#banner span { font-size: .75rem; color: var(--text-dim); }
#session-pill {
  font-size: .75rem; background: #f3f4f6;
  color: var(--text-dim); padding: .25rem .7rem; border-radius: 20px;
  cursor: pointer; user-select: none; border: 1px solid var(--border);
  transition: background .15s;
}
#session-pill:hover { background: #e5e7eb; color: var(--text); }

/* ── layout ────────────────────────────────────────────────────────── */
#layout {
  display: flex; flex: 1; min-height: 0; overflow: hidden;
  opacity: 0; transition: opacity .4s ease;
}
#layout.visible { opacity: 1; }

/* ── sidebar ───────────────────────────────────────────────────────── */
#sidebar {
  width: 220px; min-width: 160px;
  background: var(--sidebar);
  display: flex; flex-direction: column;
  overflow: hidden; flex-shrink: 0; min-height: 0;
  border-right: 1px solid var(--border);
}
.side-section { padding: .7rem .85rem .3rem; }
.side-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-dim);
  margin-bottom: .35rem;
}
#tools-list {
  list-style: none; font-family: var(--font-mono);
  font-size: .72rem; color: var(--text-dim);
  overflow-y: auto; flex: 0 0 auto; max-height: 160px;
  padding: 0 .85rem .5rem;
}
#tools-list li { padding: .2rem 0; }
#tools-list li::before { content: '⚙ '; opacity: .45; }
.side-divider { border: none; border-top: 1px solid var(--border); margin: .4rem .85rem; }
#examples { overflow-y: auto; padding: 0 .6rem .75rem; flex: 1; }
.ex-btn {
  display: block; width: 100%;
  background: none; border: 1px solid transparent;
  color: var(--text-dim); font-family: var(--font); font-size: .8rem;
  text-align: left; cursor: pointer; padding: .4rem .6rem;
  border-radius: 6px; line-height: 1.35;
  transition: background .15s, border-color .15s, color .15s;
}
.ex-btn:hover {
  background: #fff; border-color: var(--border);
  color: var(--text);
}

/* ── chat area ─────────────────────────────────────────────────────── */
#chat-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: #fff; }
#chat {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 1.5rem 0;
  scroll-behavior: smooth;
}
#chat::-webkit-scrollbar { width: 6px; }
#chat::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* ── messages — ChatGPT full-width row layout ──────────────────────── */
.msg {
  width: 100%;
  padding: .75rem 1rem;
  display: flex;
  gap: .75rem;
  align-items: flex-start;
}
.msg-user  { flex-direction: row-reverse; background: #fff; }
.msg-agent { background: #f9f9f9; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; flex-shrink: 0; margin-top: .1rem;
}
.msg-user  .msg-avatar { background: var(--accent); color: #fff; }
.msg-agent .msg-avatar { background: #10a37f1a; color: var(--accent); border: 1px solid #10a37f33; }

.bubble {
  max-width: 720px; width: 100%;
  font-size: .93rem; line-height: 1.65;
  word-break: break-word; color: var(--text);
}
.msg-user .bubble {
  max-width: 600px;
  background: #f3f4f6;
  border-radius: 12px 12px 2px 12px;
  padding: .55rem .85rem;
}
.msg-agent .bubble { padding: .1rem 0; }

/* ── markdown inside bubble ────────────────────────────────────────── */
.bubble h1,.bubble h2,.bubble h3 { margin: .75rem 0 .35rem; line-height: 1.3; color: var(--text); }
.bubble h1 { font-size: 1.1rem; }
.bubble h2 { font-size: 1rem; }
.bubble h3 { font-size: .95rem; }
.bubble p  { margin: .4rem 0; }
.bubble ul,.bubble ol { padding-left: 1.5rem; margin: .4rem 0; }
.bubble li { margin: .25rem 0; }
.bubble code {
  font-family: var(--font-mono); font-size: .84em;
  background: var(--code-bg); color: #c7254e;
  padding: .15em .4em; border-radius: 4px;
  border: 1px solid #e5e7eb;
}
.bubble pre {
  background: var(--code-bg);
  font-family: var(--font-mono); font-size: .82rem;
  padding: .85rem 1rem; border-radius: 8px; overflow-x: auto;
  margin: .6rem 0; border: 1px solid var(--border);
}
.bubble pre code { background: none; border: none; padding: 0; color: #374151; }
.bubble a { color: var(--text-cite); text-underline-offset: 3px; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: .6rem 0; }
.bubble strong { color: var(--text); font-weight: 600; }
.bubble blockquote {
  border-left: 3px solid #d1d5db; padding-left: .75rem;
  color: var(--text-dim); margin: .5rem 0;
}
.bubble table { border-collapse: collapse; width: 100%; margin: .5rem 0; font-size: .88rem; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: .4rem .65rem; text-align: left; }
.bubble th { background: #f3f4f6; font-weight: 600; }

/* ── tool / plan / cite lines ──────────────────────────────────────── */
.line-plan {
  color: var(--text-dim); font-size: .78rem; font-style: italic;
  padding: .15rem 0; display: flex; align-items: center; gap: .3rem;
}
.line-tool {
  color: var(--text-tool); font-family: var(--font-mono); font-size: .78rem;
  padding: .1rem 0; background: #fffbeb; border-radius: 4px;
  padding: .2rem .5rem; margin: .1rem 0; display: inline-block;
  border: 1px solid #fde68a;
}
.line-err {
  color: #b91c1c; font-size: .82rem;
  background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 8px; padding: .7rem .9rem; margin: .4rem 0;
}
.line-err strong { display: block; margin-bottom: .3rem; color: #991b1b; }
.line-err code   { background: #fee2e2; color: #b91c1c; font-size: .78rem; }
.line-err .hint  { color: #6b7280; margin-top: .35rem; font-size: .8rem; }

/* citations */
.citations {
  margin-top: .6rem; padding-top: .5rem;
  border-top: 1px solid var(--border);
  font-size: .78rem;
}
.citations strong { display: block; margin-bottom: .3rem; color: var(--text-dim); font-weight: 600; }
.citations a { color: var(--text-cite); }
.citations li { list-style: none; padding: .1rem 0; }
.citations li::before { content: '↗ '; color: var(--text-dim); }

/* streaming cursor */
.cursor::after {
  content: '▋'; color: var(--accent);
  animation: blink .7s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* separator */
.sep { border: none; border-top: 1px solid var(--border); margin: .25rem 0; opacity: .5; }

/* ── status bar ────────────────────────────────────────────────────── */
#status-bar {
  background: #fff; border-top: 1px solid var(--border);
  padding: .3rem 1rem; font-size: .75rem; color: var(--text-dim);
  display: flex; align-items: center;
  flex-shrink: 0;
}
#sse-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #10b981; margin-right: .45rem;
}
#sse-dot.busy { background: #f59e0b; animation: blink .7s step-end infinite; }

/* ── disclaimer bar ────────────────────────────────────────────────── */
#disclaimer {
  background: #fffbeb;
  border-top: 1px solid #fde68a;
  color: #92400e;
  font-size: .78rem;
  line-height: 1.45;
  padding: .45rem 1rem;
  text-align: center;
  flex-shrink: 0;
  user-select: none;
}

/* ── input row ─────────────────────────────────────────────────────── */
#input-row {
  background: #fff; border-top: 1px solid var(--border);
  padding: .75rem 1rem; display: flex; gap: .5rem; align-items: flex-end;
  flex-shrink: 0;
}
#user-input {
  flex: 1; background: #fff; color: var(--text);
  border: 1px solid #d1d5db; border-radius: 10px;
  padding: .6rem .85rem; font-family: var(--font); font-size: .93rem;
  outline: none; transition: border-color .15s, box-shadow .15s;
  resize: none; height: 44px; overflow-y: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
#user-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16,163,127,.12);
}
#user-input.tall  { height: 96px; overflow-y: auto; }
.btn {
  border: none; border-radius: 8px; cursor: pointer;
  font-family: var(--font); font-size: .87rem; font-weight: 600;
  padding: .5rem 1rem; transition: background .15s, opacity .15s;
  white-space: nowrap; height: 44px;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
#btn-send  { background: var(--accent); color: #fff; }
#btn-send:hover:not(:disabled) { background: var(--accent-dk); }
#btn-stop  {
  background: #fff; color: #b45309;
  border: 1px solid #fde68a; display: none;
}
#btn-stop:hover { background: #fffbeb; }
#btn-clear {
  background: #fff; color: var(--text-dim);
  border: 1px solid var(--border);
}
#btn-clear:hover { background: #f3f4f6; color: var(--text); }
#btn-wipe  { background: #fff; color: #dc2626; border: 1px solid #fecaca; }
#btn-wipe:hover { background: #fef2f2; }

/* ── responsive ────────────────────────────────────────────────────── */

/* tablet — hide sidebar, keep buttons */
@media (max-width: 768px) {
  #sidebar { display: none; }

  #banner h1 { font-size: .85rem; }
  #banner-right { gap: .45rem; }

  .bubble { font-size: .9rem; }

  #splash-track { width: min(340px, 80vw); }
}

/* mobile — full reflow */
@media (max-width: 520px) {
  /* banner */
  #banner { padding: .5rem .75rem; }
  #banner h1 { font-size: .8rem; }
  #banner span { font-size: .7rem; }
  #session-pill { font-size: .7rem; padding: .2rem .55rem; }

  /* splash */
  #splash h1 { font-size: 1.15rem; }
  #splash-track { width: 80vw; }

  /* chat */
  #chat { padding: 1rem 0; }
  .msg { padding: .6rem .65rem; gap: .55rem; }
  .bubble { font-size: .88rem; line-height: 1.6; }
  .msg-user .bubble { max-width: 100%; }

  /* input row — stack textarea above buttons */
  #input-row {
    flex-wrap: wrap;
    padding: .6rem .65rem;
    gap: .4rem;
  }
  #user-input {
    flex: 1 1 100%;   /* full width on its own line */
    order: 0;
    height: 44px;
  }
  #user-input.tall { height: 80px; }

  #btn-send  { order: 1; flex: 1; }
  #btn-stop  { order: 2; flex: 1; }

  /* hide secondary action buttons on very small screens */
  #btn-clear, #btn-wipe { display: none; }

  /* disclaimer */
  #disclaimer { font-size: .72rem; padding: .35rem .65rem; }

  /* status bar */
  #status-bar { padding: .25rem .65rem; font-size: .7rem; }

  /* username modal */
  #username-box { padding: 1.5rem 1.2rem; }
}

/* ── pipeline stage indicators ─────────────────────────────────────── */
.line-intent {
  font-size: .78rem;
  color: #6366f1;
  padding: .12rem 0;
  opacity: .85;
}

.line-eval {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-left: 3px solid #6366f1;
  border-radius: 6px;
  padding: .55rem .75rem;
  margin: .3rem 0;
  font-size: .8rem;
}

.eval-overall {
  display: block;
  font-size: .82rem;
  color: var(--text);
  margin-bottom: .3rem;
}

.eval-claims {
  list-style: none;
  padding: 0;
  margin: 0 0 .25rem 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

.eval-claims li {
  font-size: .77rem;
  color: var(--text-dim);
  padding-left: .5rem;
}

.eval-claim-text {
  font-style: italic;
}

.eval-regional {
  font-size: .76rem;
  color: #0369a1;
  margin-top: .2rem;
}
