:root {
  --bg: #ffffff;
  --bg-soft: #f4f4f4;
  --fg: #111111;
  --muted: #5c5c5c;
  --line: #d9d9d9;
  --inv-bg: #111111;
  --inv-fg: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .06);
}

:root[data-theme="dark"] {
  --bg: #0b0b0b;
  --bg-soft: #161616;
  --fg: #f2f2f2;
  --muted: #a3a3a3;
  --line: #2c2c2c;
  --inv-bg: #f2f2f2;
  --inv-fg: #0b0b0b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 84px; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  transition: background .25s, color .25s;
}

a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.7rem, 3.5vw, 2.4rem); }
h2 { font-size: 1.6rem; display: flex; align-items: center; gap: 10px; }

.container { width: min(1040px, 100% - 40px); margin-inline: auto; }

.icon { width: 20px; height: 20px; flex: none; vertical-align: middle; }
.icon--lg { width: 30px; height: 30px; }

/* ---------- Шапка ---------- */
/* Полоса занимает фиксированные 68px, поэтому при сворачивании содержимое страницы не «прыгает» */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 68px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.topbar::before {                       /* обычное состояние: панель на всю ширину */
  content: ""; position: absolute; inset: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  transition: opacity .3s;
}
.topbar__inner {
  position: relative; pointer-events: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: min(1040px, 100% - 40px); height: 68px; padding: 0;
  border: 1px solid transparent; border-radius: 999px;
  transition: width .35s cubic-bezier(.4, 0, .2, 1), height .35s, padding .35s,
              background .3s, border-color .3s, box-shadow .3s;
}
.brand {
  display: flex; align-items: center;
  font-weight: 700; font-size: 1.25rem; text-decoration: none; white-space: nowrap;
}
.brand__text, .nav__label {
  display: inline-block; overflow: hidden; white-space: nowrap; vertical-align: middle;
  transition: max-width .35s, padding .35s, opacity .25s;
}
.brand__text { max-width: 260px; padding-left: 10px; }
.nav__label { max-width: 160px; padding-left: 8px; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav__link {
  display: inline-flex; align-items: center;
  padding: 8px 14px; border-radius: 999px;
  text-decoration: none; font-weight: 500;
  transition: background .2s, color .2s, padding .35s;
}
.nav__link:hover { background: var(--bg-soft); }
.nav__link.is-active { background: var(--inv-bg); color: var(--inv-fg); }

/* Свёрнутая шапка — маленький «островок» по центру */
.topbar.is-compact::before { opacity: 0; }
.topbar.is-compact .topbar__inner {
  width: 204px; height: 56px; padding: 0 8px 0 14px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-color: var(--line); box-shadow: var(--shadow);
}
.topbar.is-compact .brand__text,
.topbar.is-compact .nav__label { max-width: 0; padding-left: 0; opacity: 0; }
.topbar.is-compact .nav__link { padding: 10px; }

/* На компьютере островок раскрывается при наведении мыши или фокусе с клавиатуры */
@media (hover: hover) and (pointer: fine) {
  .topbar.is-compact .topbar__inner:hover,
  .topbar.is-compact .topbar__inner:has(:focus-visible) { width: min(760px, 100% - 24px); padding: 0 12px 0 18px; }
  .topbar.is-compact .topbar__inner:hover .brand__text,
  .topbar.is-compact .topbar__inner:has(:focus-visible) .brand__text { max-width: 260px; padding-left: 10px; opacity: 1; }
  .topbar.is-compact .topbar__inner:hover .nav__label,
  .topbar.is-compact .topbar__inner:has(:focus-visible) .nav__label { max-width: 160px; padding-left: 8px; opacity: 1; }
  .topbar.is-compact .topbar__inner:hover .nav__link,
  .topbar.is-compact .topbar__inner:has(:focus-visible) .nav__link { padding: 8px 14px; }
}

.theme-toggle {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; margin-left: 6px;
  border: 1px solid var(--line); border-radius: 50%;
  background: transparent; color: var(--fg); cursor: pointer;
  transition: background .2s;
}
.theme-toggle:hover { background: var(--bg-soft); }
.icon--moon { display: none; }
:root[data-theme="dark"] .icon--sun { display: none; }
:root[data-theme="dark"] .icon--moon { display: inline-block; }

/* ---------- Основное ---------- */
.main { flex: 1; padding-block: 40px 56px; display: flex; flex-direction: column; gap: 48px; }

.hero {
  display: grid; grid-template-columns: 1.1fr .9fr; align-items: center; gap: 32px;
  padding: 40px; border: 1px solid var(--line); border-radius: calc(var(--radius) * 1.5);
  background: var(--bg-soft);
}
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); margin-bottom: 16px; }
.eyebrow { margin: 0 0 8px; text-transform: uppercase; letter-spacing: .12em; font-size: .8rem; color: var(--muted); }
.hero__lead { margin: 0 0 24px; color: var(--muted); max-width: 46ch; }
.hero__aside { min-width: 0; }
.hero__aside .eyebrow { margin-bottom: 12px; }
.hero__decode { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.decode__row {
  display: flex; align-items: center; gap: 16px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
.decode__letter {
  flex: none; width: 46px; height: 46px; display: grid; place-items: center;
  border-radius: 12px; background: var(--inv-bg); color: var(--inv-fg);
  font-size: 1.5rem; font-weight: 800; line-height: 1;
}
.decode__word { min-width: 0; font-size: 1.15rem; overflow-wrap: anywhere; }
.decode__word b { font-weight: 800; }

.section { display: flex; flex-direction: column; gap: 24px; }
.section__head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.news-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 24px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); transition: transform .2s, box-shadow .2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card, .article, .hero > *, .section { min-width: 0; }

/* Перенос длинного текста и ссылок внутри блоков */
.card__title, .card__text, .article h1, .article__body, .table td {
  overflow-wrap: anywhere; word-break: normal; hyphens: auto; -webkit-hyphens: auto;
}
.card__meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
.card__title { font-size: 1.3rem; }
.card__title a { text-decoration: none; }
.card__title a:hover { text-decoration: underline; }
.card__text { margin: 0; color: var(--muted); flex: 1; }
.more { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-decoration: none; }
.more:hover { text-decoration: underline; }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; }
.pager__info { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.article { max-width: 760px; margin-inline: auto; width: 100%; display: flex; flex-direction: column; gap: 16px; }
.article__body p { margin: 0 0 1em; }
.muted { color: var(--muted); font-size: .9rem; margin-left: 8px; }

/* ---------- Изображения ---------- */
.card__cover {
  position: relative; display: block; overflow: hidden;
  margin: -24px -24px 6px; aspect-ratio: 16 / 9;
  border-radius: var(--radius) var(--radius) 0 0; background: var(--bg-soft);
}
.card__cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.card:hover .card__cover img { transform: scale(1.03); }
.card__badge {
  position: absolute; right: 10px; bottom: 10px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  background: var(--inv-bg); color: var(--inv-fg);
}
.card__badge .icon { width: 16px; height: 16px; }

.gallery { display: grid; gap: 12px; margin-top: 8px; }
.gallery--many { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
img { max-width: 100%; }
.gallery__item {
  display: block; width: 100%; -webkit-tap-highlight-color: transparent;
  padding: 0; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: var(--bg-soft); cursor: zoom-in; line-height: 0;
}
.gallery--many .gallery__item { aspect-ratio: 4 / 3; }
.gallery__item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .2s; }
.gallery--one .gallery__item img { height: auto; max-height: 560px; object-fit: contain; }
.gallery__item:hover img { opacity: .9; }

.lightbox {
  width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: rgba(0, 0, 0, .97); color: #fff; overflow: hidden;
}
.lightbox[open] { display: grid; place-items: center; }
.lightbox::backdrop { background: rgba(0, 0, 0, .97); }
.lightbox__img { max-width: 92vw; max-height: 88vh; max-height: 88dvh; object-fit: contain; }
.lightbox__close, .lightbox__nav {
  position: absolute; border: 0; background: rgba(255, 255, 255, .14); color: #fff;
  width: 46px; height: 46px; border-radius: 50%; font-size: 1.8rem; line-height: 1; cursor: pointer;
}
.lightbox__close { top: 16px; right: 16px; }
.lightbox__nav { top: 50%; transform: translateY(-50%); }
.lightbox__nav--prev { left: 16px; }
.lightbox__nav--next { right: 16px; }
.lightbox__close:hover, .lightbox__nav:hover { background: rgba(255, 255, 255, .28); }

/* Загрузка в админке */
.uploader { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0; display: flex; flex-direction: column; gap: 14px; }
.uploader legend { padding: 0 8px; font-weight: 600; }
.uploader__hint { margin: 0; color: var(--muted); font-size: .95rem; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 28px 16px; text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--bg-soft);
  transition: border-color .2s;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--fg); }
.dropzone__title { font-weight: 700; font-size: 1.1rem; }
.dropzone small { color: var(--muted); font-weight: 400; max-width: 46ch; line-height: 1.5; }
/* Кнопка выбора файлов: настоящее поле скрыто, вместо него — обычная кнопка сайта */
.dropzone .btn { display: inline-flex; flex-direction: row; align-items: center; justify-content: center; gap: 8px; margin-top: 6px; font-weight: 600; white-space: nowrap; cursor: pointer; user-select: none; }
.dropzone:focus-within .btn { outline: 2px solid var(--fg); outline-offset: 3px; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip-path: inset(50%); pointer-events: none; }
.uploader__status { margin: 0; min-height: 1.4em; color: var(--muted); font-size: .92rem; }
.uploader__status:empty { display: none; }
.uploader__status.has-warning { color: var(--fg); font-weight: 600; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.thumbs:empty { display: none; }
.thumb { display: flex !important; flex-direction: column; gap: 6px; min-width: 0; font-weight: 400 !important; font-size: .9rem; }
.thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border: 1px solid var(--line); border-radius: 10px; }
/* Уже загруженные фото: «Удалить» — стилизованный переключатель вместо стандартного чекбокса */
.thumb--old { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.thumb--old .chk { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.thumb--old img { transition: opacity .2s, filter .2s; }
.thumb__del {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); font-size: .85rem; font-weight: 600; line-height: 1.2;
  transition: background .2s, color .2s, border-color .2s;
}
.thumb__del .icon { width: 16px; height: 16px; }
.thumb__del .when-on { display: none; }
.thumb--old:hover .thumb__del { background: var(--bg-soft); }
.thumb--old .chk:checked ~ img { opacity: .35; filter: grayscale(1); }
.thumb--old .chk:checked ~ .thumb__del { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); }
.thumb--old .chk:checked ~ .thumb__del .when-off { display: none; }
.thumb--old .chk:checked ~ .thumb__del .when-on { display: inline; }
.thumb--old .chk:focus-visible ~ .thumb__del { outline: 2px solid var(--fg); outline-offset: 2px; }
.thumb--new { position: relative; }
.thumb__remove {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--inv-bg); color: var(--inv-fg); font-size: 1.3rem; line-height: 1; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.thumb__remove:hover { opacity: .85; }
.thumb__name { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Кнопки и формы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 999px;
  border: 1px solid var(--inv-bg); background: var(--inv-bg); color: var(--inv-fg);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: opacity .2s, background .2s, color .2s;
}
.btn:hover { opacity: .85; }
.btn--ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn--ghost:hover { background: var(--bg-soft); opacity: 1; }
.btn--sm { padding: 6px 12px; font-size: .9rem; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); padding: 28px; }
.form { display: flex; flex-direction: column; gap: 18px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.form small { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=datetime-local], textarea {
  width: 100%; padding: 12px 14px; font: inherit; font-weight: 400;
  color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, textarea:focus { outline: 2px solid var(--fg); outline-offset: 1px; }
textarea { resize: vertical; }

.auth { display: grid; place-items: center; }
.auth .panel { width: min(440px, 100%); }
.auth h1 { display: flex; align-items: center; gap: 10px; font-size: 1.5rem; }
.error { text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.error__code { font-size: 4rem; font-weight: 800; margin: 0; line-height: 1; }

.flash { padding: 12px 18px; border-radius: 10px; border: 1px solid var(--fg); transition: opacity .4s; }
.flash--error { background: var(--inv-bg); color: var(--inv-fg); }
.flash.is-hidden { opacity: 0; }

/* ---------- Таблица ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 14px 18px; text-align: left; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table th { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.table a { text-decoration: none; font-weight: 600; }
.table a:hover { text-decoration: underline; }
.nowrap { white-space: nowrap; }
.td-actions { display: flex; gap: 8px; justify-content: flex-end; }
.td-actions form { margin: 0; }
.th-actions { text-align: right !important; }

/* ---------- Подвал ---------- */
.footer { border-top: 1px solid var(--line); background: var(--bg-soft); color: var(--muted); font-size: .95rem; }
.footer__grid { display: grid; grid-template-columns: 1.2fr .8fr 1.4fr; gap: 40px; padding-block: 44px 36px; }
.footer__col { display: flex; flex-direction: column; gap: 12px; }
.footer__col p { margin: 0; }
.footer__col h4 { margin: 0; color: var(--fg); font-size: 1rem; text-transform: uppercase; letter-spacing: .08em; }
.footer__brand { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); font-weight: 700; font-size: 1.2rem; }
.footer__copy { font-size: .9rem; }
.footer__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.footer__list a { text-decoration: none; color: var(--fg); }
.footer__list a:hover { text-decoration: underline; }
.footer__list--icons li { display: flex; align-items: flex-start; gap: 10px; }
.footer__list--icons .icon { margin-top: 3px; color: var(--fg); }

/* ---------- Адаптив ---------- */
/* Нечётная последняя новость (без пары) занимает всю ширину */
@media (min-width: 821px) {
  .news-list .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .news-list .card:last-child:nth-child(odd):has(.card__cover) {
    display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    column-gap: 28px; align-content: center; align-items: start;
  }
  .news-list .card:last-child:nth-child(odd):has(.card__cover) > * { grid-column: 2; }
  .news-list .card:last-child:nth-child(odd):has(.card__cover) > .card__cover {
    grid-column: 1; grid-row: 1 / span 4; align-self: stretch;
    margin: -24px 0 -24px -24px; min-height: 260px; aspect-ratio: auto;
    border-radius: var(--radius) 0 0 var(--radius);
  }
  .news-list .card:last-child:nth-child(odd):has(.card__cover) > .card__cover img { position: absolute; inset: 0; }
  .news-list .card:last-child:nth-child(odd) .card__title { font-size: 1.5rem; }
}

@media (max-width: 820px) {
  .gallery--many { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .footer__grid { grid-template-columns: 1fr 1fr; gap: 28px; }
  .footer__col:first-child { grid-column: 1 / -1; }
  .hero { grid-template-columns: 1fr; padding: 28px; }
  .news-list { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .footer__grid { grid-template-columns: 1fr; }
  /* Изображения на телефонах */
  .card { padding: 18px; }
  .card__cover { margin: -18px -18px 4px; aspect-ratio: 4 / 3; }
  .gallery { gap: 8px; }
  .gallery--many { grid-template-columns: repeat(2, 1fr); }
  .gallery--one .gallery__item img { max-height: 70vh; }
  .lightbox__img { max-width: 100vw; max-height: 76vh; max-height: 76dvh; }
  .lightbox__close { top: 12px; right: 12px; }
  .lightbox__nav { top: auto; bottom: 22px; transform: none; }
  .lightbox__nav--prev { left: calc(50% - 62px); }
  .lightbox__nav--next { right: calc(50% - 62px); }
  .panel { padding: 18px; }
  .uploader { padding: 14px; }
  .dropzone { padding: 20px 12px; }
  .dropzone .btn { width: 100%; padding: 14px 20px; }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .nav__label { display: none; }
  .nav__link { padding: 10px; }
  .brand { font-size: 1.1rem; }
  .main { padding-block: 24px 40px; gap: 32px; }
  .hero { padding: 22px; gap: 24px; }
  .decode__row { padding: 8px 12px; gap: 14px; }
  .table th:first-child, .table td:first-child { display: none; }
  .td-actions .btn { padding: 6px 10px; }
}

/* Совсем узкие экраны (до 380 px) */
@media (max-width: 380px) {
  .container, .topbar__inner { width: calc(100% - 28px); }
  .brand { font-size: 1rem; }
  .theme-toggle { width: 38px; height: 38px; margin-left: 2px; }
  .hero { padding: 18px; }
  .hero h1 { font-size: 2rem; }
  .decode__letter { width: 40px; height: 40px; font-size: 1.3rem; }
  .decode__word { font-size: 1rem; }
  .section__head h2 { font-size: 1.35rem; }
  .card__title { font-size: 1.15rem; }
  .td-actions { flex-direction: column; align-items: stretch; }
}
