/* Captain Builders — design system lifted from captain.works (verified
   2026-08-17): near-black ground with magenta/violet radial glows, Manrope,
   pill nav chips (#1F1F1F, radius 90px), CTA gradient #E60165 -> #8000DB
   (radius 10px), solid-white secondary button, yellow duck as the brand mark.
   Deliberately single-theme (dark) — the brand commits to it, so no
   prefers-color-scheme forks; every color is painted explicitly. */

:root {
  --background: #0a0a0b;
  --foreground: #ffffff;
  --card: #151517;
  --muted: #1f1f1f;
  --muted-foreground: #9a9aa3;
  --border: #2a2a2e;
  --primary: #ffffff;          /* site's secondary = solid white on black */
  --primary-foreground: #0a0a0b;
  --accent: #e60165;           /* magenta end of the CTA gradient */
  --accent-2: #8000db;         /* violet end of the CTA gradient */
  --duck: #ffc800;             /* logo yellow — brand mark accents only */
  --ring: #e60165;
  --danger: #ff4d6d;
  --success: #35d073;
  --radius: 0.625rem;          /* 10px, as on captain.works buttons */
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* our display:flex rules must not defeat the hidden attribute */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Manrope, -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--foreground);
  /* The captain.works hero glow, toned down for an app that is read daily. */
  background:
    radial-gradient(55% 38% at 75% -5%, rgba(128, 0, 219, 0.20), transparent 65%),
    radial-gradient(45% 30% at 15% 105%, rgba(230, 1, 101, 0.10), transparent 60%),
    var(--background);
  background-attachment: fixed;
}
button { font: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted-foreground); }
/* Person links in admin tables: open the unified profile in a new tab. */
.user-link { color: inherit; text-decoration: none; border-bottom: 1px dashed var(--muted-foreground); }
/* No underline of any kind for links inside tables and in card heads (next to an avatar). */
.table a:not(.btn), .table a.user-link, .kb-card-head a:not(.btn), .kb-card-head a.user-link { text-decoration: none; border-bottom: 0; }
.user-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- app shell: sidebar + content ---------- */

#app { display: flex; height: 100dvh; }

.sidebar {
  width: 15.5rem; flex: none;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: rgba(10, 10, 11, 0.6);
  padding: 1.1rem 0.8rem;
  gap: 0.15rem;
}
.brand { display: flex; align-items: center; padding: 0.2rem 0.5rem 1.1rem; }
.brand img.brand-logo { height: 2.1rem; width: auto; display: block; }
.brand .brand-word { font-weight: 800; letter-spacing: -0.02em; margin-left: 0.5rem; }

.nav-items { display: flex; flex-direction: column; gap: 0.3rem; }

/* Nav = the site's pill chips: #1F1F1F, fully rounded. Nav items and cards
   are real <a> links (2026-08-20) — keep them looking like app controls. */
a.nav-item, a.card { text-decoration: none; }
/* Nav pill chips */
.nav-item {
  display: flex; align-items: center; gap: 0.6rem;
  border: 1px solid transparent; background: transparent;
  color: var(--muted-foreground);
  padding: 0.5rem 0.9rem; min-height: 2.5rem; border-radius: 999px;
  cursor: pointer; text-align: left; font-size: 0.92rem; width: 100%;
  font-weight: 600;
}
.nav-item:hover { background: var(--muted); color: var(--foreground); }
.nav-item.active { background: var(--muted); color: var(--foreground); border-color: var(--border); }
.nav-item:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.sidebar .spacer { flex: 1; }

.sidebar-user {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.6rem 0.6rem 0.1rem; border-top: 1px solid var(--border); margin-top: 0.5rem;
  cursor: pointer; /* clicking the avatar/name opens the profile */
}
.sidebar-user:hover .u-name { color: var(--accent); }
.sidebar-user .u-name {
  font-size: 0.85rem; font-weight: 700; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.avatar {
  position: relative;
  width: 2rem; height: 2rem; border-radius: 50%; flex: none;
  background: var(--muted); display: inline-flex; align-items: center;
  justify-content: center; font-size: 0.8rem; font-weight: 800;
  color: var(--muted-foreground); overflow: hidden;
  border: 1px solid var(--border);
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--muted); }

.content { flex: 1; overflow-y: auto; min-width: 0; }
.content-inner { max-width: 64rem; margin: 0 auto; padding: 2rem 1.5rem 3.5rem; }

.page-title {
  margin: 0 0 0.4rem; font-size: 1.7rem; letter-spacing: -0.03em;
  font-weight: 800; text-wrap: balance;
}
.page-desc { margin: 0 0 1.6rem; color: var(--muted-foreground); max-width: 44rem; }

/* ---------- sections and card grid ---------- */

.section { margin-bottom: 2.4rem; }
.section-title { margin: 0 0 0.3rem; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.section-desc { margin: 0 0 1rem; font-size: 0.88rem; color: var(--muted-foreground); max-width: 44rem; }

.card-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 1rem; overflow: hidden;
  display: flex; flex-direction: column; text-align: left;
  padding: 0; cursor: default; color: var(--foreground);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover {
  border-color: rgba(230, 1, 101, 0.55);
  box-shadow: 0 8px 32px rgba(230, 1, 101, 0.12);
  transform: translateY(-2px);
}
.card:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.card-img {
  aspect-ratio: 16 / 9; width: 100%; object-fit: cover; display: block;
  background: var(--muted); border-bottom: 1px solid var(--border);
}
.card-img-placeholder {
  aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(70% 100% at 50% 0%, rgba(128, 0, 219, 0.22), transparent 70%),
    #101012;
  border-bottom: 1px solid var(--border);
}
.card-img-placeholder img { width: 3.2rem; opacity: 0.8; }
/* Batch label (B1/B2…) pinned over the card image, top-right. */
.card { position: relative; }
.card-batch {
  position: absolute; top: 0.55rem; right: 0.55rem; z-index: 1;
  padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.02em;
  color: #fff; background: rgba(10, 10, 11, 0.72);
  border: 1px solid rgba(230, 1, 101, 0.55);
  backdrop-filter: blur(4px);
}
.card-body { padding: 0.85rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.3rem; }
.card-title { font-weight: 800; font-size: 0.97rem; letter-spacing: -0.01em; }
.card-desc { font-size: 0.84rem; color: var(--muted-foreground); line-height: 1.5; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius); border: 1px solid transparent;
  padding: 0.45rem 1rem; min-height: 2.6rem; min-width: 2.6rem;
  background: transparent; color: var(--foreground); cursor: pointer;
  gap: 0.45rem; font-weight: 700;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s, filter 0.12s;
}
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
/* The captain.works CTA: bottom-to-top magenta -> violet gradient. */
.btn-primary {
  background: linear-gradient(0deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.12); }
/* The site's secondary: solid white on black. */
.btn-white { background: #fff; color: #0a0a0b; }
.btn-white:hover { opacity: 0.9; }
.btn-outline { border-color: var(--border); }
.btn-outline:hover { background: var(--muted); }
.btn-ghost:hover { background: var(--muted); }
.btn-sm { min-height: 2.1rem; padding: 0.25rem 0.7rem; font-size: 0.85rem; }
/* Small buttons drop the two-color CTA gradient for a solid fill (user
   request 2026-08-17; kept in the gradient syntax they specified). */
.btn-sm.btn-primary { background: linear-gradient(0turn, rgba(201, 0, 135, 1) 0%, rgba(201, 0, 135, 1) 100%); }
.btn-icon { padding: 0.2rem 0.55rem; }
.btn-danger { color: var(--danger); }
.btn:disabled { opacity: 0.4; cursor: default; }

.input, .select {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--foreground);
  padding: 0.4rem 0.7rem; min-height: 2.6rem; font: inherit;
}
.input::placeholder { color: var(--muted-foreground); }
.input:focus-visible, .select:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.input-sm { min-height: 2.1rem; padding: 0.2rem 0.55rem; font-size: 0.85rem; }

.badge {
  font-size: 0.7rem; font-weight: 700; padding: 0.14rem 0.55rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted-foreground); white-space: nowrap;
  background: var(--muted);
}
.badge.ok { color: var(--success); border-color: rgba(53, 208, 115, 0.35); }
.badge.info { color: #7ab8ff; border-color: rgba(90, 160, 255, 0.4); background: rgba(90, 160, 255, 0.12); }
.badge.accent { color: #ff5fa2; border-color: rgba(230, 1, 101, 0.4); background: rgba(230, 1, 101, 0.12); }
.badge.warn { color: #ffb020; border-color: rgba(255, 176, 32, 0.35); }
.badge.danger { color: var(--danger); border-color: rgba(255, 77, 109, 0.45); }

/* ---------- login screen ---------- */

.center-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 1rem; z-index: 40;
  background:
    radial-gradient(60% 45% at 70% 0%, rgba(128, 0, 219, 0.28), transparent 65%),
    radial-gradient(50% 35% at 20% 100%, rgba(230, 1, 101, 0.14), transparent 60%),
    var(--background);
}
.login-card {
  background: rgba(21, 21, 23, 0.85); border: 1px solid var(--border); border-radius: 1.1rem;
  padding: 2.3rem 1.9rem; max-width: 25rem; width: 100%; text-align: center;
  display: flex; flex-direction: column; gap: 1rem; align-items: center;
  backdrop-filter: blur(6px);
}
.login-card h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.02em; font-weight: 800; }
.login-card p { margin: 0; font-size: 0.9rem; color: var(--muted-foreground); }
.login-mark img { height: 3.4rem; width: auto; }
.login-mark { font-size: 2.6rem; line-height: 1; }
.login-wait { display: flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; color: var(--muted-foreground); }
.spinner {
  width: 1rem; height: 1rem; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  .card, .card.clickable:hover { transform: none; transition: none; }
}

/* ---------- internal page view ---------- */

.inner-page { max-width: 44rem; }
.inner-page .back-row { margin-bottom: 1rem; }
.inner-page h1 { font-size: 1.5rem; margin: 0 0 0.9rem; letter-spacing: -0.02em; font-weight: 800; }
/* Long-form reading: body copy at 16px with softened near-white — pure
   #fff on near-black is max contrast and tires the eye; headings stay
   full-white for hierarchy (2026-08-21). */
.inner-page { font-size: 1rem; color: rgba(255, 255, 255, 0.85); }
.inner-page h1, .inner-page h2, .inner-page h3 { color: var(--foreground); }
.inner-page h2 {
  font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em;
  margin: 2rem 0 0.6rem;
}
.inner-page h2:first-child { margin-top: 0; }
.inner-page ul { padding-left: 1.2rem; line-height: 1.7; }
.inner-page li { margin: 0.35rem 0; }
.inner-page p { line-height: 1.7; }

/* ---------- tables (admin, rating ledger) ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.table th {
  text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted-foreground); font-weight: 700;
  padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border);
  background: var(--muted); white-space: nowrap;
}
.table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; }
/* First two columns pinned while the wrapper scrolls horizontally
   (--sticky-col1 = measured width of column 1, set from JS). */
.table-sticky-2 th:nth-child(-n+2), .table-sticky-2 td:nth-child(-n+2) {
  position: sticky; z-index: 2; background: var(--card); white-space: nowrap;
  /* ~ «Сергей Головков» / «Sergey_Golovkov»; longer values get an ellipsis (full text in title). */
  max-width: 9.5rem; overflow: hidden; text-overflow: ellipsis;
}
.table-sticky-2 th:nth-child(-n+2) { background: var(--muted); z-index: 3; }
.table-sticky-2 th:nth-child(1), .table-sticky-2 td:nth-child(1) { left: 0; }
.table-sticky-2 th:nth-child(2), .table-sticky-2 td:nth-child(2) {
  left: var(--sticky-col1, 9rem); box-shadow: inset -1px 0 0 var(--border);
}

/* ---------- admin: rule editor ---------- */

.entity-card {
  border: 1px solid var(--border); border-radius: 0.85rem;
  background: var(--card); padding: 0.9rem 1.05rem; margin-bottom: 0.8rem;
}
.entity-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; cursor: pointer; }
/* Short admin-facing note under an entity head in the permissions editor. */
.entity-note { margin: 0.45rem 0 0; font-size: 0.82rem; line-height: 1.45; color: var(--muted-foreground); max-width: 46rem; }
/* Divider between the visibility blocks and the click-routing/access block. */
.rule-divider { border-top: 1px solid var(--border); margin: 1.1rem 0; }
/* Admin "view as participant" mode: fixed pill so it is visible on every page. */
.viewas-banner {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%);
  z-index: 2000; display: flex; align-items: center; gap: 0.8rem;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 0.88rem;
  padding: 0.5rem 0.7rem 0.5rem 1.1rem; border-radius: 999px;
  box-shadow: 0 8px 32px rgba(230, 1, 101, 0.35);
  max-width: min(92vw, 40rem);
}
.viewas-banner span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Structure tab: sections -> cards -> pages tree + tg-link rows. */
.structure-card { border-left: 2px solid var(--border); margin: 0.8rem 0 0 0.3rem; padding: 0.1rem 0 0.1rem 0.9rem; }
.structure-card-title { font-weight: 700; font-size: 0.92rem; margin-bottom: 0.25rem; }
.structure-page { border-left: 2px solid var(--border); margin: 0.6rem 0 0.2rem 0.6rem; padding: 0.1rem 0 0.1rem 0.9rem; }
.structure-line { font-size: 0.85rem; margin: 0.2rem 0; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.structure-line a { word-break: break-all; }
.tg-link-row { font-size: 0.85rem; margin: 0.25rem 0; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.tg-link-row a { word-break: break-all; }
/* Points policy lists (admin) and the rating narrative (user). */
.points-rules { margin: 0.5rem 0 0; padding-left: 1.2rem; line-height: 1.65; font-size: 0.9rem; }
.points-rules li { margin: 0.15rem 0; }
/* Drag & drop ordering (admin: perms editor blocks + pages table). */
.drag-handle { display: inline-flex; align-items: center; color: var(--muted-foreground); cursor: grab; }
.drag-handle:active { cursor: grabbing; }
.drag-handle .icon { width: 1rem; height: 1rem; }
.entity-card.dragging, tr.dragging { opacity: 0.45; }
.head-open { display: inline-flex; align-items: center; margin-left: auto; }
.head-open .icon { width: 1rem; height: 1rem; }
.entity-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; color: var(--muted-foreground); }
.rule-block { margin-top: 0.85rem; }
.rule-block-title { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground); margin-bottom: 0.45rem; }
.rule-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.rule-row .select, .rule-row .input { min-height: 2.1rem; padding: 0.2rem 0.5rem; font-size: 0.84rem; }
.rule-row .grow { flex: 1; min-width: 8rem; }
.rule-actions { display: flex; gap: 0.45rem; margin-top: 0.55rem; flex-wrap: wrap; }

.stat-row { display: flex; gap: 0.9rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.stat {
  border: 1px solid var(--border); border-radius: 0.85rem; background: var(--card);
  padding: 0.8rem 1.1rem; min-width: 8.5rem;
}
.stat .stat-value {
  font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(0deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.stat .stat-label { font-size: 0.75rem; color: var(--muted-foreground); }

.toast {
  position: fixed; top: 1.2rem; left: 50%; transform: translateX(-50%);
  background: #fff; color: #0a0a0b;
  padding: 0.6rem 1.1rem; border-radius: var(--radius); font-size: 0.9rem; font-weight: 700;
  z-index: 100; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); max-width: 90vw;
}

/* ---------- profile ---------- */

.profile-card {
  display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: 1rem; background: var(--card);
  padding: 1.3rem 1.4rem; max-width: 32rem;
}
.profile-card .avatar { width: 4rem; height: 4rem; font-size: 1.4rem; }
.profile-info { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.profile-name { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em; }
.profile-meta { font-size: 0.85rem; color: var(--muted-foreground); word-break: break-all; }
.profile-badges { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.3rem; }

/* ---------- mobile ---------- */
/* Sidebar becomes a top bar with horizontally scrollable pill nav; everything
   must fit 320px with zero horizontal page scroll. */

@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center;
    border-right: 0; border-bottom: 1px solid var(--border);
    padding: 0.45rem 0.55rem; gap: 0.3rem;
    overflow-x: auto; scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 0.2rem 0.35rem; flex: none; }
  .brand img.brand-logo { height: 1.6rem; }
  .nav-items { flex-direction: row; gap: 0.25rem; }
  .nav-item { width: auto; flex: none; padding: 0.4rem 0.7rem; min-height: 2.25rem; font-size: 0.85rem; white-space: nowrap; }
  .nav-item .icon { display: none; }
  .sidebar .spacer { display: none; }
  .sidebar-user { border-top: 0; margin: 0 0 0 auto; padding: 0.2rem 0.3rem; flex: none; }
  .sidebar-user .u-name { display: none; }
  .avatar { width: 1.75rem; height: 1.75rem; }
  .content-inner { padding: 1.1rem 0.85rem 2.5rem; }
  .card-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 1.35rem; }
}

/* ---------- user-app main-area scale ---------- */
/* USER platform only (body.app-user; the admin keeps stock sizes): the main
   content is +10% via explicit element sizes — no zoom (user request
   2026-08-17) — and card tiles are +15% via the grid minimum. The sidebar is
   deliberately untouched. */

.app-user .content { font-size: 1.1rem; }             /* inherited text +10% */
.app-user .page-title { font-size: 1.87rem; }
.app-user .section-title { font-size: 1.27rem; }
.app-user .section-desc { font-size: 0.97rem; }
.app-user .card-title { font-size: 1.07rem; }
.app-user .card-desc { font-size: 0.92rem; }
.app-user .inner-page h1 { font-size: 1.65rem; }
.app-user .content .btn { min-height: 2.85rem; }
.app-user .content .badge { font-size: 0.77rem; }
.app-user .content .table { font-size: 0.95rem; }
.app-user .stat .stat-value { font-size: 1.7rem; }
.app-user .profile-name { font-size: 1.32rem; }
.app-user .profile-meta { font-size: 0.94rem; }
/* Card tiles (and with them the preview images) are ~+15%: the grid minimum
   grows 15rem -> 17.25rem and the content column widens 64rem -> 73.6rem, so
   the same 3-per-row layout renders visibly larger tiles. */
.app-user .content-inner { max-width: 73.6rem; }
.app-user .card-grid { grid-template-columns: repeat(auto-fill, minmax(17.25rem, 1fr)); }
@media (max-width: 760px) {
  .app-user .card-grid { grid-template-columns: 1fr; }
}

/* ---------- icon sizing (inline SVG, Lucide) ---------- */

.icon { width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }
.btn .icon { width: 1.1em; height: 1.1em; }
.nav-item .icon { width: 1.15em; height: 1.15em; }

/* ---------- admin: RnD-draft card preview ---------- */
/* Replicates the USER platform's real rendered card size: content column
   73.6rem minus 2x1.5rem padding and 2x1rem grid gaps over 3 columns
   = 22.87rem — NOT the 17.25rem grid minimum. Typography matches the
   .app-user card scale. */
.draft-card-preview { width: 22.87rem; max-width: 100%; position: relative; }
.draft-card-preview .card-title { font-size: 1.07rem; }
.draft-card-preview .card-desc { font-size: 0.92rem; }

/* ---------- inner-page quotes (Alumni RnD Terms examples etc.) ---------- */
.inner-page blockquote {
  margin: 1rem 0; padding: 0.75rem 1.1rem;
  border-left: 3px solid rgba(230, 1, 101, 0.55);
  background: var(--muted);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.inner-page blockquote p { margin: 0 0 0.6rem; }
.inner-page blockquote p:last-child { margin-bottom: 0; }

/* ---------- admin: «Разделы» tree (menu -> sections -> cards) ---------- */
.tree-node { margin-bottom: 0.6rem; }
.tree-children {
  margin: 0.6rem 0 0.2rem 1.4rem;
  padding-left: 0.9rem;
  border-left: 2px solid var(--border);
}

/* While dragging a tree node, hide its subtree (and dim the node) so the
   browser moves a small block instead of re-laying-out dozens of editors. */
.tree-node.drag-collapsed .tree-children { display: none; }
.tree-node.dragging { opacity: 0.6; }

/* ---------- light theme (user setting «Настройки», localStorage) ---------- */
[data-theme="light"] {
  --background: #f7f7f9;
  --foreground: #16161a;
  --card: #ffffff;
  --muted: #ececf0;
  --muted-foreground: #63636e;
  --border: #dcdce2;
  --primary: #16161a;
  --primary-foreground: #ffffff;
  color-scheme: light;
}
[data-theme="light"] body {
  background:
    radial-gradient(55% 38% at 75% -5%, rgba(128, 0, 219, 0.07), transparent 65%),
    radial-gradient(45% 30% at 15% 105%, rgba(230, 1, 101, 0.05), transparent 60%),
    var(--background);
}
[data-theme="light"] .sidebar { background: rgba(255, 255, 255, 0.65); }
[data-theme="light"] .login-card { background: rgba(255, 255, 255, 0.92); }
[data-theme="light"] .btn-white { background: #16161a; color: #ffffff; }
[data-theme="light"] .inner-page { color: rgba(22, 22, 26, 0.88); }
[data-theme="light"] .card-img-placeholder {
  background:
    radial-gradient(70% 100% at 50% 0%, rgba(128, 0, 219, 0.10), transparent 70%),
    #ececf0;
}
[data-theme="light"] img.brand-logo,
[data-theme="light"] .login-mark img {
  content: url("/shared/img/logo_light.svg?v=7");
}

/* ---------- admin: digest message popup ---------- */
.kb-modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.kb-modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 1rem;
  max-width: 46rem; width: 100%; max-height: 82vh;
  display: flex; flex-direction: column; padding: 1rem 1.2rem;
}
.kb-modal .kb-modal-close { margin-left: auto; }
.kb-modal-body { overflow-y: auto; margin-top: 0.6rem; }
.kb-msg { padding: 0.55rem 0; border-bottom: 1px solid var(--border); line-height: 1.55; }
.kb-msg:last-child { border-bottom: none; }
.kb-msg-text { white-space: pre-wrap; overflow-wrap: break-word; }
.kb-msg-img { max-width: 100%; max-height: 24rem; border-radius: 0.5rem; border: 1px solid var(--border); display: block; cursor: zoom-in; margin: 0.4rem 0; }
.kb-lightbox { position: fixed; inset: 0; z-index: 300; background: rgba(0, 0, 0, 0.85); display: flex; align-items: center; justify-content: center; padding: 2rem; cursor: zoom-out; }
.kb-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 0.5rem; cursor: default; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6); }
.kb-lightbox-close { position: absolute; top: 1rem; right: 1rem; cursor: pointer; }
/* Digest review table: keep «За что» readable, cap the email column. */
.table .dg-reason { min-width: 24rem; max-width: 32rem; }
.table .dg-email { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Digest link rows: Q/A dimmed, the summary (S) is the line to read. */
.table .kb-qa { color: var(--muted-foreground); }
.table .kb-s { color: var(--foreground); font-weight: 600; margin-top: 0.2rem; }
/* Digest per-chat spoilers */
details.dg-spoiler { margin-top: 0.6rem; }
details.dg-spoiler > summary { cursor: pointer; font-weight: 700; font-size: 1rem; padding: 0.35rem 0; list-style: none; }
details.dg-spoiler > summary::before { content: "▸ "; color: var(--muted-foreground); }
details.dg-spoiler[open] > summary::before { content: "▾ "; }
.kb-msg-text a { color: var(--accent); word-break: break-all; }
.kb-msg-text code, .kb-msg-text pre { font-family: ui-monospace, Menlo, monospace; font-size: 0.85em; background: var(--muted); border-radius: 0.3rem; padding: 0 0.25rem; }
.kb-msg-text pre { display: block; padding: 0.5rem; overflow-x: auto; }
.kb-msg-text blockquote { margin: 0.2rem 0; padding-left: 0.6rem; border-left: 2px solid var(--border); color: var(--muted-foreground); }
/* Insight card popup */
.kb-insight { max-width: 52rem; }
.kb-insight-body h2 { font-size: 1.25rem; margin: 0.2rem 0 0.6rem; }
.kb-insight-body h3 { font-size: 1rem; margin: 1rem 0 0.35rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-foreground); }
.kb-insight-body p { margin: 0.35rem 0; line-height: 1.55; }
.kb-insight-body ol, .kb-insight-body ul { margin: 0.3rem 0 0.6rem 1.2rem; padding: 0; line-height: 1.55; }
.kb-insight-body li { margin: 0.2rem 0; }
.kb-insight-body a { color: var(--accent); word-break: break-all; }
.kb-insight-body img.kb-msg-img { margin: 0.5rem 0; }
/* Search results / chat reader */
.kb-msg-hit { background: rgba(230, 1, 101, 0.08); border-left: 2px solid var(--accent); padding-left: 0.6rem; }
.kb-msg .badge { vertical-align: middle; }
a.badge { text-decoration: none; }

/* ===== KB UI kit (2026-09-17): page head, filter panel, entity cards, prose, steps ===== */
a.btn, a.btn:hover { text-decoration: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head .page-title, .page-head .page-desc { margin-bottom: 0.3rem; }
.page-head > div { min-width: 0; flex: 1; }
.page-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; padding-top: 0.35rem; }

/* Tabs (Search: substring / AI) */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin: 0 0 1rem; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 0.55rem 0.9rem;
  font: inherit; font-weight: 600; color: var(--muted-foreground); cursor: pointer; min-height: 44px; }
.tab:hover { color: var(--foreground); }
.tab.active { color: var(--foreground); border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; border-radius: 0.3rem; }

/* Toolbar above tables/cards: actions right on desktop, full-width on phones */
.toolbar { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; margin: 0 0 0.8rem; }
/* Client-side substring filter over cards/rows + match highlight */
.kb-live { display: flex; align-items: center; gap: 0.6rem; margin: 0 0 0.8rem; }
.kb-live .input { flex: 1; min-width: 0; }
.kb-live-n { font-size: 0.8rem; white-space: nowrap; }
.toolbar .toolbar-filter { flex: 1 1 16rem; min-width: 0; }
.toolbar .toolbar-filter .kb-live { margin: 0; }
mark.hl { background: #ffb020; color: #1a1a1f; border-radius: 0.2rem; padding: 0 0.1em; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; margin: 1.2rem 0 0.6rem; }
.section-head .section-title { margin: 0; }
@media (max-width: 640px) { .toolbar .btn, .section-head > .btn { flex: 1 1 100%; justify-content: center; } }

/* Filter panel: search row, always-open labelled grid, AND note + actions */
.kb-panel { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; padding: 1rem 1.1rem; }
.kb-panel + .kb-panel, .kb-panel + .kb-results, .kb-results + .kb-panel { margin-top: 1rem; }
.kb-search-row { display: flex; gap: 0.5rem; align-items: center; }
.kb-search-row .input { flex: 1; min-width: 0; }
.kb-fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.6rem 0.9rem; margin-top: 0.8rem; padding: 0.8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--muted); }
.kb-fgrid-top { margin-top: 0; }
.kb-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.kb-field.wide { grid-column: 1 / -1; }
.kb-field > span { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground); }
.kb-fgrid .input { background: var(--card); }
.kb-factions { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted-foreground); }
.kb-factions .kb-fbtns { display: flex; gap: 0.5rem; margin-left: auto; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted-foreground); }
.btn-ghost:hover { background: var(--muted); color: var(--foreground); }

/* Multi-select dropdown with its own search */
.ms { position: relative; }
.ms-btn { width: 100%; justify-content: space-between; font-weight: 600; }
.ms-pop { position: absolute; z-index: 50; top: calc(100% + 0.3rem); left: 0; min-width: 100%; width: max-content; max-width: 28rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0,0,0,0.45); padding: 0.5rem; }
.ms-pop .input { width: 100%; margin-bottom: 0.4rem; }
.ms-list { max-height: 16rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.1rem; }
.ms-list label { display: flex; align-items: center; gap: 0.45rem; padding: 0.3rem 0.4rem; border-radius: 0.4rem; font-size: 0.86rem; cursor: pointer; }
.ms-list label:hover { background: var(--muted); }
.ms-list label span.muted { margin-left: auto; font-size: 0.78rem; white-space: nowrap; }
.ms-tools { display: flex; gap: 0.6rem; font-size: 0.78rem; margin-bottom: 0.3rem; }
.ms-tools a { cursor: pointer; }

/* Entity card (message / link / bio / insight) */
.kb-results { display: flex; flex-direction: column; gap: 0.7rem; }
.kb-card { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; padding: 0.85rem 1rem 0.95rem; }
.kb-card.kb-hit { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(230, 1, 101, 0.18); }
.kb-card-head { display: flex; align-items: flex-start; gap: 0.7rem; flex-wrap: wrap; }
.kb-card-head .avatar { width: 2.75rem; height: 2.75rem; font-size: 1rem; }
.kb-card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.kb-card-line1 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.5rem; line-height: 1.25; }
.kb-card-line1 .n { font-weight: 700; font-size: 0.92rem; }
.kb-card-line1 .u { font-size: 0.82rem; color: var(--muted-foreground); }
.kb-card-who { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.kb-card-who .n { font-weight: 700; font-size: 0.9rem; }
.kb-card-who .u { font-size: 0.78rem; color: var(--muted-foreground); }
.kb-card-meta { font-size: 0.78rem; color: var(--muted-foreground); white-space: nowrap; }
.kb-msg-id { font-family: ui-monospace, Menlo, monospace; }
a.kb-msg-id { color: inherit; text-decoration: none; border-bottom: 1px dashed currentColor; }
a.kb-msg-id:hover { color: var(--accent); }
.kb-card-actions { margin-left: auto; display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.kb-card-tags { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.kb-card-body { margin-top: 0.55rem; }
.kb-card-body .kb-qa { margin: 0.15rem 0; }
.kb-card-body .kb-s { margin-top: 0.35rem; }
.kb-score { font-size: 0.74rem; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }

/* Long-form text: AI answer, insight card, message bodies */
.kb-prose { font-size: 0.95rem; line-height: 1.65; max-width: 72ch; }
.kb-panel.kb-answer { max-width: none; }
.kb-panel.kb-answer > * { max-width: 72ch; }
.kb-prose p { margin: 0.45rem 0; }
.kb-prose h2 { font-size: 1.2rem; margin: 0.4rem 0 0.7rem; letter-spacing: -0.02em; }
.kb-prose h3 { font-size: 0.82rem; margin: 1.1rem 0 0.4rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground); }
.kb-prose ul, .kb-prose ol { margin: 0.4rem 0 0.7rem 1.3rem; padding: 0; }
.kb-prose li { margin: 0.25rem 0; }
.kb-prose a { color: var(--accent); word-break: break-word; }
.kb-prose code, .kb-prose pre { font-family: ui-monospace, Menlo, monospace; font-size: 0.86em; background: var(--muted); border-radius: 0.3rem; }
.kb-prose code { padding: 0.05em 0.3em; }
.kb-prose pre { display: block; padding: 0.6rem 0.75rem; margin: 0.5rem 0; overflow-x: auto; white-space: pre; border: 1px solid var(--border); }
.kb-prose pre code { padding: 0; background: none; }
.kb-prose blockquote { margin: 0.5rem 0; padding: 0.4rem 0.8rem; border-left: 3px solid var(--accent); background: var(--muted); border-radius: 0 0.4rem 0.4rem 0; color: var(--foreground); }
.kb-prose li blockquote { margin: 0.4rem 0 0.2rem; }
.kb-prose table { border-collapse: collapse; margin: 0.5rem 0; font-size: 0.9em; }
.kb-prose th, .kb-prose td { border: 1px solid var(--border); padding: 0.3rem 0.6rem; text-align: left; vertical-align: top; }
.kb-prose th { background: var(--muted); font-weight: 700; }
.kb-prose a.kb-fn { color: var(--foreground); background: var(--muted); border-radius: 0.3rem; padding: 0 0.3rem; font-size: 0.8em; text-decoration: none; }
.kb-prose a.kb-fn:hover { background: var(--border); }
.kb-msg-text { font-size: 0.95rem; line-height: 1.6; }
.kb-msg-text.muted { font-size: 0.85rem; }

/* Progress chips for the AI job */
.kb-steps { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.kb-step { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.3rem 0.65rem; border-radius: 999px; border: 1px solid var(--border); background: var(--muted); font-size: 0.8rem; font-weight: 600; color: var(--muted-foreground); }
.kb-step.done { color: var(--foreground); }
.kb-step.done svg { color: var(--success); }
.kb-step.now { color: var(--foreground); border-color: rgba(230, 1, 101, 0.55); }
.kb-step.err { color: #fff; background: rgba(255, 77, 109, 0.25); border-color: var(--danger); }
.kb-spin { width: 0.8rem; height: 0.8rem; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: kb-spin 0.8s linear infinite; }
@keyframes kb-spin { to { transform: rotate(360deg); } }
.kb-step svg { width: 0.85rem; height: 0.85rem; }

/* Tables: clipped text columns */
.table .td-clip { max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .td-clip-l { max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .td-num { text-align: right; white-space: nowrap; }
/* The ellipsis belongs to the clipped element: clip the link itself, not the cell */
/* display:block gives the link the cell's real width (inline-block + max-width:100% could collapse to «…» alone) */
.table .td-clip > a, .table .td-clip-l > a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .clip-row { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.table .clip-row .clip { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sg-comment-box { display: flex; flex-direction: column; gap: 0.3rem; min-width: 14rem; }
.sg-comment-box .sg-apply-row { align-self: flex-start; }
.pager { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.6rem; flex-wrap: wrap; }
.sg-comment-box select.sg-reason-pick { max-width: 18rem; }
.input.input-error { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(255, 77, 109, 0.2); }
.btn-stack { display: inline-flex; flex-direction: column; gap: 0.35rem; align-items: stretch; }
.btn-stack .btn { justify-content: center; }
.table .td-who { max-width: 15rem; white-space: nowrap; }
.table .td-who .kb-card-head { flex-wrap: nowrap; align-items: center; gap: 0.5rem; }
.table .td-who .avatar { width: 2rem; height: 2rem; font-size: 0.75rem; }
.table .td-who .kb-card-who { min-width: 0; overflow: hidden; }
.table .td-who .kb-card-who .n, .table .td-who .kb-card-who .u { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-sticky-1 th:first-child, .table-sticky-1 td:first-child { position: sticky; left: 0; z-index: 2; background: var(--card); box-shadow: inset -1px 0 0 var(--border); }
.table-sticky-1 th:first-child { background: var(--muted); z-index: 3; }

/* RnD cards: key/value table with chips and clipped links */
.rnd-table th { width: 7rem; white-space: nowrap; vertical-align: top; }
.rnd-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; min-width: 0; }
.rnd-link { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; font-size: 0.82rem; }
a.badge { text-decoration: none; }
a.badge:hover { border-color: var(--accent); }

/* Reader toolbar */
.kb-reader-head { position: sticky; top: 0; z-index: 5; background: var(--background); padding: 0.4rem 0 0.6rem; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.kb-reader-head .page-title { margin: 0; font-size: 1.3rem; }
.kb-reader-nav { display: flex; justify-content: center; margin: 0.6rem 0; }
@media (max-width: 640px) { .kb-fgrid { grid-template-columns: 1fr; } .kb-card-actions { margin-left: 0; width: 100%; } }
