/* Material Design 3 — тёмная и светлая схемы из одного исходного цвета (#4a5d9a, «индиго гаранта»). */
:root {
  --md-primary: #b4c5ff;
  --md-on-primary: #1a2d60;
  --md-primary-container: #324478;
  --md-on-primary-container: #dbe1ff;
  --md-secondary-container: #3f4759;
  --md-on-secondary-container: #dbe2f9;
  --md-tertiary: #e2bbdb;
  --md-tertiary-container: #5a3d58;
  --md-on-tertiary-container: #ffd7f6;
  --md-error: #ffb4ab;
  --md-on-error: #690005;
  --md-error-container: #93000a;
  --md-on-error-container: #ffdad6;
  --md-success: #8fd8a6;
  --md-success-container: #0e5130;
  --md-surface: #121318;
  --md-surface-dim: #121318;
  --md-surface-c-lowest: #0d0e13;
  --md-surface-c-low: #1a1b21;
  --md-surface-c: #1e1f25;
  --md-surface-c-high: #292a2f;
  --md-surface-c-highest: #33343a;
  --md-on-surface: #e3e2e9;
  --md-on-surface-variant: #c5c6d0;
  --md-outline: #8f909a;
  --md-outline-variant: #45464f;
  --md-inverse-surface: #e3e2e9;
  --md-inverse-on-surface: #2f3036;
  --md-scrim: #000;
  --elev-1: 0 1px 2px rgb(0 0 0 / .3), 0 1px 3px 1px rgb(0 0 0 / .15);
  --elev-3: 0 1px 3px rgb(0 0 0 / .3), 0 4px 8px 3px rgb(0 0 0 / .15);
  --shape-xs: 4px; --shape-s: 8px; --shape-m: 12px; --shape-l: 16px; --shape-xl: 28px; --shape-full: 999px;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --ease-emph: cubic-bezier(.05, .7, .1, 1);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --md-primary: #4a5d92;
  --md-on-primary: #fff;
  --md-primary-container: #dbe1ff;
  --md-on-primary-container: #01174b;
  --md-secondary-container: #dbe2f9;
  --md-on-secondary-container: #141b2c;
  --md-tertiary: #735471;
  --md-tertiary-container: #ffd7f6;
  --md-on-tertiary-container: #2b122b;
  --md-error: #ba1a1a;
  --md-on-error: #fff;
  --md-error-container: #ffdad6;
  --md-on-error-container: #410002;
  --md-success: #1f6b42;
  --md-success-container: #b0f1c7;
  --md-surface: #faf8ff;
  --md-surface-dim: #dad9e0;
  --md-surface-c-lowest: #fff;
  --md-surface-c-low: #f4f3fa;
  --md-surface-c: #eeedf4;
  --md-surface-c-high: #e9e7ef;
  --md-surface-c-highest: #e3e2e9;
  --md-on-surface: #1a1b21;
  --md-on-surface-variant: #45464f;
  --md-outline: #757680;
  --md-outline-variant: #c5c6d0;
  --md-inverse-surface: #2f3036;
  --md-inverse-on-surface: #f1f0f7;
  --elev-1: 0 1px 2px rgb(0 0 0 / .3), 0 1px 3px 1px rgb(0 0 0 / .15);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Roboto Flex", system-ui, sans-serif;
  font-optical-sizing: auto;
  background: var(--md-surface);
  color: var(--md-on-surface);
  font-size: 14px; line-height: 20px; letter-spacing: .25px;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
code, .mono { font-family: "Roboto Mono", ui-monospace, monospace; font-size: 12.5px; }
a { color: var(--md-primary); }

.ms {
  font-family: "Material Symbols Rounded";
  font-weight: normal; font-style: normal; font-size: 24px; line-height: 1;
  display: inline-block; white-space: nowrap; direction: ltr;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  user-select: none;
}
.ms.fill { font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24; }

/* ---------- каркас: navigation rail + контент ---------- */
.app { display: grid; grid-template-columns: 88px 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0; gap: 8px; background: var(--md-surface);
}
.rail-head { padding: 4px 0 20px; }
.brand-mark {
  width: 56px; height: 56px; border-radius: var(--shape-l);
  display: grid; place-items: center;
  background: var(--md-tertiary-container); color: var(--md-on-tertiary-container);
  box-shadow: var(--elev-3);
}
.brand-mark.big { width: 72px; height: 72px; border-radius: 22px; }
.brand-mark.big .ms { font-size: 36px; }
.rail-items { display: flex; flex-direction: column; gap: 12px; flex: 1; overflow-y: auto; width: 100%; align-items: center; }
.rail-foot { padding-top: 8px; }
.rail-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--md-on-surface-variant); text-decoration: none;
  font-size: 12px; font-weight: 500; letter-spacing: .5px; line-height: 16px;
  background: none; border: 0; cursor: pointer; width: 80px; padding: 0;
}
.rail-item .pill {
  width: 56px; height: 32px; border-radius: var(--shape-full);
  display: grid; place-items: center; position: relative; overflow: hidden;
  transition: background-color .2s var(--ease);
}
.rail-item:hover .pill { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.rail-item[aria-current="page"] { color: var(--md-on-surface); }
.rail-item[aria-current="page"] .pill { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.rail-item[aria-current="page"] .ms { font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24; }
.rail-item .badge {
  position: absolute; top: 2px; right: 10px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--md-error); color: var(--md-on-error);
  font-size: 11px; line-height: 16px; font-weight: 500;
}

.main { min-width: 0; background: var(--md-surface-c-lowest); border-radius: var(--shape-xl) 0 0 var(--shape-xl); min-height: 100vh; }
:root[data-theme="light"] .main { background: var(--md-surface-c-low); }
.top-bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 32px 16px; background: inherit; border-radius: inherit;
}
.top-titles h1 { margin: 0; font-size: 28px; line-height: 36px; font-weight: 400; letter-spacing: 0; }
.sub { margin: 2px 0 0; color: var(--md-on-surface-variant); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.view { padding: 8px 32px 48px; outline: none; }

/* ---------- кнопки ---------- */
.btn {
  --bg: transparent; --fg: var(--md-primary);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 24px; border-radius: var(--shape-full);
  border: 0; background: var(--bg); color: var(--fg);
  font: 500 14px/20px "Roboto Flex", sans-serif; letter-spacing: .1px;
  cursor: pointer; text-decoration: none; position: relative; isolation: isolate;
  transition: box-shadow .2s var(--ease);
}
.btn .ms { font-size: 18px; margin-left: -8px; }
.btn::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: currentColor; opacity: 0; transition: opacity .15s; z-index: -1; }
.btn:hover::after { opacity: .08; }
.btn:active::after { opacity: .12; }
.btn:disabled { opacity: .38; cursor: default; }
.btn.filled { --bg: var(--md-primary); --fg: var(--md-on-primary); }
.btn.filled:hover { box-shadow: var(--elev-1); }
.btn.tonal { --bg: var(--md-secondary-container); --fg: var(--md-on-secondary-container); }
.btn.outlined { border: 1px solid var(--md-outline); }
.btn.danger { --bg: var(--md-error); --fg: var(--md-on-error); }
.btn.text { padding: 0 12px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--shape-full); border: 0;
  display: inline-grid; place-items: center; background: none; color: var(--md-on-surface-variant);
  cursor: pointer; text-decoration: none; transition: background-color .15s;
}
.icon-btn:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.icon-btn.danger { color: var(--md-error); }

/* ---------- чипы ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 16px;
  border-radius: var(--shape-s); border: 1px solid var(--md-outline-variant);
  background: none; color: var(--md-on-surface-variant);
  font: 500 14px/20px "Roboto Flex", sans-serif; cursor: pointer; white-space: nowrap;
}
.chip .ms { font-size: 18px; margin-left: -8px; }
.chip.assist { cursor: default; }
.chip[aria-pressed="true"] { background: var(--md-secondary-container); color: var(--md-on-secondary-container); border-color: transparent; }
.chip[aria-pressed="true"]::before { content: "check"; font-family: "Material Symbols Rounded"; font-size: 18px; margin-left: -8px; }
.chip.locked { opacity: .7; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- карточки и раскладка ---------- */
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.card {
  background: var(--md-surface-c-low); border-radius: var(--shape-m); padding: 20px 24px;
}
:root[data-theme="light"] .card { background: var(--md-surface-c-lowest); }
.card.elevated { background: var(--md-surface-c-low); box-shadow: var(--elev-1); }
.card.outlined { background: none; border: 1px solid var(--md-outline-variant); }
.card h2 { margin: 0 0 4px; font-size: 22px; line-height: 28px; font-weight: 400; }
.card h3 { margin: 0 0 12px; font-size: 16px; line-height: 24px; font-weight: 500; letter-spacing: .15px; }
.card .hint { margin: 0 0 16px; color: var(--md-on-surface-variant); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.section-label { margin: 28px 0 12px; font-size: 14px; font-weight: 500; color: var(--md-primary); letter-spacing: .1px; }
.section-label:first-child { margin-top: 0; }

.stat {
  border-radius: var(--shape-l); padding: 20px; position: relative; overflow: hidden;
  background: var(--md-surface-c); min-height: 132px; display: flex; flex-direction: column; justify-content: space-between;
  animation: rise .5s var(--ease-emph) both;
}
.stat:nth-child(2) { animation-delay: .04s; } .stat:nth-child(3) { animation-delay: .08s; }
.stat:nth-child(4) { animation-delay: .12s; } .stat:nth-child(5) { animation-delay: .16s; }
.stat:nth-child(6) { animation-delay: .2s; }
.stat .ms { color: var(--md-primary); }
.stat .value { font-size: 45px; line-height: 52px; font-weight: 400; letter-spacing: -.5px; font-variation-settings: "opsz" 96; }
.stat .label { color: var(--md-on-surface-variant); font-weight: 500; }
.stat.hero { background: var(--md-primary-container); color: var(--md-on-primary-container); grid-column: span 2; }
.stat.hero .ms, .stat.hero .label { color: inherit; opacity: .85; }
.stat.warn { background: var(--md-tertiary-container); color: var(--md-on-tertiary-container); }
.stat.warn .ms, .stat.warn .label { color: inherit; opacity: .85; }
@media (max-width: 720px) { .stat.hero { grid-column: span 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* ---------- списки ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 16px; padding: 10px 8px 10px 16px; min-height: 56px;
  border-radius: var(--shape-m); transition: background-color .15s;
}
.list li:hover { background: color-mix(in srgb, var(--md-on-surface) 5%, transparent); }
.list li + li { margin-top: 2px; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 500; font-size: 16px;
  background: var(--md-primary-container); color: var(--md-on-primary-container);
}
.avatar.err { background: var(--md-error-container); color: var(--md-on-error-container); }
.avatar.ter { background: var(--md-tertiary-container); color: var(--md-on-tertiary-container); }
.li-text { flex: 1; min-width: 0; }
.li-title { font-size: 16px; line-height: 24px; letter-spacing: .5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-sub { color: var(--md-on-surface-variant); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-trail { display: flex; align-items: center; gap: 4px; color: var(--md-on-surface-variant); flex: none; }
.empty { padding: 32px 16px; text-align: center; color: var(--md-on-surface-variant); }
.empty .ms { font-size: 40px; display: block; margin: 0 auto 8px; opacity: .6; }

/* ---------- поля ---------- */
.field { position: relative; display: block; flex: 1; min-width: 160px; }
.field input, .field select, .field textarea {
  width: 100%; height: 56px; padding: 20px 16px 6px; border-radius: var(--shape-xs) var(--shape-xs) 0 0;
  border: 0; border-bottom: 1px solid var(--md-on-surface-variant);
  background: var(--md-surface-c-highest); color: var(--md-on-surface);
  font: 400 16px/24px "Roboto Flex", sans-serif; outline: none; transition: border-color .15s;
  appearance: none;
}
.field textarea { height: auto; min-height: 96px; resize: vertical; padding-top: 26px; }
.field select { cursor: pointer; }
.field label {
  position: absolute; left: 16px; top: 8px; font-size: 12px; line-height: 16px;
  color: var(--md-on-surface-variant); pointer-events: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-bottom: 2px solid var(--md-primary); }
.field:focus-within label { color: var(--md-primary); }
.field .ms.trail { position: absolute; right: 12px; top: 16px; color: var(--md-on-surface-variant); pointer-events: none; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-row + .form-row { margin-top: 12px; }
.supporting { font-size: 12px; color: var(--md-on-surface-variant); margin: 6px 16px 0; }

/* ---------- переключатель (switch) ---------- */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; }
.switch-row + .switch-row { border-top: 1px solid var(--md-outline-variant); }
.switch-row .t { font-size: 16px; line-height: 24px; }
.switch-row .s { color: var(--md-on-surface-variant); }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch .track {
  position: absolute; inset: 0; border-radius: 16px;
  background: var(--md-surface-c-highest); border: 2px solid var(--md-outline);
  transition: background-color .2s var(--ease), border-color .2s var(--ease);
}
.switch .thumb {
  position: absolute; top: 8px; left: 8px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--md-outline); transition: all .25s var(--ease-emph);
}
.switch input:checked ~ .track { background: var(--md-primary); border-color: var(--md-primary); }
.switch input:checked ~ .thumb { left: 24px; top: 4px; width: 24px; height: 24px; background: var(--md-on-primary); }
.switch input:focus-visible ~ .track { outline: 3px solid var(--md-primary); outline-offset: 2px; }

/* ---------- сегменты ---------- */
.segmented { display: inline-flex; border: 1px solid var(--md-outline); border-radius: var(--shape-full); overflow: hidden; flex-wrap: wrap; }
.segmented button {
  height: 40px; padding: 0 14px; border: 0; background: none; color: var(--md-on-surface);
  font: 500 14px/20px "Roboto Flex", sans-serif; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.segmented button + button { border-left: 1px solid var(--md-outline); }
.segmented button[aria-pressed="true"] { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.segmented button[aria-pressed="true"]::before { content: "check"; font-family: "Material Symbols Rounded"; font-size: 18px; }

/* ---------- таблица ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--md-on-surface-variant); padding: 8px 12px; font-size: 12px; letter-spacing: .5px; }
.table td { padding: 12px; border-top: 1px solid var(--md-outline-variant); }
.table td.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--md-success); font-weight: 500; }
.neg { color: var(--md-error); font-weight: 500; }

/* ---------- журнал ---------- */
.log { margin: 0; padding: 0; list-style: none; }
.log li { display: grid; grid-template-columns: 150px 210px 1fr; gap: 12px; padding: 8px 12px; border-radius: var(--shape-s); }
.log li:nth-child(odd) { background: color-mix(in srgb, var(--md-on-surface) 3%, transparent); }
.log .when { color: var(--md-on-surface-variant); }
.log .by { color: var(--md-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log .what { word-break: break-word; }
@media (max-width: 860px) { .log li { grid-template-columns: 1fr; gap: 0; } }

/* ---------- snackbar, dialog ---------- */
.snackbar {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 24px);
  min-width: 288px; max-width: min(560px, 92vw); padding: 14px 16px; border-radius: var(--shape-xs);
  background: var(--md-inverse-surface); color: var(--md-inverse-on-surface); box-shadow: var(--elev-3);
  opacity: 0; pointer-events: none; transition: all .25s var(--ease-emph); z-index: 50; white-space: pre-line;
}
.snackbar.show { opacity: 1; transform: translate(-50%, 0); }
.dialog {
  border: 0; border-radius: var(--shape-xl); padding: 24px; width: min(560px, 92vw);
  background: var(--md-surface-c-high); color: var(--md-on-surface); box-shadow: var(--elev-3);
}
.dialog::backdrop { background: rgb(0 0 0 / .4); }
.dialog h2 { margin: 0 0 16px; font-size: 24px; line-height: 32px; font-weight: 400; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.dialog[open] { animation: pop .3s var(--ease-emph); }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }

/* ---------- вход ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse at 20% 0%, color-mix(in srgb, var(--md-primary) 18%, transparent), transparent 60%),
              radial-gradient(ellipse at 100% 100%, color-mix(in srgb, var(--md-tertiary) 14%, transparent), transparent 55%), var(--md-surface); }
.gate-card { max-width: 420px; text-align: center; background: var(--md-surface-c-low); padding: 40px 32px; border-radius: var(--shape-xl); box-shadow: var(--elev-3); }
.gate-card .brand-mark { margin: 0 auto 20px; }
.gate-card h1 { font-size: 28px; line-height: 36px; font-weight: 400; margin: 0 0 12px; }
.gate-card p { color: var(--md-on-surface-variant); margin: 0 0 24px; }

.view > * { animation: fade .28s var(--ease) both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- мобильная раскладка: rail → нижняя навигация ---------- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: 80px; flex-direction: row; padding: 0 4px; z-index: 10; background: var(--md-surface-c); }
  .rail-head, .rail-foot { display: none; }
  .rail-items { flex-direction: row; justify-content: space-around; overflow-x: auto; gap: 0; }
  .rail-item { width: 64px; flex: none; }
  .main { border-radius: 0; padding-bottom: 88px; }
  .top-bar, .view { padding-left: 16px; padding-right: 16px; }
  .top-titles h1 { font-size: 22px; line-height: 28px; }
  #who span:last-child { display: none; }
}

/* длинные названия веток в чипах не должны раздвигать экран на телефоне */
.chip { max-width: 100%; }
.chips .chip { overflow: hidden; text-overflow: ellipsis; }
.li-text .chips { min-width: 0; }
@media (max-width: 720px) {
  .list li { flex-wrap: wrap; }
  .list li .li-text { flex-basis: calc(100% - 56px); }
  .list li .li-trail { margin-left: auto; }
}
