/* ============================================================
   feld — дизайн-система на стыке Vercel и Linear
   Vercel: монохром, Geist, hairline-бордеры, чёткая типографика.
   Linear: тёмная тема по умолчанию, blur-поверхности, точечные
   акценты, плотные списки, спокойные микровзаимодействия.
   ============================================================ */

/* ---------- Шрифты (самохостинг, без внешних запросов) ---------- */

@font-face {
  font-family: "Geist";
  src: url("/static/fonts/geist-latin-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist";
  src: url("/static/fonts/geist-cyrillic-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/static/fonts/geist-mono-latin-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/static/fonts/geist-mono-cyrillic-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* ---------- Токены ---------- */

:root {
  color-scheme: light;
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #ebebed;
  --border: #e6e6e8;
  --border-strong: #d8d8dc;
  --fg: #171717;
  --fg-muted: #63636b;
  --fg-faint: #8f8f97;
  --accent: #5e6ad2;
  --accent-hover: #4f5bc4;
  --accent-soft: color-mix(in srgb, #5e6ad2 10%, transparent);
  --success: #1f8a4d;
  --warning: #96651a;
  --danger: #d93036;
  --card-shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 0 0 0.5px rgb(0 0 0 / 0.02);
  --ring: color-mix(in srgb, var(--accent) 32%, transparent);
  --topbar-bg: color-mix(in srgb, var(--bg) 74%, transparent);
  --code-bg: #f6f6f7;
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0b;
  --surface: #101012;
  --surface-2: #17171a;
  --surface-3: #1e1e22;
  --border: #232327;
  --border-strong: #323238;
  --fg: #ededee;
  --fg-muted: #9c9ca6;
  --fg-faint: #6c6c76;
  --accent: #7c86e8;
  --accent-hover: #939bf0;
  --accent-soft: color-mix(in srgb, #7c86e8 12%, transparent);
  --success: #4cb782;
  --warning: #e0a33e;
  --danger: #ec5c62;
  --card-shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 0 0 0.5px rgb(255 255 255 / 0.03);
  --ring: color-mix(in srgb, var(--accent) 40%, transparent);
  --topbar-bg: color-mix(in srgb, var(--bg) 68%, transparent);
  --code-bg: #151518;
}

/* ---------- База ---------- */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 400 14px/1.6 var(--font-sans);
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { letter-spacing: -0.021em; font-weight: 600; }
h1 { font-size: 20px; line-height: 1.3; margin: 0; }
h2 { font-size: 16px; margin: 0; }

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

::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

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

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

@media (prefers-reduced-motion: no-preference) {
  .btn, .icon-btn, .input, .badge, .nav-link, tr, .doclist a, .switch input, .switch input::before {
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
      box-shadow 0.15s ease, transform 0.15s ease;
  }
}

/* Скроллбары — тонкие, ненавязчивые */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Раскладка ---------- */

.page { max-width: 1040px; margin: 0 auto; padding: 32px 24px 64px; }
.page.narrow { max-width: 640px; }
.page.wide { max-width: 1440px; }
.page.slim { max-width: 840px; }

.spacer { flex: 1; }
.inline { display: inline; }
.side { display: grid; gap: 16px; min-width: 0; }
p a svg, .hint a svg, td a svg { vertical-align: -2px; }
.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); }
.mono { font-family: var(--font-mono); font-size: 0.93em; }
.row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }

/* ---------- Топбар ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1488px;
  margin: 0 auto;
  height: 52px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.02em;
}
.brand:hover { color: var(--fg); }
.brand .logo { display: block; color: var(--fg); }

.nav { display: flex; align-items: center; gap: 2px; margin-left: 6px; }
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  color: var(--fg-muted);
  font-size: 13.5px;
  font-weight: 500;
}
.nav-link:hover { color: var(--fg); background: var(--surface-2); }
.nav-link.active { color: var(--fg); background: var(--surface-2); }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 4px 0 10px;
  border-radius: 7px;
  color: var(--fg-muted);
  font-size: 13px;
}
.user-chip .avatar {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

/* Иконка темы: солнце в тёмной, луна в светлой */
[data-theme-toggle] .icon-sun { display: none; }
[data-theme="dark"] [data-theme-toggle] .icon-sun { display: block; }
[data-theme="dark"] [data-theme-toggle] .icon-moon { display: none; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn svg { flex: none; }

.btn-primary {
  background: var(--fg);
  color: var(--bg);
  box-shadow: 0 0 0 0.5px rgb(0 0 0 / 0.12);
}
.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--fg) 86%, var(--bg));
  color: var(--bg);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: 0 1px 1.5px rgb(0 0 0 / 0.04);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }

.btn-ghost { color: var(--fg-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--fg); }

.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; gap: 5px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.icon-btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.icon-btn.sm { width: 26px; height: 26px; }

/* ---------- Поля ввода ---------- */

.field { display: block; margin: 0; }
.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
}
.field-label .optional { color: var(--fg-faint); font-weight: 400; }

.input,
select.input,
textarea.input {
  width: 100%;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-size: 13.5px;
  box-shadow: 0 1px 1.5px rgb(0 0 0 / 0.03);
}
textarea.input {
  height: auto;
  min-height: 46vh;
  padding: 12px 14px;
  font: 400 13px/1.65 var(--font-mono);
  resize: vertical;
  tab-size: 2;
}
textarea.input.dragover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.input::placeholder { color: var(--fg-faint); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
.input.mono-input { font-family: var(--font-mono); font-size: 12.5px; }

select.input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16' fill='none' stroke='%23888' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

/* Переключатель (Linear-style switch) */
.switch { position: relative; display: inline-block; flex: none; width: 30px; height: 17px; }
.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
}
.switch input:checked {
  background: var(--accent);
  border-color: transparent;
}
.switch input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.16s cubic-bezier(0.3, 0.7, 0.4, 1);
}
.switch input:checked::before { transform: translateX(13px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--fg);
}
.option-row .switch { margin-top: -1px; }

/* Сегментированный контрол (срок ссылки) */
.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.segmented label { position: relative; display: inline-flex; }
.segmented input {
  position: absolute;
  inset: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.segmented span {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 12px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fg-muted);
  position: relative;
  z-index: 1;
}
.segmented input:checked + span {
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 0 0 0.5px rgb(0 0 0 / 0.04);
}
:root[data-theme="dark"] .segmented input:checked + span {
  background: var(--surface-3);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 0 0 0.5px rgb(255 255 255 / 0.05);
}
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Карточки ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
}
.card.pad { padding: 28px; }
.card.center { text-align: center; }

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-head h1, .card-head h2 { font-size: 14.5px; }
.card-body { padding: 20px; }

/* ---------- Баннеры ---------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  border: 1px solid color-mix(in srgb, var(--warning) 32%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--warning) 9%, transparent);
  font-size: 13.5px;
  color: var(--fg);
}
.banner svg { flex: none; margin-top: 2px; color: var(--warning); }
.banner.ok {
  border-color: color-mix(in srgb, var(--success) 32%, transparent);
  background: color-mix(in srgb, var(--success) 9%, transparent);
}
.banner.ok svg { color: var(--success); }
.banner.error {
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
  background: color-mix(in srgb, var(--danger) 9%, transparent);
}
.banner.error svg { color: var(--danger); }

/* ---------- Бейджи (Linear-style: точка + текст) ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg-muted);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.ok {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  background: color-mix(in srgb, var(--success) 9%, transparent);
}
.badge.burned {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
  background: color-mix(in srgb, var(--warning) 9%, transparent);
}
.badge svg { flex: none; }

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--fg-faint);
  font: 500 10.5px/1 var(--font-sans);
  letter-spacing: 0;
}

/* Фильтр каталога */
.doc-filter-field { flex: 0 1 auto; }
#doc-filter { width: 200px; height: 32px; }

/* ---------- Таблица каталога ---------- */

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-faint);
  letter-spacing: 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--fg-muted);
}
.table tbody tr { background: transparent; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .doc-title {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 320px;
  color: var(--fg);
  font-weight: 500;
}
.table .doc-title svg { flex: none; color: var(--fg-faint); }
.table .doc-title .t {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table td.num { text-align: right; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions .icon-btn { opacity: 0.55; }
.table tr:hover td.actions .icon-btn,
.table td.actions .icon-btn:focus-visible { opacity: 1; }
.table .cell-strong { color: var(--fg); }

/* ---------- Пустое состояние ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 56px 24px;
  text-align: center;
}
.empty .empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  color: var(--fg-faint);
}
.empty h2 { font-size: 15px; }
.empty p { margin: 0; font-size: 13.5px; color: var(--fg-muted); }
.empty .btn { margin-top: 14px; }

/* ---------- Авторизация ---------- */

.auth-wrap { position: relative; min-height: 100vh; }
.auth-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(560px 320px at 50% -60px, color-mix(in srgb, var(--accent) 14%, transparent), transparent 72%);
}
:root[data-theme="dark"] .auth-glow {
  background:
    radial-gradient(560px 320px at 50% -60px, color-mix(in srgb, var(--accent) 17%, transparent), transparent 72%),
    radial-gradient(900px 480px at 50% 110%, rgb(255 255 255 / 0.02), transparent 70%);
}
.auth-card {
  position: relative;
  max-width: 380px;
  margin: 14vh auto 0;
  padding: 36px 32px 30px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
}
.auth-card .brand-big {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
  text-align: center;
}
.brand-word {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.03em;
  background: linear-gradient(160deg, var(--fg) 55%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.auth-card .logo-glow {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-strong);
  box-shadow: var(--card-shadow);
  color: var(--fg);
}
.auth-card form { margin-top: 20px; display: grid; gap: 14px; }
.auth-card .btn { width: 100%; height: 36px; margin-top: 4px; }
.auth-card .hint { text-align: center; }
.auth-foot {
  margin-top: 18px;
  text-align: center;
  font-size: 12.5px;
  color: var(--fg-faint);
}

.hint { color: var(--fg-muted); font-size: 13px; line-height: 1.55; }
.error-text {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  color: var(--danger);
  font-size: 13px;
}

/* ---------- Страница «ссылка готова» ---------- */

.success-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.success-icon {
  flex: none;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--success);
  background: color-mix(in srgb, var(--success) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--success) 28%, transparent);
}
.meta-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; }

.link-group {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin: 16px 0 6px;
}
.link-group .input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--accent);
}

/* ---------- Код-блок с шапкой ---------- */

.codeblock {
  margin: 10px 0 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  overflow: hidden;
}
.codeblock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  font: 500 11.5px/1 var(--font-mono);
  color: var(--fg-faint);
  letter-spacing: 0.02em;
}
.codeblock pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font: 400 12px/1.6 var(--font-mono);
  color: var(--fg-muted);
}
.codeblock code { font: inherit; }

/* ---------- Чтение документа ---------- */

.read-sheet { max-width: 1200px; margin: 0 auto; padding: 40px 32px 64px; }

.markdown-body {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  padding: 48px 56px;
  font-family: var(--font-sans);
  letter-spacing: 0;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 { letter-spacing: -0.018em; }

/* Мера строки: бегущий текст ограничен узкой колонкой, широкие блоки
   (таблицы, код, изображения) используют всю ширину листа */
.read-sheet .markdown-body > p,
.read-sheet .markdown-body > ul,
.read-sheet .markdown-body > ol,
.read-sheet .markdown-body > blockquote,
.read-sheet .markdown-body > h1,
.read-sheet .markdown-body > h2,
.read-sheet .markdown-body > h3,
.read-sheet .markdown-body > h4,
.read-sheet .markdown-body > h5,
.read-sheet .markdown-body > h6 { max-width: 820px; }

/* Полный набор переменных github-markdown.css под палитру feld —
   чтобы ручной тумблер темы перекрывал системную настройку */
:root[data-theme="dark"] .markdown-body {
  color-scheme: dark;
  --focus-outlineColor: var(--accent);
  --fgColor-default: #ededee;
  --fgColor-muted: #9c9ca6;
  --fgColor-accent: var(--accent);
  --fgColor-success: var(--success);
  --fgColor-attention: var(--warning);
  --fgColor-danger: var(--danger);
  --fgColor-done: #ab7df8;
  --bgColor-default: transparent;
  --bgColor-muted: #151518;
  --bgColor-neutral-muted: rgba(255, 255, 255, 0.12);
  --bgColor-attention-muted: rgba(224, 163, 62, 0.14);
  --borderColor-default: #2a2a30;
  --borderColor-muted: #232329;
  --borderColor-neutral-muted: rgba(255, 255, 255, 0.1);
  --borderColor-accent-emphasis: var(--accent);
  --borderColor-success-emphasis: var(--success);
  --borderColor-attention-emphasis: var(--warning);
  --borderColor-danger-emphasis: var(--danger);
  --borderColor-done-emphasis: #8957e5;
  --color-prettylights-syntax-comment: #9198a1;
  --color-prettylights-syntax-constant: #79c0ff;
  --color-prettylights-syntax-constant-other-reference-link: #a5d6ff;
  --color-prettylights-syntax-entity: #d2a8ff;
  --color-prettylights-syntax-storage-modifier-import: #ededee;
  --color-prettylights-syntax-entity-tag: #7ee787;
  --color-prettylights-syntax-keyword: #ff7b72;
  --color-prettylights-syntax-string: #a5d6ff;
  --color-prettylights-syntax-variable: #ffa657;
  --color-prettylights-syntax-brackethighlighter-unmatched: #f85149;
  --color-prettylights-syntax-brackethighlighter-angle: #9198a1;
  --color-prettylights-syntax-invalid-illegal-text: #f0f6fc;
  --color-prettylights-syntax-invalid-illegal-bg: #8e1519;
  --color-prettylights-syntax-carriage-return-text: #f0f6fc;
  --color-prettylights-syntax-carriage-return-bg: #b62324;
  --color-prettylights-syntax-string-regexp: #7ee787;
  --color-prettylights-syntax-markup-list: #f2cc60;
  --color-prettylights-syntax-markup-heading: var(--accent);
  --color-prettylights-syntax-markup-italic: #ededee;
  --color-prettylights-syntax-markup-bold: #ededee;
  --color-prettylights-syntax-markup-deleted-text: #ffdcd7;
  --color-prettylights-syntax-markup-deleted-bg: #67060c;
  --color-prettylights-syntax-markup-inserted-text: #aff5b4;
  --color-prettylights-syntax-markup-inserted-bg: #033a16;
  --color-prettylights-syntax-markup-changed-text: #ffdfb6;
  --color-prettylights-syntax-markup-changed-bg: #5a1e02;
  --color-prettylights-syntax-markup-ignored-text: #f0f6fc;
  --color-prettylights-syntax-markup-ignored-bg: #1158c7;
  --color-prettylights-syntax-meta-diff-range: #d2a8ff;
  --color-prettylights-syntax-sublimelinter-gutter-mark: #2a2a30;
}
:root[data-theme="light"] .markdown-body {
  color-scheme: light;
  --focus-outlineColor: var(--accent);
  --fgColor-default: #171717;
  --fgColor-muted: #63636b;
  --fgColor-accent: var(--accent);
  --fgColor-success: var(--success);
  --fgColor-attention: var(--warning);
  --fgColor-danger: var(--danger);
  --fgColor-done: #8250df;
  --bgColor-default: transparent;
  --bgColor-muted: #f6f6f7;
  --bgColor-neutral-muted: rgba(0, 0, 0, 0.05);
  --bgColor-attention-muted: rgba(150, 101, 26, 0.1);
  --borderColor-default: #e4e4e7;
  --borderColor-muted: #eaeaed;
  --borderColor-neutral-muted: rgba(0, 0, 0, 0.08);
  --borderColor-accent-emphasis: var(--accent);
  --borderColor-success-emphasis: var(--success);
  --borderColor-attention-emphasis: var(--warning);
  --borderColor-danger-emphasis: var(--danger);
  --borderColor-done-emphasis: #8250df;
  --color-prettylights-syntax-comment: #7b8295;
  --color-prettylights-syntax-constant: #0550ae;
  --color-prettylights-syntax-constant-other-reference-link: #0a3069;
  --color-prettylights-syntax-entity: #6639ba;
  --color-prettylights-syntax-storage-modifier-import: #171717;
  --color-prettylights-syntax-entity-tag: #0550ae;
  --color-prettylights-syntax-keyword: #cf222e;
  --color-prettylights-syntax-string: #0a3069;
  --color-prettylights-syntax-variable: #953800;
  --color-prettylights-syntax-brackethighlighter-unmatched: #82071e;
  --color-prettylights-syntax-brackethighlighter-angle: #7b8295;
  --color-prettylights-syntax-invalid-illegal-text: #fafafa;
  --color-prettylights-syntax-invalid-illegal-bg: #82071e;
  --color-prettylights-syntax-carriage-return-text: #fafafa;
  --color-prettylights-syntax-carriage-return-bg: #cf222e;
  --color-prettylights-syntax-string-regexp: #116329;
  --color-prettylights-syntax-markup-list: #3b2300;
  --color-prettylights-syntax-markup-heading: var(--accent);
  --color-prettylights-syntax-markup-italic: #171717;
  --color-prettylights-syntax-markup-bold: #171717;
  --color-prettylights-syntax-markup-deleted-text: #82071e;
  --color-prettylights-syntax-markup-deleted-bg: #ffebe9;
  --color-prettylights-syntax-markup-inserted-text: #116329;
  --color-prettylights-syntax-markup-inserted-bg: #dafbe1;
  --color-prettylights-syntax-markup-changed-text: #953800;
  --color-prettylights-syntax-markup-changed-bg: #ffd8b5;
  --color-prettylights-syntax-markup-ignored-text: #e4e4e7;
  --color-prettylights-syntax-markup-ignored-bg: #0550ae;
  --color-prettylights-syntax-meta-diff-range: #8250df;
  --color-prettylights-syntax-sublimelinter-gutter-mark: #e4e4e7;
}

.read-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
  color: var(--fg-faint);
  font-size: 12.5px;
}
.read-meta .sep { opacity: 0.5; }
.read-meta svg { vertical-align: -2px; }

@media (max-width: 640px) {
  .markdown-body { padding: 24px 20px; }
  .read-sheet { padding: 20px 16px 40px; }
}

/* ---------- Pygments (подсветка кода, классы вместо инлайна) ---------- */

.markdown-body pre, .codeblock pre { border-radius: 8px; }

.highlight .hll { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs, .highlight .cd { color: #7b8295; font-style: italic; }
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt, .highlight .ow { color: #cf222e; }
.highlight .s, .highlight .sa, .highlight .sb, .highlight .sc, .highlight .sd, .highlight .s2, .highlight .s1, .highlight .ss { color: #0a3069; }
.highlight .se, .highlight .si, .highlight .sr { color: #116329; }
.highlight .m, .highlight .mb, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .mo, .highlight .il { color: #0550ae; }
.highlight .nf, .highlight .fm { color: #8250df; }
.highlight .nb, .highlight .bp { color: #0550ae; }
.highlight .nc { color: #953800; }
.highlight .nd { color: #8250df; }
.highlight .na { color: #0550ae; }
.highlight .nt { color: #116329; }
.highlight .ne, .highlight .err { color: var(--danger); }
.highlight .w { color: inherit; }

:root[data-theme="dark"] .highlight .c, :root[data-theme="dark"] .highlight .c1,
:root[data-theme="dark"] .highlight .cm, :root[data-theme="dark"] .highlight .cs,
:root[data-theme="dark"] .highlight .cd { color: #9198a1; }
:root[data-theme="dark"] .highlight .k, :root[data-theme="dark"] .highlight .kc,
:root[data-theme="dark"] .highlight .kd, :root[data-theme="dark"] .highlight .kn,
:root[data-theme="dark"] .highlight .kp, :root[data-theme="dark"] .highlight .kr,
:root[data-theme="dark"] .highlight .kt, :root[data-theme="dark"] .highlight .ow { color: #ff7b72; }
:root[data-theme="dark"] .highlight .s, :root[data-theme="dark"] .highlight .sa,
:root[data-theme="dark"] .highlight .sb, :root[data-theme="dark"] .highlight .sc,
:root[data-theme="dark"] .highlight .sd, :root[data-theme="dark"] .highlight .s2,
:root[data-theme="dark"] .highlight .s1, :root[data-theme="dark"] .highlight .ss { color: #a5d6ff; }
:root[data-theme="dark"] .highlight .se, :root[data-theme="dark"] .highlight .si,
:root[data-theme="dark"] .highlight .sr { color: #7ee787; }
:root[data-theme="dark"] .highlight .m, :root[data-theme="dark"] .highlight .mb,
:root[data-theme="dark"] .highlight .mf, :root[data-theme="dark"] .highlight .mh,
:root[data-theme="dark"] .highlight .mi, :root[data-theme="dark"] .highlight .mo,
:root[data-theme="dark"] .highlight .il { color: #79c0ff; }
:root[data-theme="dark"] .highlight .nf, :root[data-theme="dark"] .highlight .fm { color: #d2a8ff; }
:root[data-theme="dark"] .highlight .nb, :root[data-theme="dark"] .highlight .bp { color: #79c0ff; }
:root[data-theme="dark"] .highlight .nc { color: #ffa657; }
:root[data-theme="dark"] .highlight .nd { color: #d2a8ff; }
:root[data-theme="dark"] .highlight .na { color: #79c0ff; }
:root[data-theme="dark"] .highlight .nt { color: #7ee787; }
:root[data-theme="dark"] .highlight .ne, :root[data-theme="dark"] .highlight .err { color: #f85149; }

/* ---------- Редактор ---------- */

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 1080px) { .editor-grid { grid-template-columns: 1fr; } }

.editor-form { display: flex; flex-direction: column; }
.editor-form .input { border: none; box-shadow: none; background: transparent; border-radius: 0; }
.editor-form .input:focus {
  box-shadow: inset 0 0 0 1px var(--border);
  background: color-mix(in srgb, var(--surface-2) 45%, transparent);
}
.editor-form input.input[name="title"] {
  height: 46px;
  padding: 0 20px;
  font-size: 15px;
  font-weight: 550;
  letter-spacing: -0.015em;
  border-bottom: 1px solid var(--border);
}
.editor-form textarea.input {
  min-height: 56vh;
  padding: 16px 20px;
}
.editor-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.save-state { font-size: 12.5px; color: var(--fg-faint); display: inline-flex; align-items: center; gap: 6px; }
.save-state .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-faint); }
.save-state.dirty { color: var(--warning); }
.save-state.dirty .dot { background: var(--warning); }

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 550;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.preview-card .markdown-body {
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 18px 20px;
  font-size: 14px;
  max-height: 58vh;
  overflow: auto;
}
.preview-card .html-preview {
  display: block;
  width: 100%;
  height: 58vh;
  border: none;
  border-radius: 0;
  background: #fff;
}
:root[data-theme="dark"] .preview-card .html-preview { background: #fff; }

.doclist { list-style: none; margin: 0; padding: 4px 6px; }
.doclist li { border-radius: 8px; }
.doclist a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--fg-muted);
  font-size: 13px;
}
.doclist a:hover { background: var(--surface-2); color: var(--fg); }
.doclist a .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doclist .badge { height: 19px; font-size: 10.5px; padding: 0 7px; }
.doclist-empty { padding: 14px 16px; }

/* ---------- Страница «документ недоступен» ---------- */

.gone-card { max-width: 420px; margin: 22vh auto 0; text-align: center; }
.gone-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: var(--fg-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.gone-code {
  font: 500 11px/1 var(--font-mono);
  letter-spacing: 0.1em;
  color: var(--fg-faint);
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* ---------- Адаптив ---------- */

@media (max-width: 720px) {
  .page { padding: 20px 16px 48px; }
  .topbar-inner { padding: 0 12px; gap: 8px; }
  .nav { margin-left: 0; }
  .user-chip .who-text { display: none; }
  .card.pad { padding: 20px; }
  .link-group { flex-direction: column; }
  .doc-filter-field { flex: 1 1 100%; }
  #doc-filter { width: 100%; }
}
