/* exyt knowledge base — components and layout.
 * Every colour comes from tokens.css. No raw hex in this file. */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-body);
  font-kerning: normal;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-heading);
  font-kerning: normal;
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); }

p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--text-link);
  text-decoration: none;
}
a:hover { color: var(--text-link-hover); text-decoration: underline; }

/* Focus: navy outline for contrast, cyan halo for brand. Cyan alone on a light
 * surface is far too faint to serve as a visible focus indicator. */
:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--cyan-30);
  border-radius: var(--radius-sm);
}
.sidebar :focus-visible,
.surface-inverse :focus-visible {
  outline-color: var(--cyan);
  box-shadow: 0 0 0 5px var(--white-15);
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  object-fit: contain;
}
.icon-sm { width: 16px; height: 16px; }

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

/* ============================================================ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem 1.125rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--navy);
  color: var(--ink-inverse);
  font: inherit;
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition);
}
.btn:hover { background: var(--grey-800); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-raised);
  border-color: var(--border-strong);
  color: var(--ink);
}
.btn-secondary:hover { background: var(--surface-hover); }

.btn-ghost {
  background: transparent;
  color: var(--ink-secondary);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--ink); }

.btn-danger {
  background: transparent;
  border-color: var(--error-border);
  color: var(--error);
}
.btn-danger:hover { background: var(--error-bg); }

/* Cyan as a FILL with navy text on it — 10.6:1. This is the one place cyan
 * carries an action, and the text on it is navy, never white. */
.btn-accent {
  background: var(--cyan);
  color: var(--navy);
  font-weight: var(--weight-semibold);
}
.btn-accent:hover { filter: brightness(0.94); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: var(--text-sm); }
.btn-block { width: 100%; }

/* ============================================================== forms */

.field { margin-bottom: var(--space-4); }

.label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-secondary);
  letter-spacing: var(--tracking-body);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--ink);
  font: inherit;
  transition: border-color var(--transition);
}
.input:hover,
.select:hover,
.textarea:hover { border-color: var(--grey-400); }
.textarea { min-height: 108px; resize: vertical; line-height: var(--leading-relaxed); }
.select { cursor: pointer; }

.hint {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--error-border);
  border-radius: var(--radius);
  background: var(--error-bg);
  color: var(--error);
  font-size: var(--text-sm);
}
.alert-success {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--success);
}
.alert-warning {
  border-color: var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning);
}
.alert[hidden] { display: none; }

/* ============================================================== shell */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface-inverse);
  color: var(--ink-inverse);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4) var(--space-4);
}

/* The brand logo is navy artwork, so it disappears on a navy sidebar.
 * Rather than ship a second asset, knock it to pure white. */
.logo { height: 24px; width: auto; }
.logo-inverse { filter: brightness(0) invert(1); }

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-3);
}

.sidebar-label {
  padding: var(--space-4) var(--space-2) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: lowercase;
  color: var(--ink-on-navy-muted);
}

.session {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--white-75);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.session:hover { background: var(--white-15); color: var(--ink-inverse); }

/* Active thread marked with a cyan rule — cyan ON navy, which is exactly the
 * pairing the brand rule permits. */
.session.is-active {
  background: var(--white-15);
  color: var(--ink-inverse);
  box-shadow: inset 3px 0 0 var(--cyan);
}
.session-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session .icon { opacity: 0.7; }

.sidebar-foot {
  padding: var(--space-3);
  border-top: 1px solid var(--border-inverse);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
}
.user-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-role {
  font-size: var(--text-xs);
  color: var(--ink-on-navy-muted);
  letter-spacing: var(--tracking-caps);
  text-transform: lowercase;
}
.user-chip .spacer { flex: 1; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); }
.sidebar .icon-btn:hover { background: var(--white-15); }

/* =============================================================== main */

.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
}
.topbar h1 { font-size: var(--text-md); }
.topbar .spacer { flex: 1; }

.nav-link {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.nav-link:hover { background: var(--surface-hover); color: var(--ink); text-decoration: none; }
.nav-link.is-active { background: var(--navy); color: var(--ink-inverse); }

.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

.container {
  max-width: var(--content-max);
  margin: 0 auto;
}
.container-wide { max-width: 980px; margin: 0 auto; }

/* =========================================================== messages */

.messages { display: flex; flex-direction: column; gap: var(--space-5); }

.msg { display: flex; flex-direction: column; gap: var(--space-2); }
.msg-user { align-items: flex-end; }

.bubble {
  max-width: 88%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  line-height: var(--leading-relaxed);
}
.msg-user .bubble {
  background: var(--surface-inverse);
  color: var(--ink-inverse);
  border-bottom-right-radius: var(--radius-sm);
}
.msg-assistant .bubble {
  max-width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 var(--space-3); padding-left: 1.25rem; }
.bubble li { margin-bottom: var(--space-1); }
.bubble code {
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.bubble pre {
  overflow-x: auto;
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--surface-sunken);
}
.bubble pre code { padding: 0; background: none; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

/* Mode badges. The assistant's answer mode is the single most useful thing to
 * surface — it tells the reader whether they're looking at approved doctrine,
 * an inference, or a decline, without having to guess from tone. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.125rem 0.5rem;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: lowercase;
}
.badge-a { background: var(--cyan); color: var(--navy); }
.badge-b { background: var(--grey-100); color: var(--grey-700); border-color: var(--border); }
.badge-c { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.badge-d { background: var(--error-bg); color: var(--error); border-color: var(--error-border); }
.badge-neutral { background: var(--grey-100); color: var(--grey-700); border-color: var(--border); }
.badge-approved { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge-draft { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }

.cites { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* D8: sources are not stated by default, so this is the way in. Styled as a
 * quiet inline control rather than a button — asking where an answer came from
 * should feel like a footnote, not an action. */
.cite-ask {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-link);
  font: inherit;
  font-size: var(--text-xs);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.cite-ask:hover { color: var(--text-link-hover); }
.cite-ask:disabled { color: var(--ink-muted); cursor: default; text-decoration: none; }

.cite-note { font-size: var(--text-xs); color: var(--ink-muted); }
.cite {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  font-size: var(--text-xs);
  color: var(--ink-secondary);
}

.typing { display: inline-flex; gap: 4px; padding: var(--space-2) 0; }
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--grey-400);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ======================================================= empty state */

/* build.md is right that skipping this costs half the team on first contact:
 * a blank box gives no signal about what's actually in the knowledge base. */
.empty { padding: var(--space-8) 0; text-align: center; }
.empty-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px; height: 56px;
  margin-bottom: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--surface-inverse);
}
.empty h2 { margin-bottom: var(--space-3); }
.empty p { max-width: 42ch; margin-inline: auto; color: var(--ink-secondary); }

/* Fixed 2-up rather than auto-fit: with four examples, auto-fit lands on
 * three-plus-an-orphan at this container width, which reads as a mistake. */
.examples {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-6);
  text-align: left;
}
@media (max-width: 620px) {
  .examples { grid-template-columns: 1fr; }
}

/* Stand-in when there is nothing approved to suggest. Spans both columns so
 * it centres under the intro rather than sitting in the left cell. */
.examples-empty {
  grid-column: 1 / -1;
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  text-align: center;
}
.example {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition),
    transform var(--transition);
}
.example:hover {
  border-color: var(--grey-400);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

/* ========================================================== composer */

.composer-wrap {
  padding: var(--space-4) var(--space-6) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.composer:focus-within {
  border-color: var(--navy);
  box-shadow: 0 0 0 4px var(--cyan-30);
}
.composer textarea {
  flex: 1;
  max-height: 180px;
  padding: var(--space-2) 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  line-height: var(--leading-relaxed);
  resize: none;
}
.composer textarea:focus { outline: none; box-shadow: none; }
.composer textarea::placeholder { color: var(--ink-muted); }

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--navy);
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
}
.send-btn:hover { background: var(--grey-800); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.composer-note {
  max-width: var(--content-max);
  margin: var(--space-2) auto 0;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  text-align: center;
}

/* ============================================================= cards */

.card {
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--space-4); }
.card-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.card-head .spacer { flex: 1; }
.card-title { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.card-sub { font-size: var(--text-sm); color: var(--ink-muted); }

.section-head { margin-bottom: var(--space-4); }
.section-head p { margin-top: var(--space-2); color: var(--ink-secondary); }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}

.stat { display: flex; flex-direction: column; gap: var(--space-1); }
.stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-heading);
}
.stat-label {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: lowercase;
  color: var(--ink-muted);
}

/* ============================================================ tables */

.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-strong);
  color: var(--ink-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: lowercase;
  text-align: left;
}
.table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: var(--space-2); justify-content: flex-end; }
.table-wrap { overflow-x: auto; }

/* ============================================================ review */

.review-item + .review-item { margin-top: var(--space-4); }
.review-source {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--ink-muted);
}
.review-pills { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.review-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.review-actions .spacer { flex: 1; }

/* ============================================================== auth */

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--space-5);
  background: var(--surface);
}
.auth-card {
  width: 100%;
  max-width: 396px;
  padding: var(--space-7);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
}
.auth-head { margin-bottom: var(--space-6); text-align: center; }
.auth-head .logo { height: 30px; margin-bottom: var(--space-5); }
.auth-head h1 { font-size: var(--text-xl); margin-bottom: var(--space-2); }
.auth-head p { color: var(--ink-muted); font-size: var(--text-sm); }
.auth-foot {
  margin-top: var(--space-5);
  font-size: var(--text-sm);
  color: var(--ink-muted);
  text-align: center;
}

/* ======================================================== responsive */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--transition);
  }
  .sidebar.is-open { transform: none; }
  .scroll-area, .composer-wrap { padding-inline: var(--space-4); }
  .bubble { max-width: 100%; }
}
@media (min-width: 861px) {
  .sidebar-toggle { display: none; }
}
