:root {
  --bg: #f1f2f4;
  --surface: #ffffff;
  --ink: #1b1e22;
  --muted: #6b7079;
  --line: #e2e4e8;
  --shadow: 0 1px 2px rgb(16 24 40 / .04), 0 4px 14px rgb(16 24 40 / .05);
  --accent: #4d918d; /* uFinance logo teal */
  --accent-ink: #ffffff;
  --accent-soft: #e6f1f0;
  --cite: #8a5a14;
  --cite-soft: #f6ead6;
  --danger: #a33a2c;
  --radius: 10px;
  --serif: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --sans: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a19; --surface: #1d2422; --ink: #e8ebe8; --muted: #9aa49f; --line: #2e3734; --shadow: none;
    --accent: #6fb29f; --accent-ink: #0f1513; --accent-soft: #233430; --cite: #e2b46a; --cite-soft: #3a2f1e; --danger: #e07a6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--sans); }
[hidden] { display: none !important; }
/* Premium touch: soft lift on the header, cards, answers, example questions and the ask box */
.top, .card, .a, .examples button, .ask textarea { box-shadow: var(--shadow); }
a { color: var(--accent); }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--muted); }

button {
  font: inherit; cursor: pointer; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); padding: 10px 16px; font-weight: 600;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); padding: 6px 12px; font-weight: 500; }
button.ghost:hover { border-color: var(--muted); }
input, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Sign-in */
.center { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: min(420px, 100%); display: grid; gap: 12px; }
.card h1 { margin: 0; font-size: 26px; }
.card p { margin: 0; }
.card label { font-weight: 600; font-size: 13px; margin-top: 6px; }
.msg { min-height: 1.4em; font-size: 14px; }
.msg.ok { color: var(--accent); }
.msg.err { color: var(--danger); }
.mark { width: 34px; height: 34px; border-radius: 8px; background:
  linear-gradient(135deg, var(--accent) 0 50%, transparent 50%), linear-gradient(var(--cite-soft), var(--cite-soft)); border: 1px solid var(--line); }
.mark.small { width: 22px; height: 22px; border-radius: 6px; }
/* uFinance logo: dark text, so in dark mode it sits on a white chip to stay readable */
.logo { display: block; height: 64px; width: auto; max-width: 100%; justify-self: start; }
.logo.small { height: 34px; }
.card .logo { justify-self: center; }

/* Faint uFinance "u" watermark, fixed in the middle of the page behind everything */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: url("watermark.png") center 55% / auto min(70vh, 560px) no-repeat;
  opacity: .05;
}
@media (prefers-color-scheme: dark) { body::before { opacity: .07; } }
@media (prefers-color-scheme: dark) {
  .logo { background: #fff; padding: 6px 10px; border-radius: 8px; box-sizing: content-box; }
  .logo.small { padding: 4px 7px; border-radius: 6px; }
}

/* App shell */
#app { display: grid; grid-template-rows: auto 1fr auto auto; height: 100%; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 2; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 600; font-size: 17px; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
#library-btn { font-size: 13px; }
.top button { white-space: nowrap; }

#library {
  position: fixed; top: 53px; left: 0; bottom: 0; width: min(380px, 100%); z-index: 3;
  background: var(--surface); border-right: 1px solid var(--line); padding: 16px; overflow: auto;
  box-shadow: 8px 0 24px rgb(0 0 0 / .06);
}
.lib-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.lib-head h2 { margin: 0; font-size: 19px; }
.lib-head p { margin: 2px 0 12px; font-size: 13px; }
#lib-filter { margin-bottom: 12px; }
.lender { margin: 14px 0 4px; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.doc { display: flex; justify-content: space-between; gap: 8px; padding: 7px 8px; border-radius: 6px; font-size: 14px; text-decoration: none; color: var(--ink); }
.doc:hover { background: var(--accent-soft); }
.doc small { color: var(--muted); white-space: nowrap; }
.doc.bad small { color: var(--danger); white-space: normal; }

#chat { overflow-y: auto; padding: 24px 16px 8px; }
#empty, #thread { max-width: 780px; margin: 0 auto; }
#empty { padding-top: 6vh; }
#empty h2 { font-size: 30px; margin: 0 0 8px; color: var(--ink); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.examples button { background: var(--surface); color: var(--ink); border: 1px solid var(--line); font-weight: 400; text-align: left; font-size: 14px; }
.examples button:hover { border-color: var(--accent); }

#thread { list-style: none; padding: 0; display: grid; gap: 20px; }
.q { justify-self: end; max-width: 85%; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.a { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.a .body > :first-child { margin-top: 0; }
.a .body > :last-child { margin-bottom: 0; }
.a .body h3, .a .body h4 { font-family: var(--serif); margin: 14px 0 6px; }
.a .body ul, .a .body ol { padding-left: 22px; }
.a .body table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 8px 0; display: block; overflow-x: auto; }
.a .body th, .a .body td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.a .body th { background: var(--accent-soft); }
.a.error { border-color: var(--danger); color: var(--danger); }
.cite {
  display: inline-block; min-width: 1.5em; padding: 0 5px; margin: 0 1px; border-radius: 5px; text-align: center;
  font-size: 11.5px; font-weight: 700; line-height: 1.6; vertical-align: 1px; text-decoration: none;
  background: var(--cite-soft); color: var(--cite);
}
.sources { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 6px; }
.sources a { font-size: 12.5px; text-decoration: none; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; }
.sources a:hover { border-color: var(--cite); color: var(--ink); }
.sources a b { color: var(--cite); margin-right: 4px; }
.sources a.unused { display: none; }
.thinking { color: var(--muted); font-style: italic; }
.thinking::after { content: '…'; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.ask { display: flex; gap: 8px; max-width: 780px; width: calc(100% - 32px); margin: 8px auto 0; align-items: end; }
.ask textarea { resize: none; max-height: 200px; border-radius: 12px; padding: 12px 14px; }
.ask button { border-radius: 12px; padding: 12px 18px; }
.foot { text-align: center; font-size: 12px; margin: 6px 16px 12px; }

@media (max-width: 640px) {
  .who span { display: none; }
  .brand span { display: none; }
  #empty h2 { font-size: 24px; }
  .card { padding: 24px; }
}
