: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 */
/* "uFinance Compass" is a wide logo, so it is sized by width and keeps its shape when squeezed */
.logo { display: block; width: 300px; height: auto; max-width: 100%; justify-self: start; }
/* Header (top corner) keeps the original uFinance Australia logo, sized by height */
.logo.small { width: auto; height: 34px; }
.card .logo { justify-self: center; }
/* Medium logo above "Ask about any lender's policy and rates" */
.logo.hero { width: 440px; margin: 0 auto 18px; }
/* Start screen centred: logo, heading, text and example questions */
#empty { text-align: center; }
/* Example questions: two even columns of three (one column on phones) */
#empty .examples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
#empty .examples button { width: 100%; height: 100%; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
  #empty .examples { grid-template-columns: minmax(0, 1fr); }
  #empty .examples button { white-space: normal; }
}
@media (max-width: 640px) { .logo.hero { width: 300px; margin-bottom: 12px; } }

/* 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; grid-template-columns: minmax(0, 1fr); height: 100%; height: 100dvh; overflow: hidden; }
#app > * { min-width: 0; }
.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; }

/* Admin staff panel (same look as the library panel, opens from the right) */
#staff {
  position: fixed; top: 53px; right: 0; bottom: 0; width: min(440px, 100%); z-index: 3;
  background: var(--surface); border-left: 1px solid var(--line); padding: 16px; overflow: auto;
  box-shadow: -8px 0 24px rgb(0 0 0 / .06);
}
.staff-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.staff-email { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.staff-row small { color: var(--muted); }
.staff-row small.ok { color: var(--accent); }
.staff-row button { white-space: nowrap; font-size: 13px; }
.card button.ghost { width: 100%; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 400; text-decoration: underline; justify-self: center; font-size: 14px; }
.staff-row small.req { color: var(--danger); font-weight: 600; }
@media (max-width: 640px) { .who #changepw-btn, .who #staff-btn { padding: 6px 8px; font-size: 12px; } }

#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); }
#empty .uptodate { margin: 0 0 4px; font-weight: 600; }
.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; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.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 { flex: 1; min-width: 0; resize: none; max-height: 200px; border-radius: 12px; padding: 12px 14px; overflow-y: auto; }
.ask button { flex: none; border-radius: 12px; padding: 12px 18px; }
.foot { text-align: center; font-size: 12px; margin: 6px 16px 12px; }
.a, .q { overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .who span { display: none; }
  .brand span { display: none; }
  .top { padding: 8px 12px; }
  .logo.small { height: 30px; }
  #chat { padding: 16px 12px 8px; }
  #empty { padding-top: 2vh; }
  #empty h2 { font-size: 22px; line-height: 1.25; }
  #empty p { font-size: 14px; }
  .examples { margin-top: 14px; }
  .examples button { width: 100%; font-size: 14px; padding: 10px 12px; }
  .ask { width: calc(100% - 24px); }
  /* 16px stops iPhones zooming in when the box is tapped */
  .ask textarea, .card input { font-size: 16px; }
  /* Two lines tall so the hint text fits without a scroll bar */
  .ask textarea { min-height: calc(2 * 1.55em + 24px); line-height: 1.55; }
  .ask textarea::placeholder { font-size: 15px; }
  .ask button { padding: 12px 14px; }
  .foot { font-size: 11px; margin: 6px 12px calc(8px + env(safe-area-inset-bottom)); }
  .a { padding: 14px; }
  .q { max-width: 92%; }
  .card { padding: 24px; }
}
