/*
 * style.css — оформление сайта. Цвета берутся только из токенов (tokens.css),
 * ни одного захардкоженного цвета — иначе тёмная тема поедет.
 *
 * Шрифты системные, без Google Fonts: внешние CDN из РФ грузятся нестабильно
 * (та же причина, по которой пришлось повозиться с Let's Encrypt), а ждать
 * шрифт ради заголовков — плохой размен.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  background: var(--bg);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: Georgia, 'Times New Roman', 'Droid Serif', serif;
  font-weight: 400;
  color: var(--text-main);
  text-wrap: balance;
}

h1 { font-size: var(--fs-h1); line-height: var(--lh-h1); }
h2 { font-size: var(--fs-h2); line-height: var(--lh-h2); }
h3 { font-size: var(--fs-h3); line-height: var(--lh-h3); }

p { text-wrap: pretty; }

a {
  color: var(--primary);
  text-decoration: none;
  touch-action: manipulation;
}
a:hover { text-decoration: underline; }

:focus-visible {
  outline: var(--focus-ring-width) solid var(--primary);
  outline-offset: var(--focus-ring-offset);
  border-radius: 2px;
}

img { max-width: 100%; height: auto; }

/* ── Раскладка ── */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--container-px);
}

main.container {
  flex: 1;
  padding-block: var(--section-py);
}

.stack > * + * { margin-top: var(--gap); }

/* ── Шапка ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 60px;
}

.brand {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin-right: auto;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--primary); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
}

.nav-links a {
  display: block;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--fs-ui);
  white-space: nowrap;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-links a:hover {
  background: var(--primary-soft);
  color: var(--primary);
  text-decoration: none;
}
.nav-links a[aria-current='page'] {
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 600;
}

/* Кнопки-иконки в шапке (тема, бургер) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-target);
  height: var(--tap-target);
  flex: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }
/* flex: none обязательно — иначе SVG без атрибутов width/height сжимается
   flex-контейнером кнопки до нулевой ширины и иконка просто исчезает. */
.icon-btn svg { width: 20px; height: 20px; flex: none; }
/* Явно, потому что UA-правило [hidden]{display:none} на SVG в flex-контейнере
   не срабатывает — элемент блокифицируется как flex-item. */
.icon-btn svg[hidden] { display: none; }

.nav-toggle { display: none; }

/* ── Подвал ── */
.site-footer {
  background: var(--surface-alt);
  border-top: 1px solid var(--border);
  padding-block: 1.25rem;
  color: var(--text-light);
  font-size: var(--fs-sub);
}
.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: center;
  justify-content: space-between;
}

/* ── Карточки ── */
.card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 2.5vw, 1.5rem);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--gap); }

.card-grid {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
}

/* ── Профиль ── */
.profile {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: clamp(1rem, 3vw, 2rem);
  align-items: start;
}
.profile-photo {
  width: clamp(120px, 20vw, 180px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.profile h1 { margin-bottom: 0.5rem; }

.positions { list-style: none; }
.positions li {
  position: relative;
  padding-left: 1rem;
  color: var(--text-main);
  font-weight: 600;
  line-height: 1.45;
}
.positions li + li { margin-top: 0.3rem; }
.positions li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
}

.meta-line { color: var(--text-muted); font-size: var(--fs-ui); }
.muted { color: var(--text-light); }

/* ── Таблицы: на узких экранах скроллятся, страница — нет ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--fs-ui);
}
th, td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--surface);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--primary-soft); }

/* ── Публикации ── */
.pub-list { list-style: none; }
.pub-item {
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.25rem 1rem;
}
.pub-item:last-child { border-bottom: none; }
.pub-year {
  font-variant-numeric: tabular-nums;
  color: var(--text-light);
  font-size: var(--fs-sub);
  padding-top: 0.15rem;
}
.pub-title { font-weight: 600; line-height: 1.4; }
.pub-meta {
  grid-column: 2;
  color: var(--text-muted);
  font-size: var(--fs-sub);
  line-height: var(--lh-sub);
}

/* Список, уже сгруппированный по годам: колонка года не нужна — год стоит
   в заголовке группы, дублировать его в каждой строке незачем. */
.pub-list-grouped .pub-item { grid-template-columns: 1fr; }
.pub-list-grouped .pub-meta { grid-column: 1; }

/* ── Расписание ── */
.schedule-table td { min-width: 8.5rem; }
.schedule-slot { font-weight: 600; white-space: nowrap; }
.schedule-time {
  display: block;
  font-weight: 400;
  color: var(--text-light);
  font-size: var(--fs-sub);
  font-variant-numeric: tabular-nums;
}
.lesson-title { font-weight: 600; line-height: 1.35; }
.lesson-type {
  display: inline-block;
  margin-top: 0.2rem;
  font-size: var(--fs-sub);
  color: var(--text-muted);
}

/* Мобильный вариант расписания — карточки по дням */
.schedule-cards { display: none; }
.day-card + .day-card { margin-top: var(--gap); }
.day-card h3 {
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.day-lesson { display: flex; gap: 0.75rem; }
.day-lesson + .day-lesson {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}
.day-lesson-time {
  flex: none;
  width: 5.5rem;
  color: var(--text-light);
  font-size: var(--fs-sub);
  font-variant-numeric: tabular-nums;
}

/* ── Формы ── */
label { display: block; font-weight: 600; font-size: var(--fs-ui); }
label + label, .field + .field { margin-top: 0.9rem; }

input, textarea, select {
  width: 100%;
  min-height: var(--tap-target);
  padding: 0.55rem 0.7rem;
  margin-top: 0.3rem;
  font: inherit;
  font-size: var(--fs-ui);
  color: var(--text-main);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
textarea { min-height: 6rem; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input[type='file'] { padding: 0.45rem; }
input[type='checkbox'] { width: auto; min-height: auto; }

/* ── Кнопки ── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--tap-target);
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-size: var(--fs-ui);
  font-weight: 600;
  color: var(--text-on-primary);
  background: var(--primary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s var(--ease);
}
button:hover, .btn:hover { background: var(--primary-hover); text-decoration: none; }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--primary-soft); }

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); background: var(--error); }

.btn-sm { min-height: 34px; padding: 0.3rem 0.7rem; font-size: var(--fs-sub); }

form.inline { display: inline-block; }

/* ── Сообщения ── */
.flashes { list-style: none; margin-bottom: 1rem; }
.flash {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--fs-ui);
}
.flash + .flash { margin-top: 0.5rem; }
.flash-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.flash-error { background: var(--error-bg); color: var(--error); border-color: var(--error-border); }

/* ── Мелочи ── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--fs-sub);
  font-weight: 600;
}
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-light);
}
.tag-list { display: flex; flex-wrap: wrap; gap: 0.5rem; list-style: none; }

.link-list { list-style: none; }
.link-list li + li { margin-top: 0.5rem; }
.link-list a { font-weight: 600; }

.stat-row { display: flex; flex-wrap: wrap; gap: var(--gap); }
.stat {
  flex: 1 1 120px;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: var(--fs-sub); color: var(--text-muted); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

/* Планшеты и меньше: навигация уезжает в выдвижное меню */
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; order: 3; }

  .nav-links {
    display: none;
    order: 4;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding-bottom: 0.75rem;
  }
  .nav-links.open { display: flex; }
  .nav-links a {
    padding: 0.75rem 0.7rem;
    min-height: var(--tap-target);
    display: flex;
    align-items: center;
    border-radius: var(--radius-sm);
  }
  .nav { flex-wrap: wrap; }
}

/* Телефоны */
@media (max-width: 640px) {
  .profile {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .profile .positions li { text-align: left; }
  .profile-photo { width: 140px; }

  /* Расписание: таблица прячется, показываются карточки по дням */
  .schedule-table-wrap { display: none; }
  .schedule-cards { display: block; }

  .pub-item { grid-template-columns: 1fr; }
  .pub-meta { grid-column: 1; }
  .pub-year { padding-top: 0; }

  .site-footer .container { justify-content: center; text-align: center; }

  th, td { padding: 0.5rem 0.6rem; }
}

/* Печать: только содержимое */
@media print {
  .site-header, .site-footer, .icon-btn, form { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ccc; box-shadow: none; }
}
