/* Каркас: сброс, типографика, меню (ПК), верхняя строка и нижняя панель (телефон, планшет). */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-m) / var(--lh) var(--font);
  font-variant-numeric: tabular-nums;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--text);
}

h1 {
  font-size: var(--fs-xl);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h2 {
  font-size: var(--fs-h2);
  font-weight: 650;
  line-height: 1.3;
}

h3 {
  font-size: var(--fs-m);
  font-weight: 600;
}

p {
  margin: 0 0 var(--s3);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* радиус рамки фокуса — только у ссылок; поля и кнопки при фокусе сохраняют свой радиус */
:where(a, summary):focus-visible {
  border-radius: var(--r1);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.skip-link {
  position: absolute;
  left: var(--s3);
  top: -100px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--s4);
  background: var(--card);
  border-radius: var(--r2);
}

.skip-link:focus {
  top: var(--s3);
}

/* иконки из спрайта */
.ico {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.base-svgs {
  display: none;
}

/* ---------- оболочка ---------- */

.app {
  min-height: 100vh;
}

.side {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: 52px;
  padding: 0 var(--s4);
  background: var(--card);
  color: var(--text);
  border-bottom: 1px solid var(--line);
}

.topbar .brand {
  margin-right: auto;
}

.topbar-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  margin-left: calc(var(--s2) * -1);
  color: inherit;
  border-radius: var(--r2);
}

.topbar-back.is-on {
  display: inline-flex;
}

.topbar-back:hover {
  text-decoration: none;
  background: var(--sub);
}

.topbar-title {
  margin: 0;
  font-size: var(--fs-l);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.03em;
}

.brand:hover {
  text-decoration: none;
}

.logo {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: var(--logo);
  color: var(--accent-fg);
  border-radius: var(--r2);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.main {
  min-width: 0;
}

.content {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--s4) var(--s4) var(--s6);
  outline: none;
}

/* разделы текущего модуля под шапкой (телефон и узкое окно; на ПК — боковое меню) */
.subnav {
  position: sticky;
  top: 52px;
  z-index: 19;
  display: flex;
  gap: var(--s1);
  overflow-x: auto;
  padding: 0 var(--s3);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

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

.subnav a {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--s2);
  border-bottom: 2px solid transparent;
  color: var(--text2);
  font-size: var(--fs-m);
  white-space: nowrap;
}

.subnav a:hover {
  color: var(--text);
  text-decoration: none;
}

.subnav a.is-current {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

.subnav a:focus-visible {
  outline: none;
  box-shadow: inset var(--focus);
}

/* на экране одного объекта есть стрелка «назад» — вкладки модуля не нужны */
.change-form .subnav,
.delete-confirmation .subnav,
.delete-selected-confirmation .subnav,
.results-page .subnav {
  display: none;
}

/* нижняя панель */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);  /* «Обзор», модули, «Ещё» — сколько есть */
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: var(--s1) var(--s1);
  border: 0;
  background: none;
  color: var(--text2);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.tab:hover {
  text-decoration: none;
  color: var(--text);
}

.tab.is-current {
  color: var(--accent);
  font-weight: 500;
}

.app {
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

/* лист «Ещё» */
.sheet {
  width: 100%;
  max-width: none;
  margin: auto 0 0;
  padding: var(--s2) var(--s4) calc(var(--s4) + env(safe-area-inset-bottom));
  border: 0;
  border-radius: var(--r4) var(--r4) 0 0;
  background: var(--card);
  color: var(--text);
}

.sheet::backdrop {
  background: var(--scrim);
}

.sheet-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--tap);
}

.sheet-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sheet-link,
.sheet-list button {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--s2);
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sheet-link:hover {
  text-decoration: none;
  background: var(--sub);
}

.sheet-group {
  padding: var(--s3) var(--s2) var(--s1);
  color: var(--text2);
  font-size: var(--fs-xs);
  font-weight: 500;
}

.sheet-link[aria-current="page"] {
  color: var(--accent);
  font-weight: 500;
}

.sheet-who {
  margin: 0;
  color: var(--text2);
  font-size: var(--fs-s);
}

/* служебная информация */
.foot {
  margin-top: var(--s6);
  color: var(--text2);
  font-size: var(--fs-xs);
}

/* ---------- ПК: светлое боковое меню, ширина зависит от экрана ---------- */

@media (min-width: 1024px) {
  .app {
    display: grid;
    grid-template-columns: var(--side-w, 184px) minmax(0, 1fr);
    padding-bottom: 0;
  }

  .side {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: var(--s4) var(--s2) var(--s4);
    background: var(--nav);
    color: var(--nav-text);
    border-right: 1px solid var(--nav-line);
    overflow-y: auto;
  }

  .side .brand {
    padding: var(--s1) var(--s2) var(--s4);
  }

  .topbar,
  .subnav,
  .tabbar {
    display: none;
  }

  .content {
    --content-pad: var(--s5);
    padding: var(--s5) var(--content-pad) var(--s6);
  }
}

@media (min-width: 1280px) {
  .app {
    --side-w: 208px;
  }

  .content {
    --content-pad: var(--s6);
    padding: var(--s5) var(--content-pad) var(--s6);
  }
}

@media (min-width: 1600px) {
  .app {
    --side-w: 232px;
  }
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--fs-s);
}

.nav a,
.nav summary {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--ctl-h);
  padding: 0 var(--s2);
  border-radius: var(--r1);
  color: var(--nav-text);
  cursor: pointer;
  list-style: none;
}

.nav summary::-webkit-details-marker {
  display: none;
}

.nav summary {
  font-weight: 600;
  user-select: none;
}

.nav summary span {
  flex: 1;
}

.nav-caret {
  width: 14px;
  height: 14px;
  color: var(--text2);
  transition: transform 0.15s;
}

.nav-module[open] > summary .nav-caret {
  transform: rotate(90deg);
}

.nav-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 0 var(--s2);
}

.nav-items a {
  min-height: 32px;
  padding-left: calc(var(--s2) + 18px + var(--s2));
  font-size: var(--fs-s);
}

.nav a:hover,
.nav summary:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
  color: var(--nav-text-hover);
  text-decoration: none;
}

.nav a:focus-visible,
.nav summary:focus-visible,
.side-who button:focus-visible {
  box-shadow: 0 0 0 3px var(--focus-nav);
}

.nav a.is-current {
  background: var(--nav-active);
  color: var(--accent);
  font-weight: 600;
}

/* родительский модуль текущей страницы — вторично: цвет текста, без заливки */
.nav-module.is-current > summary {
  color: var(--nav-text-hover);
}

.nav-module.is-current > summary .ico:first-child {
  color: var(--accent);
}

.side-who {
  display: flex;
  align-items: center;
  gap: var(--s1) var(--s2);
  margin-top: auto;
  padding: var(--s3) var(--s2) 0;
  border-top: 1px solid var(--nav-line);
  font-size: var(--fs-s);
}

.side-who p {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* подпись роли не рвётся посреди слова в узком меню 1024–1279 px */
.side-who p small {
  display: block;
  overflow: hidden;
  font-size: var(--fs-xs);
  font-weight: 400;
  color: var(--text2);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.side-who .avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
}

.side-who button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ctl-h);
  height: var(--ctl-h);
  padding: 0;
  border: 0;
  border-radius: var(--r1);
  background: none;
  color: var(--text2);
  font: inherit;
  cursor: pointer;
}

.side-who button:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
  color: var(--text);
}

/* ---------- вход ---------- */

body.login {
  min-height: 100vh;
}

.login-wrap {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--s4);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: var(--s5);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r2);
  box-shadow: var(--shadow);
}

.login-card .brand {
  color: var(--text);
  margin-bottom: var(--s5);
}

.login-card h1 {
  margin-bottom: var(--s4);
}

.login-card .field + .field {
  margin-top: var(--s4);
}

.login-card .btn {
  width: 100%;
  margin-top: var(--s5);
}

@media (min-width: 1024px) {
  .sheet-only {
    display: none;
  }
}

.pw-wrap {
  position: relative;
}

.pw-wrap input {
  padding-right: 92px;
}

.pw-toggle {
  position: absolute;
  right: var(--s1);
  top: 50%;
  transform: translateY(-50%);
  min-height: 28px;
  padding: 0 var(--s2);
  border: 0;
  border-radius: var(--r0);
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: var(--fs-s);
  font-weight: 500;
  cursor: pointer;
}

.pw-toggle:hover {
  background: var(--accent-bg);
}

/* меню уже 232 px (до 1600 px): аватар-буква (декоративный) скрыт, чтобы подпись роли поместилась */
@media (max-width: 1599.98px) {
  .side-who .avatar {
    display: none;
  }
}
