/* База: сброс, типографика, каркас страницы. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  transition: background var(--duration) var(--easing), color var(--duration) var(--easing);
}

h1,
h2,
h3,
h4,
p,
figure {
  margin: 0;
}

a {
  color: var(--color-primary);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--color-primary-hover);
}

img,
svg {
  display: block;
  max-width: 100%;
}

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

/* Типографика */

.title-1 {
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.title-2 {
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.title-3 {
  font-size: var(--text-lg);
  line-height: var(--leading-tight);
  font-weight: 600;
}

.title-4 {
  font-size: var(--text-md);
  line-height: var(--leading-tight);
  font-weight: 600;
}

.subtitle {
  font-size: var(--text-md);
  color: var(--color-text-muted);
  font-weight: 500;
}

.eyebrow {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.text {
  font-size: var(--text-md);
}

.text-sm {
  font-size: var(--text-sm);
}

.text-xs {
  font-size: var(--text-xs);
}

.muted {
  color: var(--color-text-muted);
}

.mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* Каркас */

/* Каркас: слева навигация, справа содержимое. */
.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  height: 100vh;
  padding: var(--space-4);
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text);
  font-weight: 700;
  text-decoration: none;
}

.sidebar__mark {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  display: grid;
  place-items: center;
  font-size: var(--text-xs);
  font-weight: 700;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  overflow-y: auto;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group__label {
  margin: 0 0 var(--space-1) 10px;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px 10px;
  border-left: 2px solid transparent;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-decoration: none;
}

.sidebar__link:hover {
  background: var(--color-surface-raised);
  color: var(--color-text);
}

.sidebar__link--active {
  border-left-color: var(--color-primary);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-weight: 500;
}

.sidebar__count {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.sidebar__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.content {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-8);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.page-head__meta {
  margin-top: var(--space-2);
}

/* Заголовок страницы: дата, название и подпись не слипаются. */
.page-head .eyebrow {
  margin-bottom: var(--space-2);
}

.page-head .title-1 {
  margin-bottom: var(--space-1);
}

.columns {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
}

/* Длинные строки и таблицы не должны растягивать страницу. */
.content,
.columns,
.columns > *,
.stack,
.card,
.agenda,
.calendar,
.table-wrap {
  min-width: 0;
}

@media (max-width: 920px) {
  .columns {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar__nav {
    margin-left: 0;
    order: 3;
    width: 100%;
    overflow-x: auto;
  }
}

/* Утилиты раскладки */

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.row--spaced {
  margin-top: var(--space-4);
}

.row--between {
  justify-content: space-between;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack--sm {
  gap: var(--space-3);
}

.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.divider {
  height: 1px;
  border: 0;
  margin: var(--space-5) 0;
  background: var(--color-border);
}

.columns + .section {
  margin-top: var(--space-7);
}

/* Вход */

.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--space-5);
}

.auth__card {
  width: min(380px, 100%);
  padding: var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-md);
}

.auth__title {
  margin-bottom: var(--space-1);
}

.auth__lead {
  margin-bottom: var(--space-5);
}

/* Витрина */

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-8);
}

.page__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-6);
}

.page__lead {
  margin-top: var(--space-2);
}

.section {
  margin-bottom: var(--space-7);
}

.section__title {
  margin-bottom: var(--space-2);
}

/* Заголовок секции с подписью справа. */
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.section__hint {
  margin-bottom: var(--space-4);
}

/* ---------- Адаптив ---------- */
/* Точки перелома: 640 — мобильный, 1024 — планшет; выше — ПК. */

/* Планшет: навигация уезжает наверх горизонтальной лентой. */
@media (max-width: 1023px) {
  .shell {
    display: block;
  }

  .sidebar {
    position: static;
    display: block;
    height: auto;
    padding: var(--space-3) var(--space-4);
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
  }

  .sidebar__brand {
    margin-bottom: var(--space-3);
  }

  .sidebar__nav {
    display: flex;
    flex-direction: row;
    gap: var(--space-2);
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .sidebar__nav::-webkit-scrollbar {
    display: none;
  }

  .nav-group {
    display: contents;
  }


  .nav-group__label {
    display: none;
  }

  .sidebar__link {
    white-space: nowrap;
  }

  .sidebar__footer {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
  }

  .content {
    padding: var(--space-5) var(--space-4) var(--space-7);
  }
}

@media (max-width: 639px) {
  .theme-toggle {
    padding: 6px var(--space-2);
  }

  .content {
    padding: var(--space-4) var(--space-3) var(--space-6);
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  .page-head .row,
  .row--between {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .page-head .row .btn,
  .row--between .btn {
    width: 100%;
  }

  .btn {
    min-height: 40px;
  }

  .page {
    padding: var(--space-4) var(--space-3) var(--space-6);
  }

  .page__header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 479px) {
  .topbar__actions .chip {
    display: none;
  }
}

.cards-2 {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cards-2 + .section {
  margin-top: var(--space-7);
}

@media (max-width: 767px) {
  .cards-2 {
    grid-template-columns: 1fr;
  }
}

/* ---------- Навигация сверху ---------- */

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  height: auto;
  padding: var(--space-2) var(--space-5);
  border-right: 0;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.sidebar__nav {
  flex: 1;
  flex-direction: row;
  align-items: center;
  gap: var(--space-4);
  overflow-x: auto;
  overflow-y: visible;
}

.nav-group {
  flex-direction: row;
  align-items: center;
  gap: var(--space-1);
}

.nav-group__label {
  display: none;
}

.sidebar__link {
  padding: 6px 10px;
  border-left: 0;
  border-bottom: 2px solid transparent;
  /* Верхнее меню — прямоугольные пункты, без скруглений. */
  border-radius: 0;
  white-space: nowrap;
}

.sidebar__link--active {
  border-left-color: transparent;
  border-bottom-color: var(--color-primary);
}

.sidebar__footer {
  margin-top: 0;
  margin-left: auto;
  padding-top: 0;
  border-top: 0;
  justify-content: flex-end;
}

@media (max-width: 900px) {
  .sidebar {
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-3);
  }

  .sidebar__nav {
    order: 3;
    flex-basis: 100%;
    width: 100%;
  }
}

[hidden] { display: none !important; }
