/*
  The Insight Navigator - Perspicacious master brand, Navigator as endorsed
  sub-brand.

  Headings Georgia (fallback serif); body Segoe UI with a system stack behind
  it. Segoe UI is Windows-native and is deliberately not embedded as a webfont.

  Structure is navy and teal; amber is the single accent. The remaining pillar
  colours are declared for use as accents but the interface stays restrained.

  Accessibility: every foreground/background pair below meets WCAG 2.1 AA on
  white or on the navy panel. Focus is always visible, and motion respects
  prefers-reduced-motion.
*/

:root {
  --navy: #1a142e;
  --teal-dark: #17505a;
  --teal: #317d8d;
  --amber: #f6a358;
  --rose: #aa3b57;
  --coral: #e24e58;
  --purple: #612756;
  --salmon: #f36f55;

  --ink: #1a142e;
  --ink-muted: #55506a;
  --ink-quiet: #6b6579;

  --page: #f7f6f9;
  --surface: #ffffff;
  --surface-sunk: #f1eff5;
  /* --line is decorative: dividers and table rules.
     --line-strong draws the edge of an interactive control (inputs, quiet
     buttons, the composer) and so has to clear 3:1 against every surface it
     sits on, per WCAG 1.4.11. It does, on white, page and sunk panel alike -
     see tests/contrast.test.js. */
  --line: #ddd9e4;
  --line-strong: #8e879f;

  --focus: #17505a;

  --radius: 6px;
  --radius-lg: 10px;

  --font-heading: Georgia, 'Times New Roman', serif;
  --font-body: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'Cascadia Mono', Consolas, 'SFMono-Regular', Menlo, monospace;

  --measure: 68ch;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

/*
  The views below set an explicit `display`, which would otherwise beat the
  user-agent rule behind the `hidden` attribute and leave every view on screen
  at once. Hidden must win.
*/
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.25;
  color: var(--navy);
  margin: 0 0 0.5em;
}

p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }

a {
  color: var(--teal-dark);
  text-underline-offset: 0.15em;
}
a:hover { color: var(--navy); }

.tm {
  font-size: 0.55em;
  vertical-align: super;
  letter-spacing: 0;
}

.mono { font-family: var(--font-mono); font-size: 0.95em; }

/* ------------------------------------------------------------ focus + a11y */

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Only remove the default ring where :focus-visible is supported. */
:is(button, a, input, textarea, [tabindex]):focus:not(:focus-visible) {
  outline: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 100;
  background: var(--navy);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  transition: top 120ms ease-in-out;
}
.skip-link:focus { top: 0.5rem; }

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

.button {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.2;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 120ms ease-in-out, border-color 120ms ease-in-out;
}
.button:disabled { cursor: not-allowed; opacity: 0.55; }

.button--primary {
  background: var(--teal-dark);
  color: #fff;
  border-color: var(--teal-dark);
  font-weight: 600;
}
.button--primary:hover:not(:disabled) { background: var(--navy); border-color: var(--navy); }

.button--quiet {
  background: transparent;
  color: var(--teal-dark);
  border-color: var(--line-strong);
}
.button--quiet:hover:not(:disabled) {
  background: var(--surface-sunk);
  border-color: var(--teal);
  color: var(--navy);
}

.chip {
  font-family: var(--font-body);
  font-size: 0.875rem;
  text-align: left;
  background: var(--surface);
  color: var(--teal-dark);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  transition: background-color 120ms ease-in-out, border-color 120ms ease-in-out;
}
.chip:hover { background: var(--surface-sunk); border-color: var(--teal); color: var(--navy); }

/* ------------------------------------------------------------------ fields */

.field { margin-bottom: 1.1rem; }

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 0.3rem;
}

.field input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.field input:focus-visible { border-color: var(--teal-dark); }

.field__hint {
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

/* ----------------------------------------------------------------- notices */

.notice {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border-left: 4px solid var(--teal);
  background: var(--surface-sunk);
  color: var(--ink);
  font-size: 0.9375rem;
  margin-bottom: 1rem;
}
.notice--stop { border-left-color: var(--rose); background: #fbf0f2; }
.notice--warn { border-left-color: var(--amber); background: #fdf4e9; }
.notice p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------------- boot */

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--ink-muted);
}

/* ---------------------------------------------------------------- sign in */

.signin {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
  background:
    radial-gradient(120% 90% at 50% 0%, #fff 0%, var(--page) 55%, #ebe8f1 100%);
}

.signin__card {
  width: 100%;
  max-width: 30rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--teal-dark);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
}

.signin__title { font-size: 1.75rem; margin-bottom: 0.35rem; }

.signin__lede {
  color: var(--ink-muted);
  font-size: 0.9375rem;
  margin-bottom: 1.75rem;
}

.signin__instruction { font-size: 0.9375rem; margin-bottom: 1.25rem; }

.signin__form button[type='submit'] { width: 100%; }

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(26, 20, 46, 0.72);
  display: grid;
  place-items: center;
  padding: 1.25rem;
  overflow-y: auto;
}

.modal__panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border-top: 4px solid var(--amber);
  max-width: 42rem;
  width: 100%;
  max-height: calc(100vh - 2.5rem);
  display: flex;
  flex-direction: column;
  margin: auto;
}

.modal__title {
  font-size: 1.5rem;
  padding: 1.75rem 2rem 0;
  margin-bottom: 0.75rem;
}

.modal__body {
  padding: 0 2rem;
  overflow-y: auto;
  font-size: 0.9375rem;
  /* Take the space the title and actions leave, rather than collapsing to a
     couple of lines on a short viewport. min-height:0 lets it actually shrink
     to its scroll container inside the flex column. */
  flex: 1 1 auto;
  min-height: 0;
}
.modal__body h2 {
  font-size: 1.0625rem;
  margin-top: 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.modal__body ul { margin: 0 0 1em; padding-left: 1.25rem; }
.modal__body li { margin-bottom: 0.35rem; }

.attribution {
  margin: 0 0 1em;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--amber);
  background: var(--surface-sunk);
  font-style: italic;
}

.modal__note {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--surface-sunk);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--ink-muted);
}

.modal__actions {
  padding: 1.25rem 2rem 1.75rem;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.modal__ack-text {
  flex: 1 1 12rem;
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}
.modal__panel .notice { margin: 0 2rem 1.5rem; }

/* -------------------------------------------------------------------- app */

.app {
  /* A definite height, not a minimum: the transcript is the only thing that
     scrolls, and it can only do that if its ancestors are bounded. dvh keeps
     it honest when a mobile browser's toolbars come and go. */
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.app__header {
  background: var(--navy);
  color: #fff;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.app__title { color: #fff; font-size: 1.1875rem; margin: 0; }

.app__subtitle {
  margin: 0.1rem 0 0;
  font-size: 0.8125rem;
  color: #cfc9de;
}

.app__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.app__header .button--quiet {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}
.app__header .button--quiet:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: #fff;
  color: #fff;
}
.app__header :focus-visible { outline-color: var(--amber); }

.app__main {
  width: 100%;
  max-width: 56rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}

.app__footer {
  padding: 0.9rem 1.5rem 1.1rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--ink-muted);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.app__footer p { margin: 0; }
.app__versions { margin-top: 0.25rem; font-size: 0.75rem; color: var(--ink-quiet); }

/* ------------------------------------------------------------- transcript */

.transcript {
  overflow-y: auto;
  padding-bottom: 1.5rem;
  min-height: 0;
}
.transcript:focus-visible { outline-offset: -3px; }

.welcome {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.welcome h2 { font-size: 1.25rem; }
.welcome p { color: var(--ink-muted); font-size: 0.9375rem; max-width: var(--measure); }

.welcome__prompts {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.turn { margin-bottom: 1.5rem; }

.turn__role {
  font-family: var(--font-heading);
  font-size: 0.8125rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-quiet);
  margin-bottom: 0.4rem;
}

.turn__body {
  font-size: 1rem;
  max-width: var(--measure);
}

.turn--user .turn__body {
  background: var(--surface-sunk);
  border-radius: var(--radius-lg);
  border-left: 3px solid var(--line-strong);
  padding: 0.85rem 1.1rem;
  white-space: normal;
}
.turn--user .turn__role { color: var(--teal-dark); }

.turn--navigator .turn__role { color: var(--purple); }
.turn--navigator .turn__body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.35rem;
}

.turn--error .turn__body {
  background: #fbf0f2;
  border-color: #eccdd4;
  border-left-color: var(--rose);
}

/* Markdown inside a reply */
.turn__body > :first-child { margin-top: 0; }
.turn__body > :last-child { margin-bottom: 0; }
.turn__body h2 { font-size: 1.1875rem; margin-top: 1.4rem; }
.turn__body h3 { font-size: 1.0625rem; margin-top: 1.25rem; }
.turn__body h4, .turn__body h5, .turn__body h6 { font-size: 1rem; margin-top: 1.1rem; }
.turn__body ul, .turn__body ol { margin: 0 0 1em; padding-left: 1.4rem; }
.turn__body li { margin-bottom: 0.3rem; }
.turn__body li > ul, .turn__body li > ol { margin-top: 0.3rem; margin-bottom: 0.3rem; }
.turn__body blockquote {
  margin: 0 0 1em;
  padding: 0.6rem 1rem;
  border-left: 4px solid var(--amber);
  background: var(--surface-sunk);
}
.turn__body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-sunk);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}
.turn__body pre {
  background: var(--surface-sunk);
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 0 0 1em;
}
.turn__body pre code { background: none; padding: 0; }
.turn__body hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }

.table-scroll { overflow-x: auto; margin: 0 0 1em; }
.turn__body table { border-collapse: collapse; font-size: 0.9375rem; min-width: 100%; }
.turn__body th, .turn__body td {
  border: 1px solid var(--line);
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
.turn__body th { background: var(--surface-sunk); font-weight: 600; }

/* Streaming cursor */
.cursor {
  display: inline-block;
  width: 0.5em;
  height: 1em;
  background: var(--teal);
  vertical-align: text-bottom;
  margin-left: 0.1em;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.thinking {
  color: var(--ink-muted);
  font-size: 0.9375rem;
  font-style: italic;
}

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

.composer {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  margin-bottom: 1.25rem;
}
.composer:focus-within { border-color: var(--teal-dark); }

.composer textarea {
  width: 100%;
  border: 0;
  resize: none;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
  background: transparent;
  padding: 0.35rem 0.4rem;
  max-height: 40vh;
  overflow-y: auto;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--ink-quiet); }

.composer__bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.composer__hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--ink-muted);
  flex: 1 1 18rem;
  max-width: 34rem;
}

.composer__buttons { display: flex; gap: 0.5rem; }

/* ---------------------------------------------------------------- protocol */

.doc {
  max-width: 44rem;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}
.doc h1 { font-size: 1.875rem; }
.doc h2 {
  font-size: 1.25rem;
  margin-top: 2rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}
.doc ul { padding-left: 1.3rem; }
.doc li { margin-bottom: 0.4rem; }
.doc__meta { color: var(--ink-muted); font-size: 0.9375rem; margin-bottom: 2rem; }
.doc__footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

/* ------------------------------------------------------------------ small */

@media (max-width: 40rem) {
  /* Comfortable touch targets. WCAG 2.1 AA sets no minimum, but a 33px button
     on a phone is a miss waiting to happen. */
  .button, .chip { min-height: 44px; }

  .app__header { padding: 0.75rem 1rem; }
  .app__title { font-size: 1.0625rem; }
  .app__actions { width: 100%; }
  .app__actions .button { flex: 1 1 auto; padding: 0.55rem 0.6rem; font-size: 0.875rem; }
  .app__main { padding: 1rem 0.85rem 0; }
  .signin__card { padding: 1.5rem; }
  .modal__title, .modal__body, .modal__actions { padding-left: 1.25rem; padding-right: 1.25rem; }
  .modal__panel .notice { margin-left: 1.25rem; margin-right: 1.25rem; }
  .turn--navigator .turn__body { padding: 0.9rem 1rem; }
  .composer__buttons { width: 100%; }
  .composer__buttons .button { flex: 1 1 auto; }
}

/* -------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; opacity: 0.6; }
}

/* ----------------------------------------------------- high contrast/print */

@media (forced-colors: active) {
  .button, .chip, .composer, .signin__card, .turn__body { border: 1px solid; }
}

@media print {
  .app__header, .composer, .app__footer, .welcome__prompts { display: none; }
  .transcript { overflow: visible; }
  body { background: #fff; }
}
