:root {
  --bg: #f6f6f9;
  --surface: #ffffff;
  --surface-2: #f0f0f5;
  --border: #e2e2ea;
  --text: #1b1b24;
  --muted: #676779;
  --accent: #5b5bd6;
  --accent-hover: #4a4ac4;
  --accent-soft: #ececfd;
  --accent-text: #ffffff;
  --danger: #d23b48;
  --danger-soft: #fdecee;
  --ok: #1f8a5b;
  --shadow: 0 1px 2px rgb(20 20 40 / 6%), 0 4px 16px rgb(20 20 40 / 5%);
  --radius: 12px;
  color-scheme: light;
}

/* Тёмная тема: по системе (если пользователь не выбрал светлую) или выбрана вручную в «Настройках».
   Выбор ставит theme.js как <html data-theme="light|dark">. Блоки ниже должны совпадать. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111117;
    --surface: #1a1a22;
    --surface-2: #23232d;
    --border: #2e2e3a;
    --text: #ececf2;
    --muted: #9a9aad;
    --accent: #7b7bf0;
    --accent-hover: #9090f5;
    --accent-soft: #26264a;
    --accent-text: #0f0f1a;
    --danger: #f06b75;
    --danger-soft: #3a1d22;
    --ok: #4cc38a;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111117;
  --surface: #1a1a22;
  --surface-2: #23232d;
  --border: #2e2e3a;
  --text: #ececf2;
  --muted: #9a9aad;
  --accent: #7b7bf0;
  --accent-hover: #9090f5;
  --accent-soft: #26264a;
  --accent-text: #0f0f1a;
  --danger: #f06b75;
  --danger-soft: #3a1d22;
  --ok: #4cc38a;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

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

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-block: 28px 64px; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent);
  display: grid; place-items: center;
}
.brand-mark svg { width: 20px; height: 20px; fill: none; stroke: var(--accent-text); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand-letter { color: var(--accent); }
.nav { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.nav .who { color: var(--muted); font-size: 14px; margin-right: 4px; }
.nav .who b { color: var(--text); }

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.big { height: 46px; padding: 0 22px; font-size: 16px; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
textarea { resize: vertical; min-height: 110px; }
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 5px; }

/* ---------- Каталог ---------- */
.hero { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.hero h1 { margin: 0; font-size: 28px; line-height: 1.2; }
.hero p { margin: 4px 0 0; color: var(--muted); }

.filters { display: grid; grid-template-columns: 1fr 180px 170px; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 5px 13px; font: inherit; font-size: 14px; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
  color: var(--text); transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.card-head { display: flex; gap: 12px; align-items: flex-start; }
.ext {
  flex: none; width: 46px; height: 46px; border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 11px; font-weight: 800; letter-spacing: .02em; text-transform: uppercase;
}
.card h3 { margin: 0; font-size: 16px; line-height: 1.3; word-break: break-word; }
.card .desc {
  margin: 0; color: var(--muted); font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.meta { display: flex; gap: 6px 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: auto; }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.meta svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tag {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}

.pager { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 26px; color: var(--muted); }

.empty {
  text-align: center; padding: 56px 20px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}
.empty h2 { color: var(--text); margin: 0 0 6px; font-size: 20px; }
.empty .btn { margin-top: 16px; }

/* ---------- Панели и формы ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow);
}
.narrow { max-width: 420px; margin: 24px auto 0; }
.medium { max-width: 680px; margin: 0 auto; }
.panel h1 { margin: 0 0 4px; font-size: 24px; }
.panel .sub { color: var(--muted); margin: 0 0 22px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.error {
  background: var(--danger-soft); color: var(--danger); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 16px; font-size: 14px;
}
.switch-link { text-align: center; margin: 18px 0 0; color: var(--muted); font-size: 14px; }

.drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s; background: var(--surface-2);
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop svg { width: 34px; height: 34px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.drop strong { display: block; margin-top: 6px; }
.drop .chosen { margin-top: 8px; font-weight: 600; color: var(--text); word-break: break-all; }

.progress { margin-top: 18px; }
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .2s; }
.progress-info { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }

/* ---------- Страница файла ---------- */
.back {
  display: flex; width: fit-content; align-items: center; gap: 6px;
  margin-bottom: 16px; padding: 7px 14px 7px 10px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); font-weight: 600; transition: border-color .15s, color .15s;
}
.back:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
/* выравниваем по левому краю карточки, если она узкая и по центру */
.back:has(+ .medium) { margin-left: max(0px, calc((100% - 680px) / 2)); }
.back:has(+ .narrow) { margin-left: max(0px, calc((100% - 420px) / 2)); }
.back + .narrow { margin-top: 0; }
.detail-head { display: flex; gap: 16px; align-items: flex-start; }
.detail-head .ext { width: 64px; height: 64px; font-size: 14px; border-radius: 14px; }
.detail-head h1 { margin: 0 0 6px; font-size: 26px; line-height: 1.25; word-break: break-word; }
.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 22px 0;
}
.fact { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.fact small { display: block; color: var(--muted); font-size: 12px; }
.fact b { font-weight: 600; word-break: break-all; }
.description { white-space: pre-wrap; word-break: break-word; margin: 0 0 22px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.notice { color: var(--muted); font-size: 13px; margin-top: 16px; }

/* ---------- Админка ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------- Подтверждение ---------- */
.confirm-box { margin-top: 16px; padding: 14px; border: 1px solid var(--danger); background: var(--danger-soft); border-radius: 10px; }
.confirm-box p { margin: 0 0 10px; }
.confirm-box.neutral { border-color: var(--border); background: var(--surface-2); }
.confirm-box .field { max-width: 320px; margin-bottom: 10px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- Аватарки и профиль ---------- */
.avatar { flex: none; border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; background: var(--surface-2); }
.avatar.letter { color: #fff; font-weight: 700; line-height: 1; user-select: none; }
.avatar.xs { width: 18px; height: 18px; font-size: 10px; }
.avatar.sm { width: 24px; height: 24px; font-size: 12px; }
.avatar.lg { width: 112px; height: 112px; font-size: 46px; }
.btn.account { padding-left: 8px; }
.btn.account .avatar { width: 26px; height: 26px; }

.profile { display: flex; gap: 24px; align-items: center; margin-bottom: 26px; }
.profile-avatar { flex: none; }
.profile-avatar .avatar { box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--border); }
.profile-info { min-width: 0; flex: 1; }
.profile-info h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; word-break: break-word; }
.profile-info h1 .badge { font-size: 12px; }
.profile-info .sub { margin-bottom: 12px; }
.profile-stats { display: flex; gap: 20px; flex-wrap: wrap; color: var(--muted); margin-bottom: 16px; }
.profile-stats b { color: var(--text); font-size: 18px; }
.list-title { font-size: 20px; margin: 0 0 14px; }

.fact-link { color: var(--text); border: 1px solid transparent; transition: border-color .15s; }
.fact-link:hover { text-decoration: none; border-color: var(--accent); }
.author { display: flex; align-items: center; gap: 6px; }
.user-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.user-link .avatar { width: 24px; height: 24px; font-size: 12px; }

@media (max-width: 720px) {
  .profile { flex-direction: column; text-align: center; }
  .profile-info h1, .profile-stats, .profile .actions { justify-content: center; }
}

/* ---------- Аккаунт ---------- */
.panel h2.section { font-size: 17px; margin: 0 0 14px; padding-top: 18px; border-top: 1px solid var(--border); }
.form-note { text-align: center; margin-top: 12px; }

/* Шестерёнка в шапке — только значок */
.btn.icon-btn { width: 38px; padding: 0; }
.btn.icon-btn svg { width: 19px; height: 19px; stroke-width: 2; }

/* Переключатель темы */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.seg {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px;
  border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .15s, color .15s;
}
.seg:hover { color: var(--text); }
.seg[aria-pressed="true"] { background: var(--surface); color: var(--accent); border-color: var(--border); box-shadow: var(--shadow); }
.seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-hint { margin: 8px 0 22px; }
.nav .account svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Уведомления ---------- */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(420px, calc(100% - 32px)); }
.toast {
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 14px; animation: rise .2s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.loading { color: var(--muted); padding: 40px 0; text-align: center; }

@media (max-width: 720px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  .row2 { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 24px; }
  .panel { padding: 18px; }
  .nav .who { display: none; }
}

.full { width: 100%; }
