/* BeHonored.ai — base styles & app-shell layout.
   Vanilla CSS, design tokens via custom properties. No frameworks. */

/* ---- Design tokens ---------------------------------------------------- */
:root {
  --color-bg: #f6f8fb;
  --color-surface: #ffffff;
  --color-text: #1a2230;
  --color-text-muted: #51607a;
  --color-primary: #102a43;       /* deep navy */
  --color-primary-hover: #0a1c2e;
  --color-accent: #b8860b;        /* gold — DECORATION ONLY (fails AA as text on light bg) */
  --color-accent-text: #8a6508;   /* darkened gold — use when gold must be text on a light surface */
  --color-link: #1d4ed8;
  --color-border: #dce2ec;
  --color-focus: #2563eb;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;

  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 42, 67, 0.08);
  --container-max: 64rem;
}

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

* { margin: 0; }

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

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img,
picture,
svg { display: block; max-width: 100%; }

a { color: var(--color-link); }

h1, h2, h3 { line-height: 1.2; }

/* ---- Accessibility ---------------------------------------------------- */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -3rem;
  background: var(--color-surface);
  color: var(--color-link);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: top 0.15s ease;
  z-index: 10;
}
.skip-link:focus { top: var(--space-2); }

/* ---- Layout ----------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.site-main {
  flex: 1;
  padding-block: var(--space-12);
}

/* ---- Header / nav ----------------------------------------------------- */
.site-header {
  background: var(--color-primary);
  color: #fff;
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
  padding-block: var(--space-4);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.25rem;
}
.brand__mark { color: var(--color-accent); font-size: 1.1em; }
.brand__tld { color: var(--color-accent); }

.site-nav__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  list-style: none;
  padding: 0;
}
.site-nav a {
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  padding-block: var(--space-1);
  border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: #fff; }
.site-nav a[aria-current="page"] {
  color: #fff;
  border-bottom-color: var(--color-accent);
}

/* ---- Hero ------------------------------------------------------------- */
.hero { max-width: 42rem; }
.hero__title { font-size: clamp(1.75rem, 4vw, 2.75rem); color: var(--color-primary); }
.hero__lede {
  font-size: 1.125rem;
  color: var(--color-text-muted);
  margin-top: var(--space-4);
}
.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-8);
}

/* ---- Buttons ---------------------------------------------------------- */
.btn {
  display: inline-block;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
  border: 2px solid transparent;
  cursor: pointer;
}
.btn--primary { background: var(--color-primary); color: #fff; }
.btn--primary:hover { background: var(--color-primary-hover); }
.btn--ghost {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-border);
}
.btn--ghost:hover { border-color: var(--color-primary); }

/* ---- Panel / status --------------------------------------------------- */
.panel {
  margin-top: var(--space-12);
  padding: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.panel__title { font-size: 1rem; color: var(--color-primary); }
.panel__body { color: var(--color-text-muted); margin-top: var(--space-2); }

.status {
  margin-top: var(--space-4);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}
.status::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: var(--space-2);
  border-radius: 50%;
  background: var(--color-accent);
  vertical-align: middle;
}

/* ---- Footer ----------------------------------------------------------- */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.875rem;
}
.site-footer__inner { padding-block: var(--space-6); }
.site-footer__disclaimer { margin-top: var(--space-1); }

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

/* ---- Chat: page-scoped full-height shell ------------------------------ */
/* The chat page wants a full-height column with a pinned composer, so we
   neutralize the default .site-main padding and the .container max-width
   ONLY when this page is present — other views are untouched. */
.site-main:has([data-page="chat"]) {
  padding-block: 0;
  min-height: 0;
}
.site-main:has([data-page="chat"]) > .container {
  max-width: none;
  height: 100%;
  padding-inline: 0;
  display: flex;
}

.chat {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
  /* Fill the viewport between header and footer; flex makes the log scroll. */
  min-height: 0;
  flex: 1;
}

.chat__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-block: var(--space-4);
}
.chat__title {
  font-size: 1.125rem;
  color: var(--color-primary);
}
.chat__new {
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
}

/* ---- Chat: message log ------------------------------------------------ */
.chat__log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding-block: var(--space-2) var(--space-6);
}
.chat__log:empty { flex: 0; }

.msg { display: flex; flex-direction: column; gap: var(--space-1); max-width: 85%; }
.msg--user { align-self: flex-end; align-items: flex-end; }
.msg--assistant { align-self: flex-start; align-items: flex-start; max-width: 100%; }

.msg__role {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-text-muted);
}

.msg__bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  line-height: 1.6;
}
.msg--user .msg__bubble {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 2px;
  white-space: pre-wrap; /* preserve user's line breaks */
}
.msg--assistant .msg__bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  border-bottom-left-radius: 2px;
}

/* ---- Chat: progress / spinner ----------------------------------------- */
.msg__progress {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}
.msg__progress[hidden] { display: none; } /* author display:flex overrides UA [hidden]; restore it */
.spinner {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent-text);
  border-radius: 50%;
  animation: chat-spin 0.7s linear infinite;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

/* ---- Chat: assistant markdown body ------------------------------------ */
.msg__body > * + * { margin-top: var(--space-3); }
.msg__body h1, .msg__body h2, .msg__body h3,
.msg__body h4, .msg__body h5, .msg__body h6 {
  color: var(--color-primary);
  line-height: 1.25;
}
.msg__body h1 { font-size: 1.375rem; }
.msg__body h2 { font-size: 1.1875rem; }
.msg__body h3 { font-size: 1.0625rem; }
.msg__body ul, .msg__body ol { padding-left: var(--space-6); }
.msg__body li + li { margin-top: var(--space-1); }
.msg__body a { color: var(--color-link); }
.msg__body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875em;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.msg__body pre {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
}
.msg__body pre code { background: none; border: 0; padding: 0; font-size: 0.875rem; }
.msg__body blockquote {
  border-left: 3px solid var(--color-border);
  padding-left: var(--space-4);
  color: var(--color-text-muted);
}
.msg__body table {
  border-collapse: collapse;
  width: 100%;
  display: block;
  overflow-x: auto; /* let wide tables scroll instead of bursting the bubble */
  font-size: 0.9375rem;
}
.msg__body th,
.msg__body td {
  border: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  vertical-align: top;
}
.msg__body thead th {
  background: var(--color-bg);
  color: var(--color-primary);
  font-weight: 600;
}
.msg__body hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin-block: var(--space-4);
}
.msg__body del { color: var(--color-text-muted); }
/* GFM task lists: drop the bullet, align the checkbox with the text. */
.msg__body li:has(> input[type="checkbox"]) { list-style: none; margin-left: calc(var(--space-6) * -1); }
.msg__body input[type="checkbox"] { margin-right: var(--space-2); }

/* Blinking caret on the actively streaming message. */
.msg__body.is-streaming > *:last-child::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 2px;
  background: var(--color-accent-text);
  vertical-align: text-bottom;
  animation: chat-caret 1s step-end infinite;
}
@keyframes chat-caret { 50% { opacity: 0; } }

.msg__error {
  color: #b42318; /* AA-compliant error red on light surface */
  font-weight: 500;
}

/* ---- Chat: empty state ------------------------------------------------ */
.chat__empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding-block: var(--space-8);
}
.chat__empty[hidden] { display: none; }
.chat__empty-title {
  font-size: clamp(1.5rem, 3vw, 2rem);
  color: var(--color-primary);
}
.chat__empty-sub {
  color: var(--color-text-muted);
  max-width: 36rem;
}
.chat__chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  list-style: none;
  padding: 0;
  margin-top: var(--space-4);
}
.chip {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-primary);
  padding: var(--space-3) var(--space-4);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.chip:hover { border-color: var(--color-primary); }

/* ---- Chat: composer --------------------------------------------------- */
.chat__composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  padding: var(--space-3);
  margin-bottom: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.chat__input {
  flex: 1;
  resize: none;
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--color-text);
  line-height: 1.5;
  padding: var(--space-2);
  max-height: 200px;
  overflow-y: auto;
}
.chat__input:focus { outline: none; }
.chat__input:disabled { color: var(--color-text-muted); }

.chat__send {
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--color-primary);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.chat__send:hover { background: var(--color-primary-hover); }
.chat__send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Chat: reduced motion --------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--color-accent-text); }
  .msg__body.is-streaming > *:last-child::after { animation: none; }
}

/* ---- Motion ----------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
