@font-face {
  font-family: "Onest";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/onest-cyrillic-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Onest";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/onest-latin-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============================ токены ============================ */

:root {
  --bg: #f4f6f5;
  --surface: #fff;
  --surface-2: #f7f9f8;
  --surface-3: #eef1f0;
  --ink: #101816;
  --ink-2: #3a4744;
  --muted: #6c7a76;
  --line: #e1e6e4;
  --line-strong: #cbd4d1;
  --accent: #226a59;
  --accent-hover: #1b594a;
  --accent-ink: #fff;
  --accent-soft: #e2efeb;
  --accent-soft-ink: #1a5648;
  --warn: #8f6118;
  --warn-soft: #f7edda;
  --danger: #a93648;
  --danger-soft: #f9e3e6;
  --focus: 0 0 0 3px rgb(34 106 89 / 24%);
  --shadow-s: 0 1px 2px rgb(16 24 22 / 6%);
  --shadow-m: 0 1px 2px rgb(16 24 22 / 5%), 0 10px 26px -18px rgb(16 24 22 / 30%);
  --shadow-l: 0 2px 6px rgb(16 24 22 / 8%), 0 28px 70px -28px rgb(16 24 22 / 40%);
  --r-s: 9px;
  --r-m: 13px;
  --r-l: 18px;
  --sans: "Onest", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --side: 264px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b100f;
    --surface: #141b19;
    --surface-2: #19211f;
    --surface-3: #212b28;
    --ink: #e9efec;
    --ink-2: #c2ccc9;
    --muted: #899894;
    --line: #232e2b;
    --line-strong: #32403c;
    --accent: #4fb89c;
    --accent-hover: #63c7ab;
    --accent-ink: #06231b;
    --accent-soft: rgb(79 184 156 / 14%);
    --accent-soft-ink: #86d9c1;
    --warn: #e0b060;
    --warn-soft: rgb(224 176 96 / 13%);
    --danger: #f07f90;
    --danger-soft: rgb(240 127 144 / 13%);
    --focus: 0 0 0 3px rgb(79 184 156 / 30%);
    --shadow-s: 0 1px 2px rgb(0 0 0 / 30%);
    --shadow-m: 0 1px 2px rgb(0 0 0 / 30%), 0 14px 34px -20px rgb(0 0 0 / 60%);
    --shadow-l: 0 2px 8px rgb(0 0 0 / 35%), 0 36px 80px -30px rgb(0 0 0 / 75%);
    color-scheme: dark;
  }
}

/* ============================ основа ============================ */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* без двойного тапа для зума и без «пружины» за краями страницы */
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  /* svh — высота при развёрнутых панелях браузера: страница не вылезает под них */
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: clip;
  overscroll-behavior: none;
  font: 400 15px/1.5 var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.02em; line-height: 1.18; }
h1 { font-size: clamp(22px, 2.4vw, 27px); font-weight: 640; }
h2 { font-size: 17px; font-weight: 620; }
h3 { font-size: 15px; font-weight: 620; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.hint-inline { color: var(--muted); font-size: 13px; }

.boot { min-height: 100svh; display: grid; place-items: center; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ============================ кнопки и поля ============================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink);
  font-weight: 560; font-size: 14.5px; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; min-height: 46px; font-size: 15.5px; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13.5px; }
.btn.icon-only { width: 38px; padding: 0; }
.btn.small.icon-only { width: 34px; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; border-color: currentColor; border-top-color: transparent; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 560; color: var(--ink-2); }
.field .hint { font-size: 12.5px; color: var(--muted); }

.input-wrap { position: relative; display: flex; align-items: center; }
.input {
  width: 100%; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink);
  font-size: 15px; transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder { color: var(--muted); opacity: 0.8; }
.input:hover { border-color: var(--muted); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input-wrap .input { padding-right: 46px; }
.input-wrap .peek {
  position: absolute; right: 5px; width: 36px; height: 36px;
  display: grid; place-items: center; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.input-wrap .peek:hover { color: var(--ink); background: var(--surface-3); }

.select {
  min-height: 40px; padding: 0 32px 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-s);
  background: var(--surface) no-repeat right 11px center/10px 6px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: var(--ink); font-size: 14px; font-weight: 520;
  appearance: none; cursor: pointer;
}
.select:hover { border-color: var(--muted); }

.strength { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 2px; }
.strength i { height: 4px; border-radius: 4px; background: var(--line); transition: background 0.2s; }
.strength[data-level="1"] i:nth-child(-n+1) { background: var(--danger); }
.strength[data-level="2"] i:nth-child(-n+2) { background: var(--warn); }
.strength[data-level="3"] i:nth-child(-n+3) { background: var(--accent); }
.strength[data-level="4"] i { background: var(--accent); }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  position: relative; flex: none; width: 44px; height: 26px; border-radius: 99px;
  background: var(--line-strong); transition: background 0.2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); transition: transform 0.2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 13px; border-radius: var(--r-s);
  background: var(--danger-soft); color: var(--danger); font-size: 14px;
}
.alert.info { background: var(--accent-soft); color: var(--accent-soft-ink); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert svg.icon { margin-top: 1px; }
.alert[hidden] { display: none; }

/* ============================ роли ============================ */

.segments {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 3px; gap: 2px; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--line);
}
.segments button {
  min-height: 30px; padding: 0 10px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 560;
  cursor: pointer; white-space: nowrap; transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.segments button:hover:not(:disabled) { color: var(--ink); }
.segments button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-s); }
.segments button[aria-pressed="true"][data-role="none"] { color: var(--muted); }
.segments button[aria-pressed="true"][data-role="admin"] { color: var(--accent); }
.segments button:disabled { cursor: default; }
.segments.busy { opacity: 0.6; pointer-events: none; }
.segments.wide { display: grid; width: 100%; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 580; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-2);
}
.badge.accent { background: var(--accent-soft); color: var(--accent-soft-ink); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.none { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line-strong); }

.role-chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 26px; padding: 0 10px 0 8px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 12.5px; color: var(--ink-2); white-space: nowrap;
}
.role-chip i { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.role-chip b { font-weight: 600; color: var(--ink); }

/* ============================ аватар и метки приложений ============================ */

.avatar {
  --h: 160;
  position: relative; overflow: hidden;
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(140deg, hsl(var(--h) 46% 46%), hsl(calc(var(--h) + 36) 52% 33%));
  color: #fff; font-weight: 650; font-size: 15px; letter-spacing: 0.01em;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar.xl { width: 72px; height: 72px; border-radius: 20px; font-size: 26px; }
.avatar.s { width: 32px; height: 32px; border-radius: 10px; font-size: 13px; }
.avatar[data-hue="1"] { --h: 200; }
.avatar[data-hue="2"] { --h: 250; }
.avatar[data-hue="3"] { --h: 290; }
.avatar[data-hue="4"] { --h: 335; }
.avatar[data-hue="5"] { --h: 20; }
.avatar[data-hue="6"] { --h: 40; }
.avatar[data-hue="7"] { --h: 120; }

/* Цвет приложения — по ключу; незнакомому достаётся нейтральный. */
.app-icon {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 11px;
  color: #fff; background: linear-gradient(140deg, #6b7b78, #3d4a47);
}
.app-icon.lg { width: 46px; height: 46px; border-radius: 14px; }
.app-icon svg.icon { width: 20px; height: 20px; stroke-width: 1.9; }
.app-icon[data-app="account"] { background: linear-gradient(140deg, #4fb89c, #1f5f52); }
.app-icon[data-app="bigfam"] { background: linear-gradient(140deg, #e0a347, #a8621c); }
.app-icon[data-app="homecloud"] { background: linear-gradient(140deg, #5aa7e8, #2e5fb0); }
.app-icon[data-app="lms_node"] { background: linear-gradient(140deg, #60b98f, #24745a); }
.app-icon[data-app="p3d"] { background: linear-gradient(140deg, #e8796c, #9f3d4c); }
.app-icon[data-app="sub_mirror"] { background: linear-gradient(140deg, #6c7ee8, #314a9f); }
.app-icon[data-app="task_tracker"] { background: linear-gradient(140deg, #b98ee0, #6a3f9e); }

/* цвет-метка приложения; незнакомому достаётся серая */
.role-chip i, .role-cell i { background: var(--line-strong); }
.role-chip i[data-app="bigfam"], .role-cell i[data-app="bigfam"] { background: #d18a36; }
.role-chip i[data-app="homecloud"], .role-cell i[data-app="homecloud"] { background: #4a8ad8; }
.role-chip i[data-app="lms_node"], .role-cell i[data-app="lms_node"] { background: #32906b; }
.role-chip i[data-app="p3d"], .role-cell i[data-app="p3d"] { background: #c55259; }
.role-chip i[data-app="sub_mirror"], .role-cell i[data-app="sub_mirror"] { background: #4d63c7; }
.role-chip i[data-app="task_tracker"], .role-cell i[data-app="task_tracker"] { background: #9463c7; }

/* ============================ бренд ============================ */

.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(140deg, #3f9e86, #1c5548); color: #fff;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 12%);
}
.brand-mark svg.icon { width: 19px; height: 19px; stroke-width: 2.1; }
.brand-text { display: grid; line-height: 1.2; }
.brand-text b { font-size: 15.5px; font-weight: 640; letter-spacing: -0.01em; }
.brand-text span { font-size: 12px; color: var(--muted); }

/* ============================ экран входа ============================ */

.auth { min-height: 100svh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.auth-aside {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
  padding: clamp(28px, 5vw, 56px);
  color: #e8f2ef;
  background: linear-gradient(160deg, #16352e 0%, #0f2521 55%, #0a1715 100%);
}
.auth-aside::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgb(255 255 255 / 6%) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
}
.auth-aside > * { position: relative; z-index: 1; }
.auth-aside .brand-text b { color: #fff; }
.auth-aside .brand-text span { color: rgb(232 242 239 / 55%); }
.auth-aside h1 { font-size: clamp(28px, 3.2vw, 40px); font-weight: 620; max-width: 15ch; }
.auth-aside .lead { margin-top: 14px; max-width: 42ch; color: rgb(232 242 239 / 70%); font-size: 16px; }
.auth-aside .auth-foot { font-size: 13.5px; color: rgb(232 242 239 / 48%); }
.auth-target {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 26px;
  padding: 11px 16px; border-radius: 99px;
  background: rgb(255 255 255 / 8%); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 12%);
  font-size: 14px; color: rgb(232 242 239 / 80%);
}
.auth-target b { color: #fff; font-weight: 600; }

.auth-main { display: grid; place-items: center; padding: clamp(20px, 5vw, 56px); }
.auth-card { width: min(410px, 100%); animation: rise 0.3s ease both; }
.auth-card header { margin-bottom: 24px; }
.auth-card header p { margin-top: 8px; color: var(--muted); }
.auth-card form { display: grid; gap: 16px; }
.auth-card .foot { margin-top: 22px; text-align: center; color: var(--muted); font-size: 14px; }
.auth-card .foot button { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 560; cursor: pointer; }
.auth-card .foot button:hover { text-decoration: underline; text-underline-offset: 3px; }
.auth-card .lead-gap { margin-top: 10px; }
.auth-card .state-icon {
  display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 18px;
  border-radius: 16px; background: var(--warn-soft); color: var(--warn);
}
.auth-card .state-icon svg.icon { width: 24px; height: 24px; }
.auth-card .actions { display: grid; gap: 10px; margin-top: 22px; }
.auth-card .who {
  display: flex; align-items: center; gap: 12px; margin-top: 18px; padding: 12px;
  border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line);
}
.auth-card .who b { display: block; font-weight: 600; }
.auth-card .who div span { font-size: 13px; color: var(--muted); }

/* ============================ каркас кабинета ============================ */

.shell { min-height: 100svh; display: grid; grid-template-columns: var(--side) minmax(0, 1fr); }

.side {
  position: sticky; top: 0; align-self: start;
  height: 100svh; display: flex; flex-direction: column; gap: 22px;
  padding: 22px 16px;
  border-right: 1px solid var(--line); background: var(--surface);
}
.side-nav { display: grid; gap: 3px; flex: 1; align-content: start; }
.side-nav a {
  display: flex; align-items: center; gap: 11px;
  min-height: 40px; padding: 0 12px; border-radius: 10px;
  color: var(--ink-2); font-weight: 540; font-size: 14.5px;
}
.side-nav a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.side-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-soft-ink); font-weight: 600; }
.side-nav a[aria-current="page"] svg.icon { stroke-width: 2.1; }
.side-foot { border-top: 1px solid var(--line); padding-top: 12px; }

.me-button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px; border: 1px solid transparent; border-radius: 11px;
  background: transparent; cursor: pointer; text-align: left;
}
.me-button:hover { background: var(--surface-3); }
.me-text { display: grid; min-width: 0; line-height: 1.25; }
.me-text b { font-weight: 580; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu-host { position: relative; }
.menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 30; min-width: 230px;
  padding: 6px; border-radius: var(--r-m);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-l); animation: rise 0.16s ease both;
}
.menu[hidden] { display: none; }
.menu .menu-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu .menu-head b { display: block; }
.menu .menu-head span { font-size: 13px; color: var(--muted); }
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: 0; border-radius: 8px; background: transparent;
  color: var(--ink); font-size: 14px; text-align: left; cursor: pointer;
}
.menu button:hover, .menu a:hover { background: var(--surface-3); text-decoration: none; }
.menu .danger { color: var(--danger); }
/* меню строки пользователя раскрывается вниз и влево */
.user-actions .menu, .topbar .menu { left: auto; right: 0; bottom: auto; top: calc(100% + 8px); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }

.page {
  width: min(1120px, 100%); margin: 0 auto;
  padding: clamp(22px, 3.4vw, 38px) clamp(16px, 3.4vw, 36px) 64px;
  display: grid; gap: 20px; align-content: start;
  animation: rise 0.25s ease both;
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { margin-top: 6px; color: var(--muted); font-size: 14.5px; }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.head-actions .search { min-width: 240px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow-s); }
.card-body { padding: clamp(18px, 2.6vw, 24px); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.card-head p { margin-top: 4px; font-size: 14px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-lg { display: grid; justify-items: center; gap: 8px; padding: 56px 20px; }
.empty-lg b { color: var(--ink); font-size: 16px; }
.empty-lg p { max-width: 42ch; }
.empty-lg .state-icon {
  display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 6px;
  border-radius: 16px; background: var(--surface-3); color: var(--muted);
}

/* ============================ приложения ============================ */

.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.app-tile {
  display: grid; gap: 12px; padding: 18px;
  border: 1px solid var(--line); border-radius: var(--r-l); background: var(--surface);
  color: var(--ink); box-shadow: var(--shadow-s);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.app-tile:hover { text-decoration: none; border-color: var(--line-strong); box-shadow: var(--shadow-m); transform: translateY(-2px); }
.app-tile.disabled { pointer-events: none; opacity: 0.6; }
.app-tile .app-text b { display: block; font-size: 16px; font-weight: 620; }
.app-tile .app-text span { display: block; margin-top: 3px; color: var(--muted); font-size: 13.5px; }
.app-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.app-open { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 13.5px; font-weight: 580; }
.app-open svg.icon { width: 15px; height: 15px; }

/* ============================ профиль ============================ */

.hero { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.hero .who { flex: 1; min-width: 220px; }
.hero .name-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; color: var(--muted); font-size: 14px; }
.hero .meta span { display: inline-flex; align-items: center; gap: 6px; }
.hero .meta svg.icon { width: 15px; height: 15px; }
.rename { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rename .input { min-height: 40px; width: min(320px, 100%); font-size: 17px; font-weight: 560; }

.access-list { display: grid; }
.access-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-top: 1px solid var(--line);
}
.access-row:first-child { border-top: 0; padding-top: 0; }
.access-row b { font-weight: 560; }

.access-grid { display: grid; gap: 10px; }
.access-edit {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 12px; align-items: center;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface-2);
}
.access-edit .text { min-width: 0; }
.access-edit .text b { display: block; font-weight: 580; font-size: 14.5px; }
.access-edit .text span { display: block; color: var(--muted); font-size: 12.5px; }
.access-edit .segments { grid-column: 1 / -1; }

.form-grid { display: grid; gap: 14px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }

/* ============================ пользователи ============================ */

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg.icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 40px; min-height: 40px; }
.filters { display: flex; align-items: center; gap: 8px; color: var(--muted); }

.users { display: grid; }
.user-row {
  display: grid; grid-template-columns: minmax(220px, 1.1fr) minmax(0, 1.4fr) auto;
  align-items: center; gap: 16px; padding: 13px clamp(14px, 2vw, 20px);
  border-top: 1px solid var(--line);
}
.user-row:first-child { border-top: 0; }
.user-row:hover { background: var(--surface-2); }
.user-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-id .text { min-width: 0; }
.user-id b { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 600; }
.user-id .text > span { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-access { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.user-actions { display: flex; align-items: center; gap: 6px; }

.settings-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-top: 16px; }
.settings-row[hidden] { display: none; }
.role-cell { display: grid; gap: 5px; min-width: 0; }
.role-cell > small { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 580; color: var(--muted); }
.role-cell > small i { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.role-cell .segments { width: 100%; display: grid; }
.role-cell .segments button { padding: 0 6px; }

/* ============================ диалоги и тосты ============================ */

dialog {
  width: min(520px, calc(100% - 24px)); max-height: calc(100svh - 24px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-l);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-l);
}
dialog[open] { animation: rise 0.18s ease both; }
dialog::backdrop { background: rgb(8 14 12 / 45%); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 16px; padding: clamp(20px, 3vw, 26px); }
dialog header p { margin-top: 6px; color: var(--muted); font-size: 14px; }
dialog .form-actions { margin-top: 6px; }

.pw-row { display: flex; gap: 8px; }
.pw-row .input-wrap { flex: 1; }

#toasts {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 100;
  display: grid; gap: 8px; transform: translateX(-50%); width: min(420px, calc(100% - 24px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-radius: var(--r-m); background: #16201e; color: #eef5f2;
  box-shadow: var(--shadow-l); font-size: 14px; animation: rise 0.2s ease both;
}
.toast.error { background: #3a1820; color: #ffd9df; }
.toast svg.icon { color: #63c7ab; }
.toast.error svg.icon { color: #ff9aab; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }

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

/* меню строки не должно прятаться под следующей карточкой */
.card { position: relative; }
.card:has(.menu:not([hidden])) { z-index: 10; }

/* ============================ планшеты и телефоны ============================ */

.bottom-nav { display: none; }

@media (hover: none) {
  .user-row:hover { background: transparent; }
  .app-tile:hover { transform: none; border-color: var(--line); box-shadow: var(--shadow-s); }
  .btn:hover { background: var(--surface); }
  .btn.primary:hover { background: var(--accent); border-color: var(--accent); }
  .btn.ghost:hover { background: transparent; }
}

@media (max-width: 1100px) {
  .user-row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 10px; }
  .user-access { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 980px) {
  /* боковая колонка уезжает: сверху полоса, снизу разделы под большим пальцем */
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    padding: calc(9px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 9px max(14px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(1.4) blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .topbar .me-button { width: auto; }
  .topbar .me-text { display: none; }
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px;
    padding: 6px max(10px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(16px);
    border-top: 1px solid var(--line);
  }
  .bottom-nav a {
    display: grid; justify-items: center; gap: 2px; padding: 7px 4px 6px;
    border-radius: 12px; color: var(--muted); font-size: 11.5px; font-weight: 580;
  }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav a svg.icon { width: 22px; height: 22px; }
  .bottom-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
  .page { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
}

@media (max-width: 880px) {
  .auth { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .auth-aside {
    gap: 14px;
    padding: calc(16px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 18px max(16px, env(safe-area-inset-left));
  }
  .auth-aside::after, .auth-aside .auth-foot { display: none; }
  .auth-aside h1, .auth-aside .lead { display: none; }
  .auth-target { margin-top: 0; }
  .auth-main {
    place-items: start stretch;
    padding: 24px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .auth-card { width: 100%; max-width: 440px; margin: 0 auto; }
  .auth-card header { margin-bottom: 20px; }
}

@media (max-width: 640px) {
  h1 { font-size: 22px; }
  h2 { font-size: 17px; }

  /* 16px в полях — иначе iOS увеличивает страницу при фокусе */
  .input, .search .input, .rename .input, .select { font-size: 16px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .btn.icon-only { width: 44px; }
  .btn.small.icon-only { width: 38px; }

  .page { gap: 14px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .head-actions, .head-actions .btn, .head-actions .search { width: 100%; min-width: 0; }

  .card { border-radius: 16px; }
  .card-body { padding: 16px; }
  .card-head { margin-bottom: 14px; }

  .app-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .app-tile { padding: 14px; }

  .hero { flex-wrap: nowrap; align-items: flex-start; gap: 14px; }
  .hero .who { min-width: 0; }
  .hero .avatar.xl { width: 56px; height: 56px; border-radius: 17px; font-size: 21px; }
  .hero .name-line h2 { overflow-wrap: anywhere; }
  .rename, .rename .input { width: 100%; }
  .rename .btn { flex: 1; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .filters { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); }
  .search { min-width: 0; }

  .user-row { gap: 10px; padding: 14px 14px 16px; }
  .user-id .text > span { white-space: normal; }
  .user-actions .btn.small { flex: 1; }
  .user-actions { grid-row: 3; grid-column: 1 / -1; }

  .settings-row { grid-template-columns: minmax(0, 1fr); }
  .switch { align-items: flex-start; }

  /* диалоги — листом снизу */
  dialog {
    width: 100%; max-width: 100%;
    max-height: calc(100svh - 12px - env(safe-area-inset-top));
    margin: auto 0 0; border-radius: 20px 20px 0 0; border-bottom: 0;
    overflow-y: auto; overscroll-behavior: contain;
  }
  dialog form {
    gap: 14px;
    padding: 20px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  dialog .form-actions { flex-direction: column-reverse; }
  dialog .form-actions .btn { width: 100%; }

  #toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .auth-card h1 { font-size: 21px; }
  .role-cell .segments button { font-size: 11.5px; }
}
