:root {
  --navy: #253673;
  --navy-ink: #1b2858;
  --teal: #048480;
  --teal-ink: #036864;
  --coral: #f5875e;
  --text: #25313b;
  --muted: #5d6b76;
  --paper: #f4f6fb;
  --card: #ffffff;
  --line: #d5dbe8;
  --shadow: 0 10px 30px rgba(37, 54, 115, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--paper);
  line-height: 1.5;
  font-size: 15px;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 1.7rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--navy-ink);
}

h2 { font-size: 1.05rem; color: var(--navy-ink); }

a { color: var(--teal-ink); text-decoration-thickness: 1px; text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.brand-logo {
  display: block;
  height: 36px;
  width: auto;
  max-width: 100%;
  background: #fff;
  border-radius: 8px;
  padding: 4px 8px;
  object-fit: contain;
  object-position: left center;
}

.brand-logo-login {
  height: 48px;
  margin-bottom: 16px;
  background: transparent;
  padding: 0;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal-ink);
  margin-bottom: 6px;
}

.lede, .hint {
  color: var(--muted);
  margin-top: 6px;
}

.hint { font-size: 0.85rem; }

button, .btn {
  background: var(--teal);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spinner {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: none;
  animation: spin 0.7s linear infinite;
}

button.is-loading .icon { display: none; }

button.is-loading .spinner,
.pending .spinner { display: inline-block; }

button.is-loading:disabled { opacity: 1; }

@keyframes spin { to { transform: rotate(360deg); } }

button:hover, .btn:hover { background: var(--teal-ink); }

button:disabled { opacity: 0.55; cursor: progress; }

button.secondary, .btn.secondary { background: var(--navy); }

button.secondary:hover { background: var(--navy-ink); }

button.quiet, a.quiet {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--line);
  min-height: 36px;
  padding: 6px 12px;
}

button.quiet:hover, a.quiet:hover { background: var(--paper); color: var(--navy); }

button.quiet.light {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

button.quiet.light:hover { background: rgba(255, 255, 255, 0.08); }

label { display: block; font-weight: 600; font-size: 0.86rem; margin: 14px 0 6px; }

input[type="checkbox"] { width: auto; accent-color: var(--teal); }

input, textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

textarea { min-height: 88px; resize: vertical; }

textarea.tall { min-height: 160px; }

input[readonly] { background: var(--paper); color: var(--muted); }

.notice, .errors {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 16px;
}

.notice { background: #e7f6f5; border: 1px solid #b7e4e1; }

.errors { background: #fff4ef; border: 1px solid var(--coral); }

.errors ul { margin: 0; padding-left: 18px; }

/* Chat */

.chat-app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background:
    radial-gradient(900px 280px at 10% -10%, rgba(4, 132, 128, 0.08), transparent 60%),
    var(--paper);
}

.chat-column { width: min(760px, calc(100% - 32px)); margin: 0 auto; }

.chat-bar {
  background: var(--navy);
  color: #fff;
}

.chat-bar-inner {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 0;
}

.brand-lockup { display: flex; gap: 12px; align-items: center; min-width: 0; }

.brand-lockup h1 {
  margin: 0;
  color: #fff;
  font-size: 1.15rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand-lockup p { color: rgba(255, 255, 255, 0.78); font-size: 0.82rem; }

.library-switch { display: flex; align-items: center; gap: 8px; }

#library-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.72);
}

.segment {
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.segment button {
  background: transparent;
  color: #fff;
  min-height: 34px;
  padding: 6px 14px;
  border-radius: 999px;
}

.segment button[aria-checked="true"] {
  background: #fff;
  color: var(--navy);
}

.segment button:hover { background: rgba(255, 255, 255, 0.16); }

.segment button[aria-checked="true"]:hover { background: #fff; }

.library-note {
  color: var(--muted);
  font-size: 0.86rem;
  padding: 10px 0 0;
}

.transcript-scroll { overflow-y: auto; padding: 8px 0 20px; }

.empty { padding: 18px 0 8px; }

.empty h2 { font-size: 1.45rem; letter-spacing: -0.03em; max-width: 18ch; }

.empty p { margin-top: 10px; color: var(--muted); max-width: 46ch; }

.examples {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-top: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.examples button {
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--line);
  border-radius: 999px;
  text-align: left;
  flex: 0 0 auto;
  white-space: nowrap;
}

.examples button:hover { border-color: var(--teal); background: #fff; color: var(--teal-ink); }

.bubble {
  max-width: min(640px, 100%);
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 16px;
}

.bubble .who {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.bubble p + p { margin-top: 8px; }

.bubble.you {
  margin-left: auto;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.bubble.you .who { color: rgba(255, 255, 255, 0.72); }

.bubble.assistant {
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 6px;
}

.bubble.assistant .who { color: var(--teal-ink); }

.answer-points { margin: 0; padding-left: 1.1rem; }

.answer-points li { margin: 6px 0; }

.fine-print { color: var(--muted); font-size: 0.82rem; margin-top: 10px; }

.sources { margin-top: 12px; display: grid; gap: 8px; }

.sources-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.source {
  border-left: 3px solid var(--teal);
  background: var(--paper);
  border-radius: 0 10px 10px 0;
  padding: 8px 10px;
}

.source-title { font-weight: 600; }

.source-section, .source-meta { color: var(--muted); font-size: 0.82rem; }

.source-excerpt { margin-top: 4px; }

.status { border-radius: 12px; padding: 12px; }

.status-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.status-red_flag, .status-error {
  background: #fff4ef;
  border: 1px solid var(--coral);
}

.status-red_flag .status-label, .status-error .status-label { color: #9c3418; }

.status-out_of_scope, .status-unanswered {
  background: var(--paper);
  border: 1px solid var(--line);
}

.status-upgrade {
  background: #e7f6f5;
  border: 1px solid #b7e4e1;
}

.status-upgrade .status-label { color: var(--teal-ink); }

.member-read { margin-top: 12px; background: var(--navy); }

.member-read:hover { background: var(--navy-ink); }

.composer-bar {
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--line);
  padding: 12px 0 16px;
}

.composer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label label"
    "box send"
    "count count";
  gap: 6px 10px;
  align-items: end;
}

.composer-grid label { grid-area: label; margin: 0; }

.composer-grid textarea { grid-area: box; min-height: 46px; max-height: 140px; }

.composer-grid button { grid-area: send; }

#count { grid-area: count; color: var(--muted); font-size: 0.8rem; }

/* Admin */

body.is-admin {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  height: 100dvh;
  background: var(--paper);
  overflow: hidden;
}

.sidebar {
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.side-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.side-kicker {
  margin: 8px 0 22px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.82rem;
}

.side-nav { display: grid; gap: 4px; }

.side-nav a {
  color: rgba(255, 255, 255, 0.86);
  text-decoration: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.side-nav a:hover, .side-nav a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.side-foot { margin-top: auto; }

.who-email {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.72);
  overflow-wrap: anywhere;
  margin-bottom: 8px;
}

.main {
  padding: 28px 32px 64px;
  min-width: 0;
  max-width: 100%;
}

body.is-admin .main {
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 16px 24px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.page-head > div { flex: 1 1 auto; min-width: 0; }

.page-head form,
.page-head > .btn { flex: 0 0 auto; }

.page-head button,
.page-head .btn {
  width: auto;
  flex-shrink: 0;
  white-space: nowrap;
  justify-self: start;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel.flush { padding: 0; overflow: hidden; }

.setting-form, .row-actions, .form-actions, .filter-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.setting-form { justify-content: space-between; }

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-weight: 500;
  margin: 0;
}

.check strong { display: block; }

.check small { display: block; color: var(--muted); font-weight: 400; max-width: 62ch; }

.check.end { align-items: end; margin-top: 28px; }

.filters {
  display: grid;
  gap: 10px;
  grid-template-columns: 1.4fr repeat(4, minmax(120px, 0.7fr)) auto;
  align-items: end;
  margin-bottom: 14px;
}

.filters label { margin-top: 0; }

.table-wrap { overflow-x: auto; max-width: 100%; }

table { width: 100%; border-collapse: collapse; background: #fff; }

th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: #fbfcfe;
}

tr:last-child td { border-bottom: 0; }

tbody tr:hover td { background: #f8fafc; }

.code { font-weight: 700; color: var(--navy); white-space: nowrap; }

.q-text {
  display: -webkit-box;
  max-width: 340px;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.q-cards { display: none; }

.q-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.q-card p { margin-top: 8px; }

.q-card-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.row-actions form { display: inline; }

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  background: #eef1f7;
  color: var(--navy);
  text-transform: capitalize;
}

.pill-active { background: #e7f6f5; color: var(--teal-ink); }

.pill-retired { background: #eef1f4; color: var(--muted); }

.pill-draft { background: #e8ebf6; color: var(--navy); }

.pill-member { background: #e8ebf6; color: var(--navy); }

.pill-free { background: #fff; border: 1px solid var(--line); color: var(--text); }

.pass { color: var(--teal-ink); font-weight: 700; }

.fail { color: #9c3418; font-weight: 700; }

.stack { display: grid; gap: 4px; }

[hidden] { display: none !important; }

.form-narrow { max-width: 820px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
}

.source-slot {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px 14px;
  margin-top: 12px;
}

.source-slot legend { padding: 0 6px; font-weight: 700; color: var(--navy); }

.text-link { font-weight: 600; }

.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: stretch; }

.import-grid > .panel { margin-bottom: 0; }

.import-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100%;
}

.import-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }

.import-copy h2,
.import-copy p { margin: 0; }

.import-form {
  margin-top: auto;
  padding-top: 18px;
  display: flex;
  flex-direction: column;
}

.import-form label { margin-top: 0; }

.import-form button,
.download-demo { width: 100%; min-height: 44px; white-space: nowrap; }

.download-demo { margin-top: 4px; }

.card-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #e7f6f5;
  color: var(--teal-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.column-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  margin: 4px 0 0;
}

.column-list code {
  display: inline-block;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.75rem;
  color: var(--navy);
}

.pending-line { display: flex; align-items: center; gap: 8px; }

.phrase-list { display: grid; gap: 12px; margin-bottom: 16px; }

.section-title { margin: 8px 0 12px; }

.stats {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 0;
  margin: 0 0 16px;
}

.stats li {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.stats span { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 600; }

.stats strong { display: block; margin-top: 4px; font-size: 1.4rem; color: var(--navy-ink); }

.result-banner.is-pass { border-color: #b7e4e1; }

.result-banner.is-fail { border-color: var(--coral); background: #fff4ef; }

body.is-auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(165deg, var(--navy) 0 42%, var(--paper) 42% 100%);
}

body.is-auth .main {
  width: min(420px, calc(100% - 32px));
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
}

body.is-auth h1 { margin-bottom: 4px; }

body.is-auth button { width: 100%; margin-top: 16px; }

@media (max-width: 980px) {
  body.is-admin {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    position: relative;
    height: auto;
    z-index: 2;
    padding: 12px;
    min-width: 0;
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    overflow: visible;
  }

  .brand-logo { height: 30px; }

  .side-kicker, .side-foot p { display: none; }

  .side-brand { margin-right: auto; }

  .side-nav {
    order: 3;
    flex: 1 0 100%;
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: center;
    min-width: 0;
    overflow: hidden;
  }

  .side-nav a { justify-content: center; height: auto; min-height: 40px; padding: 8px 4px; }

  .side-foot { margin-top: 0; margin-left: auto; }

  .filters, .stats, .split, .form-grid { grid-template-columns: 1fr 1fr; }

  .table-wrap { display: none; }

  .q-cards { display: block; }

  .main { padding: 20px 16px 48px; }
}

@media (max-width: 640px) {
  .page-head { display: grid; justify-items: start; }

  .chat-bar-inner { align-items: flex-start; justify-items: start; }
}

@media (max-width: 520px) {
  .filters, .stats, .split, .form-grid { grid-template-columns: 1fr; }

  .bubble.you { margin-left: 12%; }

  .check.end { margin-top: 8px; }
}
