/* FBR Tax Research — plain, utilitarian research tool.
   Self-hosted type (CSP: default-src 'self'):
     system sans   — UI chrome (header, buttons, labels)
     Newsreader    — answer body text
     IBM Plex Mono — citations and metadata */

@font-face {
  font-family: "Newsreader";
  src: url("/static/fonts/newsreader.woff2") format("woff2");
  font-weight: 400 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("/static/fonts/newsreader-italic.woff2") format("woff2");
  font-weight: 400 700; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/static/fonts/ibm-plex-mono.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #fafaf8;
  --ink: #1d1d1b;
  --muted: #6f6f68;
  --accent: #1d4a7a;
  --accent-dark: #163a61;
  --rule: #e3e3dd;
  --rule-dark: #c9c9c0;
  --amber: #8a6a1f;
  --red: #a03c2e;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --measure: 44rem;
  --sidebar: 15.5rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 400 .9375rem/1.55 var(--sans);
  padding-bottom: 180px;
}

/* ------------------------------------------------------ sidebar --- */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  background: #f4f4f0;
  border-right: 1px solid var(--rule);
  z-index: 20;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid var(--rule);
}

.sidebar-title {
  margin: 0;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar-head .ghost { padding: .4em .8em; font-size: .75rem; }

.history { flex: 1; overflow-y: auto; padding: .35rem 0; }

.session {
  display: flex;
  align-items: center;
  width: 100%;
  border-bottom: 1px solid transparent;
}
.session:hover { background: #eaeae4; }
.session.active { background: #e4e9ef; box-shadow: inset 2px 0 0 var(--accent); }

/* The label is the click target; the delete control sits alongside it rather
   than nested inside, since a button cannot contain another button. */
.session-open {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  text-align: left;
  padding: .6rem .25rem .6rem 1rem;
  font: 400 .8125rem/1.35 var(--sans);
}
.session-open:hover { background: none; }
.session.active .session-open { font-weight: 600; }

.session-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta {
  display: block;
  margin-top: .15rem;
  font: 400 .6875rem/1.3 var(--mono);
  color: var(--muted);
}

.session-delete {
  flex: none;
  background: none;
  border: 0;
  border-radius: 3px;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1;
  padding: .35em .55em;
  margin-right: .4rem;
  opacity: 0;
}
.session:hover .session-delete,
.session-delete:focus-visible { opacity: 1; }
.session-delete:hover { background: #dcdcd4; color: var(--red); }

.history-empty {
  margin: 0;
  padding: 1rem;
  font-size: .8125rem;
  color: var(--muted);
}

.sidebar-toggle { display: none; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(29, 29, 27, .35);
  border: 0;
  border-radius: 0;
  padding: 0;
  z-index: 15;
}

/* ------------------------------------------------------ header ---- */

.shell { margin-left: var(--sidebar); }

.topbar { border-bottom: 1px solid var(--rule); }

.topbar-inner {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -.01em;
}

.corpus-note {
  margin: .2rem 0 0;
  font-size: .75rem;
  color: var(--muted);
}

/* ------------------------------------------------------ buttons --- */

button {
  font: 500 .8125rem/1 var(--sans);
  cursor: pointer;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  padding: .55em 1.1em;
}
button:hover { background: var(--accent-dark); }
button:disabled { opacity: .55; cursor: wait; }

.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule-dark);
  white-space: nowrap;
}
.ghost:hover { background: #f0f0ec; }

/* ------------------------------------------------------ intro ----- */

main { max-width: var(--measure); margin: 0 auto; padding: 0 1.25rem; }

.intro { padding: 2.5rem 0 1rem; }

.intro-note {
  margin: 0 0 1.5rem;
  color: var(--muted);
  max-width: 34rem;
}

.examples { list-style: none; margin: 0; padding: 0; }
.examples button {
  display: block;
  width: 100%;
  background: none;
  color: var(--accent);
  border: 0;
  border-radius: 0;
  border-top: 1px solid var(--rule);
  padding: .7rem .1rem;
  font-size: .875rem;
  font-weight: 400;
  text-align: left;
}
.examples li:last-child button { border-bottom: 1px solid var(--rule); }
.examples button:hover { background: none; text-decoration: underline; }

/* ------------------------------------------------------ entries --- */

.entries { display: flex; flex-direction: column; }

.entry { padding: 1.5rem 0; border-bottom: 1px solid var(--rule); }

.entry.query { padding-bottom: 0; border-bottom: 0; }
.entry.query + .entry { padding-top: .85rem; }
.entry.query .entry-body {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.45;
}

.entry.finding .entry-body {
  font: 400 1.0625rem/1.7 var(--serif);
  max-width: 40rem;
}
.entry.finding .entry-body p { margin: 0 0 .9em; }
.entry.finding .entry-body p:last-child { margin-bottom: 0; }

.tag {
  display: inline-block;
  margin-bottom: .5rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--amber);
}
.entry.error .tag { color: var(--red); }

.entry.abstained .entry-body, .entry.error .entry-body { color: #4d4a42; }
.entry.error .entry-body { color: #6e352b; }

.entry-meta {
  margin-top: .9rem;
  font: 400 .6875rem/1.4 var(--mono);
  color: var(--muted);
}

.entry.thinking .entry-body { color: var(--muted); font-style: italic; }

/* ------------------------------------------------------ sources --- */

.sources { margin-top: 1.25rem; }
.sources-heading {
  margin: 0 0 .25rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
}

.source { border-top: 1px solid var(--rule); }
.source summary {
  cursor: pointer;
  padding: .5rem 0;
  font: 400 .78rem/1.5 var(--mono);
  color: var(--accent);
  list-style: none;
  display: flex;
  gap: .7em;
  align-items: baseline;
}
.source summary::-webkit-details-marker { display: none; }
.source summary::before { content: "+"; color: var(--rule-dark); }
.source[open] summary::before { content: "−"; color: var(--accent); }
.source summary:hover span:first-of-type { text-decoration: underline; }
.source .src-doc { color: var(--muted); }
.source p {
  margin: .1rem 0 .8rem 1.2rem;
  font: 400 .9375rem/1.65 var(--serif);
  color: #44443f;
}
.source a {
  display: inline-block;
  margin: 0 0 .8rem 1.2rem;
  font-size: .75rem;
  color: var(--accent);
}

.copy {
  margin-top: 1rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
  font-size: .75rem;
  padding: .45em .9em;
}
.copy:hover { background: #f0f0ec; color: var(--ink); }

/* ------------------------------------------------------ composer -- */

.composer-dock {
  position: fixed;
  left: var(--sidebar); right: 0; bottom: 0;
  background: linear-gradient(to top, var(--bg) 80%, transparent);
  padding: 1.25rem 1.25rem .6rem;
}

.composer {
  max-width: var(--measure);
  margin: 0 auto;
  display: flex;
  align-items: stretch;
  background: #fff;
  border: 1px solid var(--rule-dark);
  border-radius: 6px;
}
.composer:focus-within { border-color: var(--accent); }

.form-error {
  flex-basis: 100%;
  margin: .4rem 0 0;
  font-size: .8125rem;
  color: #a3372b;
}

textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  padding: .8rem 1rem;
  font: 400 .9375rem/1.5 var(--sans);
  color: var(--ink);
}
textarea::placeholder { color: #a3a39a; }

#send { border-radius: 0 5px 5px 0; padding: 0 1.4em; }

.disclaimer {
  max-width: var(--measure);
  margin: .5rem auto 0;
  font-size: .6875rem;
  color: var(--muted);
  text-align: center;
}

/* ------------------------------------------------------ misc ------ */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Below this width the sidebar becomes an off-canvas drawer over the
   transcript, so the reading column keeps the full viewport. */
@media (max-width: 880px) {
  .shell { margin-left: 0; }
  .composer-dock { left: 0; }
  .sidebar-toggle { display: inline-block; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .18s ease-out;
    box-shadow: 0 0 2rem rgba(29, 29, 27, .18);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

@media (min-width: 881px) {
  /* The drawer scrim is drawer-only chrome; never show it beside a docked sidebar. */
  .scrim { display: none; }
}

@media (max-width: 640px) {
  .topbar-inner { align-items: flex-start; }
  body { padding-bottom: 200px; }
}
