/*
 * Panel styles. The tokens come from the project sketch (ai-asistent.html).
 * Layout chosen in the mockup: the sites dashboard is home, a site opens in a
 * top bar with section tabs and a link back to the dashboard.
 */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --sunken: #eaeef4;
  --ink: #131925;
  --muted: #566074;
  --line: #d8dde6;
  --accent: #2343bd;
  --accent-ink: #ffffff;
  --accent-soft: #e1e7fa;
  --good: #16754d;
  --good-soft: #daf0e4;
  --warn: #8f5b0b;
  --warn-soft: #f7ebd3;
  --bad: #ae352e;
  --bad-soft: #f6deda;
  /* Lighter shades of --muted, for the quiet kinds of questions in the inbox. */
  --quiet: #7d869a;
  --quiet-soft: #eef0f4;
  --faint: #a9b1c1;
  --faint-soft: #f4f5f8;
  --shadow: 0 1px 2px rgb(19 25 37 / 0.06), 0 10px 28px rgb(19 25 37 / 0.08);
  --font-body: "Sofia Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 10px;
  /* The panel is light only, whatever the system theme. */
  color-scheme: light;
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font-body);
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.6rem;
  line-height: 1.15;
  text-wrap: balance;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

.ico {
  width: 15px;
  height: 15px;
  flex: none;
}

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

.muted {
  color: var(--muted);
}

.hint {
  font-size: 0.82rem;
  color: var(--muted);
}

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

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

.row.end {
  justify-content: flex-end;
}

/* ---------- Buttons, chips, notices ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--muted);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
}

.btn.full {
  width: 100%;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--sunken);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.chip.good {
  background: var(--good-soft);
  color: var(--good);
}

.chip.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.chip.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--sunken);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.status .ico {
  margin-top: 2px;
}

.status.good {
  background: var(--good-soft);
  color: var(--good);
}

.status.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.status.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.messages {
  display: grid;
  gap: 8px;
}

.notice {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
}

.notice.success {
  border-color: transparent;
  background: var(--good-soft);
  color: var(--good);
}

.notice.warning {
  border-color: transparent;
  background: var(--warn-soft);
  color: var(--warn);
}

.notice.error {
  border-color: transparent;
  background: var(--bad-soft);
  color: var(--bad);
}

/* ---------- Forms ---------- */

.stack-form {
  display: grid;
  gap: 14px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.label {
  padding: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.field input:not([type="checkbox"], [type="radio"]),
.field select,
.field textarea,
.input-like {
  width: 100%;
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.field input:not([type="checkbox"], [type="radio"]):focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
  outline-offset: 0;
}

.field input[disabled],
.field select[disabled],
.input-like.locked {
  background: var(--sunken);
  color: var(--muted);
}

.input-like {
  display: flex;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field.has-error input,
.field.has-error select {
  border-color: var(--bad);
}

.error {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--bad);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

/* Radio buttons shown as a segmented control. */
.choice-seg {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  width: fit-content;
}

.choice-seg label {
  position: relative;
  padding: 7px 13px;
  border-left: 1px solid var(--line);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.choice-seg label:first-child {
  border-left: 0;
}

.choice-seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-seg label:has(input:checked) {
  background: var(--accent-soft);
  color: var(--accent);
}

.choice-seg label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---------- Top bar (panel) ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px max(16px, env(safe-area-inset-left, 0px)) 10px max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.85rem;
  font-weight: 800;
}

.spacer {
  flex: 1;
}

.top-links {
  display: flex;
  gap: 4px;
}

.top-links a {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
}

.top-links a:hover,
.top-links a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
}

.home-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.crumb-sep {
  color: var(--line);
  font-weight: 700;
}

.languages {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.languages button {
  padding: 4px 9px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.languages button:first-child {
  border-left: 0;
}

.languages button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Dropdowns built on <details>: work without JavaScript. */
.dropdown {
  position: relative;
}

.dropdown > summary {
  list-style: none;
  cursor: pointer;
}

.dropdown > summary::-webkit-details-marker {
  display: none;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-weight: 800;
}

.pill-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  gap: 2px;
  min-width: 260px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.menu.right {
  left: auto;
  right: 0;
}

.menu .opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 8px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu .opt:hover {
  background: var(--sunken);
}

.menu .opt.cur {
  background: var(--accent-soft);
  font-weight: 800;
}

.menu .add {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 9px 9px 5px;
  border-top: 1px solid var(--line);
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.menu-head {
  display: grid;
  padding: 6px 9px 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.menu-head span {
  color: var(--muted);
  font-size: 0.82rem;
}

.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--sunken);
  font-size: 0.85rem;
  font-weight: 800;
}

/* Section tabs of a site. */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 max(16px, env(safe-area-inset-left, 0px)) 0 max(16px, env(safe-area-inset-right, 0px));
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 11px 10px 10px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.tab[aria-current="page"] {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

/* ---------- Page ---------- */

.page {
  display: grid;
  gap: 20px;
  max-width: 1080px;
  margin: 0 auto;
  padding-block: 26px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.page > * {
  min-width: 0;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.crumbs {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

.crumbs a {
  color: var(--muted);
}

.card {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card.narrow {
  max-width: 560px;
}

.card-title {
  font-size: 1rem;
  font-weight: 800;
}

.cols {
  display: grid;
  gap: 16px;
  align-items: start;
}

@media (min-width: 860px) {
  .cols {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cols.wide-right {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  }

  .cols.wide-left {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  }
}

.grid2 {
  display: grid;
  gap: 14px;
}

@media (min-width: 520px) {
  .grid2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.key-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.key-row .input-like {
  flex: 1;
  min-width: 180px;
}

/* ---------- Sites dashboard ---------- */

.sites-grid {
  display: grid;
  gap: 14px;
}

@media (min-width: 640px) {
  .sites-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1000px) {
  .sites-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.site-card {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.site-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.site-name {
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 800;
  text-decoration: none;
}

.site-name:hover {
  color: var(--accent);
}

.site-addr {
  color: var(--muted);
  font: 0.78rem var(--font-mono);
  overflow-wrap: anywhere;
}

.meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 14px;
  margin: 0;
  font-size: 0.9rem;
}

.meta dt {
  color: var(--muted);
}

.meta dd {
  margin: 0;
  min-width: 0;
}

.site-card-foot {
  display: flex;
  justify-content: flex-end;
}

.add-card {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  min-height: 160px;
  padding: 16px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  color: var(--accent);
  text-align: center;
  text-decoration: none;
}

.add-card:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.add-card span {
  color: var(--muted);
  font-size: 0.85rem;
}

.empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 40px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.empty .glyph {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  color: var(--accent);
}

.empty p {
  max-width: 40ch;
  color: var(--muted);
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 10px 8px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.table thead th {
  border-top: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.copy-row {
  display: flex;
  gap: 6px;
  min-width: 260px;
}

.copy-row input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--sunken);
  color: var(--muted);
  font: 0.75rem var(--font-mono);
}

/* ---------- Login and other entrance pages ---------- */

.auth-page {
  display: grid;
  justify-items: center;
  gap: 18px;
  min-height: 100vh;
  align-content: start;
  padding-block: 40px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.auth-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 420px;
}

.auth-card {
  display: grid;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.auth-title {
  font-size: 1.5rem;
}

.auth-foot {
  font-size: 0.9rem;
}

.rule {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
}

/* allauth pages shown inside the panel (e.g. password change). */
.page-manage .auth-title {
  font-size: 1.4rem;
}

.page-manage .stack-form {
  max-width: 480px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

@media (max-width: 560px) {
  .top-links {
    order: 10;
    width: 100%;
  }

  .pill-btn {
    max-width: 180px;
  }
}

/* ---------- Wide pages (knowledge, tests) ---------- */

.page.page-wide {
  max-width: 1320px;
}

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

.btn.danger {
  color: var(--bad);
}

.btn.danger-fill {
  border-color: var(--bad);
  background: var(--bad);
  color: #ffffff;
}

.btn.current {
  border-color: var(--accent);
  color: var(--accent);
}

.form-actions.end {
  justify-content: flex-end;
}

.row.wrap {
  flex-wrap: wrap;
}

.row.between {
  justify-content: space-between;
}

.nowrap {
  white-space: nowrap;
}

h2.title {
  font-size: 1.35rem;
}

/* ---------- Knowledge ---------- */

.kb-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
}

.meter {
  display: grid;
  gap: 4px;
  flex: 1;
  min-width: 240px;
}

.meter .bar {
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--sunken);
}

.meter .bar i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--good);
}

.meter.over .bar i {
  background: var(--warn);
}

.meter span {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.kb-grid {
  display: grid;
  gap: 16px;
  align-items: start;
}

@media (min-width: 900px) {
  .kb-grid {
    grid-template-columns: 280px minmax(0, 1fr);
  }
}

.kb-main {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.tree-panel {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

@media (min-width: 900px) {
  .tree-panel {
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 24px);
    overflow: auto;
  }
}

.tree-filter {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.tree,
.tree ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tree ul {
  margin-left: 8px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.node {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 0.9rem;
  text-decoration: none;
}

.node:hover {
  background: var(--sunken);
}

.node.cat {
  font-weight: 700;
}

.node.cat::before {
  content: "▾";
  width: 9px;
  color: var(--muted);
  font-size: 0.7rem;
}

.node .n {
  margin-left: auto;
  color: var(--muted);
  font: 0.72rem var(--font-mono);
}

.node.entry::before {
  content: "";
  width: 6px;
  height: 6px;
  margin: 0 1px;
  border-radius: 2px;
  background: var(--line);
  flex: none;
}

.node.cur {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.node.entry.cur::before {
  background: var(--accent);
}

.node.off {
  color: var(--muted);
  text-decoration: line-through;
}

.tree li[hidden] {
  display: none;
}

.pairbox {
  display: grid;
  gap: 14px;
  align-items: start;
}

@media (min-width: 1100px) {
  .pairbox {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.half {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
  padding: 14px;
  border-radius: var(--radius);
}

.half.info {
  background: var(--surface);
  border: 1px solid var(--line);
}

.half.ins {
  background: #f7f9ff;
  border: 1px solid #c9d4f6;
}

.half-title {
  font-size: 0.95rem;
  font-weight: 800;
}

.half.ins .half-title {
  color: var(--accent);
}

.half.ins textarea {
  border-color: #b9c6f2;
}

.inherit {
  display: grid;
  gap: 4px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--sunken);
  font-size: 0.85rem;
}

.inherit b {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.inherit span::before {
  content: "↳ ";
  color: var(--muted);
}

.variant {
  display: grid;
  gap: 6px;
}

.variants > summary {
  width: fit-content;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.variants[open] {
  display: grid;
  gap: 8px;
  padding: 8px 10px;
  border: 1px dashed #c9d4f6;
  border-radius: 8px;
}

.channels {
  display: grid;
  gap: 14px;
}

@media (min-width: 760px) {
  .channels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.channel-box {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

/* ---------- Tests ---------- */

.tests-grid {
  display: grid;
  gap: 18px;
  align-items: start;
}

@media (min-width: 980px) {
  .tests-grid {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
}

.conversation {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.side-panel {
  display: grid;
  gap: 14px;
}

/* The conversation is one card as tall as the screen under what is above it (--chat-top comes
   from the panel's script). The chat scrolls inside it and the field stays at its bottom, so
   sending never moves the page. */
.chat-card {
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  height: max(440px, calc(100vh - var(--chat-top, 180px) - 18px));
  height: max(440px, calc(100dvh - var(--chat-top, 180px) - 18px));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.conv-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
}

.conv-head h1 {
  font-size: 1.1rem;
}

.chat {
  position: relative; /* the script measures the messages from here */
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 12px;
  overflow-wrap: anywhere;
}

.msg.user {
  justify-self: end;
  border-bottom-right-radius: 4px;
  background: var(--accent);
  color: var(--accent-ink);
}

.msg.bot {
  justify-self: start;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  background: var(--bg);
}

.msg.bot.none {
  border-color: #e7cf9f;
  background: #fffaf0;
}

.chat.email .msg {
  max-width: 100%;
  width: 100%;
  border-radius: 10px;
}

.chat.email .msg.user {
  background: var(--accent-soft);
  color: var(--ink);
}

.mail-head {
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid currentColor;
  font-size: 0.8rem;
  font-weight: 800;
  opacity: 0.8;
}

.trace {
  display: grid;
  gap: 3px;
  justify-self: start;
  max-width: 92%;
  padding: 4px 10px;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
}

.trace b {
  color: var(--ink);
}

.trace a {
  font-weight: 700;
  text-decoration: none;
}

.trace .num {
  font: 0.74rem var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* The field, as in Claude Code: the text on top, the keys and the Send arrow under it. The field
   grows with the text up to a few lines. */
.composer {
  display: grid;
  gap: 2px;
  margin: 0 12px 12px;
  padding: 8px 8px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(19 25 37 / 0.05);
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer textarea {
  width: 100%;
  min-height: 1.6em;
  max-height: 9.5em;
  padding: 3px 0;
  border: 0;
  outline: 0; /* the box around it shows the focus */
  background: transparent;
  resize: none;
  field-sizing: content;
}

.composer.email textarea {
  min-height: 6em;
  max-height: 16em;
}

.composer textarea::placeholder {
  color: var(--faint);
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.composer-bar .hint {
  font-size: 0.78rem;
}

.send {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

.send .ico {
  width: 17px;
  height: 17px;
}

.send:disabled {
  background: var(--sunken);
  color: var(--faint);
  cursor: default;
}

/* Shown at once after sending, until the chat comes back with the answer. */
.msg.sent {
  white-space: pre-line;
}

.msg.failed {
  opacity: 0.55;
}

/* While the answer comes: a turning star, the word and the seconds, as in Claude Code. */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
  padding: 4px 2px;
  color: var(--accent);
  font-weight: 700;
}

.typing .ico {
  width: 17px;
  height: 17px;
  animation: turn 2.4s linear infinite, breathe 1.2s ease-in-out infinite;
}

.typing-time {
  color: var(--muted);
  font: 600 0.78rem var(--font-mono);
}

@keyframes turn {
  to {
    rotate: 360deg;
  }
}

@keyframes breathe {
  50% {
    scale: 0.72;
  }
}

@media (prefers-reduced-motion: reduce) {
  .typing .ico {
    animation: none;
  }
}

.chat-notice {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.88rem;
}

.history-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.history-row:first-of-type {
  border-top: 0;
}

.log {
  margin: 0;
  max-height: 520px;
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: var(--sunken);
  font: 0.78rem/1.5 var(--font-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.seg-links {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.seg-links a {
  padding: 5px 11px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
}

.seg-links a:first-child {
  border-left: 0;
}

.seg-links a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- No answer: the questions grouped by where the answer goes ---------- */

.cases-card {
  gap: 12px;
}

.cgroup {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.cgroup-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.cgroup-add {
  margin-left: auto;
}

.cgroup-count,
.cgroup-none {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.place {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 700;
}

.place-part {
  padding: 1px 8px;
  border: 1.5px solid transparent;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  overflow-wrap: anywhere;
}

/* Not in the knowledge yet: "Add an entry here" creates it. */
.place-part.new {
  border-color: var(--accent);
  border-style: dashed;
  background: var(--surface);
}

.place-part.new::before {
  content: "+ ";
}

.place-sep {
  color: var(--faint);
  font-weight: 800;
}

.new-tag {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--good-soft);
  color: var(--good);
  font-size: 0.72rem;
  font-weight: 800;
}

.cgroup-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 12px;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
}

.cgroup-head + .cgroup-row {
  border-top: 0;
}

.cgroup-q {
  overflow-wrap: anywhere;
}

.cgroup-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 600px) {
  .cgroup-add,
  .cgroup-add .btn {
    width: 100%;
  }

  .cgroup-row {
    grid-template-columns: minmax(0, 1fr);
    justify-items: start;
  }
}

/* A new entry made from "Add an entry here": the questions it answers. */
.answering {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--warn-soft);
}

.answering ul {
  margin: 0;
  padding-left: 1.2em;
  overflow-wrap: anywhere;
}

/* ---------- Overview ---------- */

.setup-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 20px;
}

.setup-title {
  display: grid;
  gap: 2px;
}

.progress {
  display: flex;
  gap: 4px;
  width: 220px;
  max-width: 100%;
}

.progress i {
  flex: 1;
  height: 7px;
  border-radius: 4px;
  background: var(--sunken);
}

.progress i.done {
  background: var(--good);
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 860px) {
  .steps {
    columns: 2;
    column-gap: 28px;
  }
}

.step {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  break-inside: avoid;
}

.step > div {
  display: grid;
  min-width: 0;
}

.step b {
  font-size: 0.92rem;
}

.step > div > span {
  color: var(--muted);
  font-size: 0.82rem;
}

.step > a:not(.btn) {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.step-mark {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1.5px dashed var(--muted);
  border-radius: 50%;
}

.step-mark .ico {
  width: 12px;
  height: 12px;
}

.step.done .step-mark {
  border: 0;
  background: var(--good);
  color: var(--accent-ink);
}

.step.next .step-mark {
  border: 2px solid var(--accent);
}

.step.next b {
  color: var(--accent);
}

.step.later b {
  color: var(--muted);
  font-weight: 600;
}

.setup-done {
  padding: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.setup-done > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--good);
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}

.setup-done > summary::-webkit-details-marker {
  display: none;
}

.setup-done > summary span {
  color: var(--accent);
  font-size: 0.85rem;
}

.setup-done[open] > summary {
  margin-bottom: 8px;
}

.activity {
  display: grid;
  gap: 12px;
}

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

@media (min-width: 860px) {
  .tiles {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.tile {
  display: grid;
  gap: 2px;
  align-content: start;
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tile small {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.tile b {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.tile span {
  color: var(--muted);
  font-size: 0.82rem;
}

.tile.warn b {
  color: var(--warn);
}

.table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Columns a phone can do without. */
@media (max-width: 600px) {
  .table .wide-only {
    display: none;
  }
}

.case-list {
  display: grid;
}

.case-row {
  display: grid;
  gap: 2px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.case-row:first-child {
  padding-top: 0;
  border-top: 0;
}

/* ---------- Inbox from Messenger (in Tests) ---------- */

/* Every kind of question has a colour: --c marks it, --cs is its soft background. */
.kind-kb {
  --c: var(--good);
  --cs: var(--good-soft);
}

.kind-data {
  --c: var(--accent);
  --cs: var(--accent-soft);
}

.kind-action {
  --c: var(--warn);
  --cs: var(--warn-soft);
}

.kind-human {
  --c: var(--bad);
  --cs: var(--bad-soft);
}

.kind-followup {
  --c: var(--muted);
  --cs: var(--sunken);
}

.kind-none {
  --c: var(--quiet);
  --cs: var(--quiet-soft);
  --c-text: var(--muted);
}

.kind-offtopic {
  --c: var(--faint);
  --cs: var(--faint-soft);
  --c-text: var(--muted);
}

.tests-switch {
  width: fit-content;
}

.tests-switch .count {
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--sunken);
  font: 600 0.74rem var(--font-mono);
}

.tests-switch a[aria-current="page"] .count {
  background: var(--surface);
}

.kind-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.kind-card {
  position: relative;
  display: grid;
  gap: 2px;
  align-content: start;
  padding: 12px 14px 15px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
}

.kind-card::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 4px;
  background: var(--c);
}

.kind-card:hover,
.kind-card[aria-current="true"] {
  border-color: var(--c);
}

.kind-card[aria-current="true"] {
  background: var(--cs);
}

.kind-card b {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kind-card span {
  font-size: 0.88rem;
  font-weight: 700;
}

.kind-card small {
  color: var(--muted);
  font-size: 0.78rem;
}

.kind-group {
  display: grid;
  gap: 2px;
}

.kind-group h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.kind-group h2 i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--c);
}

.kind-group > .hint {
  margin-bottom: 6px;
}

.topic-row {
  display: grid;
  grid-template-columns: minmax(160px, 300px) minmax(0, 1fr) 48px;
  gap: 12px;
  align-items: center;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}

.topic-row:hover,
.topic-row[aria-expanded="true"] {
  background: var(--surface);
}

.topic-row[aria-expanded="true"] {
  box-shadow: inset 0 0 0 1px var(--line);
}

.topic-name {
  font-size: 0.93rem;
  font-weight: 600;
}

.topic-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--sunken);
}

.topic-bar i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--c);
}

.topic-count {
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  .topic-row {
    grid-template-columns: minmax(0, 1fr) 48px;
  }

  .topic-bar {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

.topic-questions {
  display: grid;
  gap: 8px;
  justify-items: start;
  padding: 6px 0 16px 10px;
}

.inbox-q {
  position: relative;
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.inbox-q::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: -1px;
  width: 3px;
  border-radius: 3px;
  background: var(--c);
}

.inbox-q-summary {
  font-weight: 700;
}

.inbox-q-text {
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.inbox-q-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.inbox-q-meta a {
  margin-left: auto;
  font-weight: 700;
}

.trip {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}

.kind-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--cs);
  color: var(--c-text, var(--c));
  font-size: 0.76rem;
  font-weight: 700;
}

.kind-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c);
}

/* The Messenger chat in the side column of Tests. Its filter lists long topics: the columns
   must not grow to fit them. */
.tests-grid.with-inbox {
  grid-template-columns: minmax(0, 1fr);
}

.tests-grid.with-inbox > .side-panel,
.side-swap > * {
  min-width: 0;
}

@media (min-width: 980px) {
  .tests-grid.with-inbox {
    grid-template-columns: minmax(0, 1fr) 380px;
  }
}

.side-swap {
  display: grid;
  gap: 14px;
}

.side-swap.swapped > :first-child {
  order: 1;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn.icon-btn {
  min-width: 36px;
  padding-inline: 8px;
}

.inbox-window {
  gap: 10px;
  min-width: 0;
}

.inbox-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.inbox-pos {
  min-width: 64px;
  color: var(--muted);
  font: 600 0.82rem var(--font-mono);
  text-align: center;
}

.inbox-filter {
  flex: 1 1 160px;
  min-width: 0;
}

.inbox-filter select {
  min-width: 0;
}

.inbox-who {
  display: grid;
}

.inbox-who .hint {
  font-size: 0.8rem;
}

.inbox-chat {
  display: grid;
  gap: 8px;
  align-content: start;
  max-height: 460px;
  overflow-y: auto;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.inbox-turn {
  display: grid;
  gap: 4px;
  justify-items: end;
}

.imsg {
  position: relative;
  max-width: 94%;
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.imsg.from-customer {
  padding-right: 34px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--surface));
  border-bottom-right-radius: 4px;
}

.imsg.from-company {
  justify-self: start;
  border: 1px dashed var(--line);
  border-bottom-left-radius: 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

.imsg[data-fold] {
  cursor: pointer;
}

.imsg[data-fold]:not(.open) {
  max-height: 7.6em;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, #000 60%, transparent);
}

.imsg-who {
  display: block;
  margin-bottom: 2px;
  font: 600 0.66rem var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.imsg-copy {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.imsg-copy:hover,
.imsg-copy.done {
  background: var(--accent-soft);
  color: var(--accent);
}

.turn-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.btn.to-test {
  min-height: 30px;
  padding: 3px 10px;
  border-color: var(--accent);
  color: var(--accent);
  font-size: 0.82rem;
}

.btn.to-test:hover {
  background: var(--accent);
  color: var(--accent-ink);
}

.inbox-test {
  display: grid;
  gap: 6px;
  justify-items: start;
}

/* The field lights up when "Into the test" fills it. */
.composer:has(textarea.filled) {
  animation: filled 0.9s ease-out;
}

@keyframes filled {
  from {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
  }
}

@media (prefers-reduced-motion: reduce) {
  .composer:has(textarea.filled) {
    animation: none;
  }
}

/* ---------- Photos in a conversation ---------- */

.msg-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.msg-photos img {
  display: block;
  width: auto;
  max-width: 180px;
  height: auto;
  max-height: 180px;
  border-radius: 8px;
  background: var(--surface);
}

.composer-bar .hint {
  flex: 1;
}

.photo-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.photo-list:empty {
  display: none;
}

.photo-chip img {
  display: block;
  width: 44px;
  height: 44px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.btn.small {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.sent-photos {
  display: block;
  margin-bottom: 2px;
  font-size: 0.8rem;
  opacity: 0.85;
}

/* ---------- Overview: below the numbers ---------- */

.activity-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.activity-foot .warn {
  color: var(--warn);
  font-weight: 700;
}

.activity-foot .bad {
  color: var(--bad);
  font-weight: 700;
}

/* ---------- Conversations ---------- */

.back {
  margin: 0 0 10px;
}

.back a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  text-decoration: none;
}

.pager {
  margin-top: 12px;
  align-items: center;
}

.side-panel .case-row {
  display: grid;
  gap: 2px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.side-panel .case-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

/* ---------- Channels ---------- */

.copy-row input.mono {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.field input[type="color"] {
  width: 64px;
  height: 38px;
  padding: 3px;
  cursor: pointer;
}

/* ---------- A colleague in the chat ---------- */

/* A colleague's message: on the business's side of the chat, in green, with the name on top. */
.msg.team {
  justify-self: start;
  border: 1px solid #b8dcc8;
  border-bottom-left-radius: 4px;
  background: var(--good-soft);
}

.msg-who {
  display: block;
  margin-bottom: 2px;
  color: var(--good);
  font-size: 0.78rem;
  font-weight: 800;
}

.chat-foot {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.colleague-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  margin: 0 12px;
  font-size: 0.85rem;
}

.colleague-bar.on {
  padding: 6px 6px 6px 12px;
  border-radius: 9px;
  background: var(--good-soft);
  color: var(--good);
  font-weight: 700;
}

.colleague-bar .hint {
  font-size: 0.8rem;
}

.tests-grid.alone {
  grid-template-columns: minmax(0, 1fr);
}

/* The chat window inside Telegram: the chat card alone, close to the edges. */
.window-page {
  padding-top: 10px;
  padding-bottom: 0;
}

.window-start {
  padding-top: 40px;
  text-align: center;
}
