/* ==========================================================================
   Базовые стили, каркас страницы, шапка
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
}

body:has(dialog[open]) { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: var(--fw-bold); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
dl, dd { margin: 0; }
table { border-collapse: collapse; width: 100%; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--c-blue); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--c-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Программный фокус на контейнерах и диалогах не рисует рамку */
dialog:focus-visible, [tabindex="-1"]:focus-visible { outline: none; }

/* Быстрые нажатия без задержки двойного тапа */
a, button, input, select, textarea, summary, label, [role="button"], [role="tab"], .btn, .chip { touch-action: manipulation; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -4rem;
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--c-surface);
  color: var(--c-text);
  border: 2px solid var(--c-focus);
  border-radius: var(--radius-md);
  font-weight: 600;
}
.skip-link:focus { top: var(--space-3); }

/* --- Каркас --- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
main.container { padding-block: var(--space-4) var(--space-7); outline: none; }

.stack { display: grid; gap: var(--space-4); }
.stack > * { min-width: 0; }
.stack--sm { gap: var(--space-2); }
.stack--lg { gap: var(--space-5); }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--c-text-muted); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.break { overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* --- Шапка --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.app-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--header-h);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--c-text);
  font-weight: 750;
  font-size: var(--fs-lg);
  letter-spacing: -0.01em;
  text-decoration: none;
  min-height: var(--tap);
}
.brand__mark {
  display: grid;
  place-items: center;
  width: 2rem; height: 2rem;
  border-radius: var(--radius-md);
  background: var(--c-accent);
  color: var(--c-on-accent);
}
.brand__mark svg { width: 1.2rem; height: 1.2rem; }

.app-nav { display: flex; gap: var(--space-1); margin-left: var(--space-3); }
.app-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding-inline: var(--space-3);
  border-radius: var(--radius-md);
  color: var(--c-text-muted);
  font-weight: 600;
  text-decoration: none;
}
.app-nav a:hover { background: var(--c-surface-2); color: var(--c-text); }
.app-nav a[aria-current="page"] { color: var(--c-text); background: var(--c-accent-soft); }

.app-user { display: none; text-align: right; line-height: 1.2; margin-right: var(--space-1); }
.app-user__name { font-weight: 600; font-size: var(--fs-sm); max-width: 12rem; }
.app-user__role { font-size: var(--fs-xs); color: var(--c-text-muted); }
@media (min-width: 720px) { .app-user { display: block; } }

/* Мобильная навигация под шапкой */
.app-nav--mobile {
  margin-left: 0;
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  padding-bottom: var(--space-2);
}
@media (min-width: 720px) { .app-nav--mobile { display: none; } }
.app-nav:not(.app-nav--mobile) { display: none; }
@media (min-width: 720px) { .app-nav:not(.app-nav--mobile) { display: flex; } }

/* --- Заголовок страницы --- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.page-head h1 { font-size: var(--fs-xl); }
@media (min-width: 720px) { .page-head h1 { font-size: var(--fs-2xl); } }

/* --- Режим пониженной анимации --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Печать --- */
@media print {
  .app-header, .toasts, .btn { display: none !important; }
}
