/* ==========================================================================
   base.css — сброс, типографика, каркас, утилиты.
   Зависит только от tokens.css.
   ========================================================================== */

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

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

body {
  margin: 0;
  min-width: 320px;
  background: var(--color-bg);
  color: var(--color-text);
  font: 400 16px/25px var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  color: var(--color-brown);
  font-weight: 700;
  line-height: 1.2;
}

h1 { font-size: var(--text-h1); line-height: 40px; }
h2 { font-size: var(--text-2xl); line-height: 32px; }
h3 { font-size: 19px; line-height: 26px; }
h4 { font-size: var(--text-lg); line-height: 24px; }

p {
  margin: 0 0 16px;
}

a {
  color: var(--color-info);
  text-decoration: underline;
  text-decoration-color: rgba(13, 76, 211, 0.35);
  text-underline-offset: 2px;
}
a:hover {
  text-decoration-color: currentColor;
}

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

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

img {
  height: auto;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--color-brand-tint);
  color: var(--color-text);
}

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

/* ---------- Каркас ------------------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

@media (min-width: 1024px) {
  .container {
    padding-inline: 24px;
  }
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.main {
  min-width: 0;
  padding: 24px 0 48px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.page-title {
  margin: 0 0 4px;
  font-size: var(--text-h1);
  line-height: 40px;
  color: var(--color-brown);
}

.page-subtitle {
  margin: 0;
  font-size: var(--text-base);
  line-height: 25px;
  color: var(--color-text-secondary);
}

.page-actions {
  display: flex;
  flex-shrink: 0;
  gap: 12px;
}

.section-title {
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-line);
  font-size: var(--text-2xl);
  line-height: 32px;
  color: var(--color-brown);
}

.section-title--flush {
  padding-bottom: 0;
  border-bottom: 0;
}

/* ---------- Утилиты ------------------------------------------------------ */

.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;
}

.skip-link {
  position: absolute;
  left: -9999px;
  z-index: 999;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus {
  left: 16px;
  top: 8px;
}

.stack > * + * {
  margin-top: var(--space-4);
}
.stack--5 > * + * { margin-top: var(--space-5); }
.stack--6 > * + * { margin-top: var(--space-6); }

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

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

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

.text-muted { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.text-brand { color: var(--color-brand); }
.text-danger { color: var(--color-danger); }
.text-center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.mt-0 { margin-top: 0 !important; }
.mt-2 { margin-top: var(--space-2) !important; }
.mt-3 { margin-top: var(--space-3) !important; }
.mt-4 { margin-top: var(--space-4) !important; }
.mt-5 { margin-top: var(--space-5) !important; }
.mt-6 { margin-top: var(--space-6) !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--space-2) !important; }
.mb-4 { margin-bottom: var(--space-4) !important; }
.mb-5 { margin-bottom: var(--space-5) !important; }

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

/* ---------- Иконки ------------------------------------------------------- */

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
}
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 24px; height: 24px; }

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

@media (max-width: 959px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .page-head {
    flex-direction: column;
  }
  .page-actions {
    width: 100%;
  }
  .grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 639px) {
  .grid--2,
  .grid--3,
  .grid--4 {
    grid-template-columns: 1fr;
  }
  .page-actions > .btn {
    flex: 1;
  }
}

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