/* Стили АСУ.
   Правило проекта: селекторы только по классам — ни тегов, ни идентификаторов,
   ни универсального селектора. Разметка обязана нести класс на каждом
   оформляемом элементе. */

.theme {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #d9e0e7;
  --text: #1c2530;
  --muted: #6b7885;
  --accent: #1f6feb;
  --accent-dark: #1a5fd0;
  --ok: #1a7f4b;
  --neg: #c0392b;
  --danger: #b62b2b;
  --radius: 8px;

  margin: 0;
  font: 15px/1.5 "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-width: 400px;
  box-sizing: border-box;
}

/* ---------- макет: боковая панель фильтров + содержимое ---------- */
.layout {
  max-width: 1700px;
  margin: 0 auto;
  padding: 20px;
  box-sizing: border-box;
}
.layout--with-sidebar {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.content { min-width: 0; }

.sidebar {
  position: sticky; top: 20px;
  max-height: calc(100vh - 40px); overflow-y: auto;
}
.sidebar__inner {
  /* relative внутри sticky-родителя: дочерние элементы не выходят за границы */
  position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  box-sizing: border-box;
}
/* ---------- сворачиваемые блоки ----------
   Построены на <details>/<summary>: раскрытие работает без JavaScript и
   доступно с клавиатуры. Заголовок служит переключателем. */
.fold { margin: 0; }
.fold__title {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 22px 0 12px; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); text-align: center; cursor: pointer;
  list-style: none;                 /* убираем штатный треугольник */
}
.fold__title::-webkit-details-marker { display: none; }
.fold__title::after {
  content: "▾";
  font-size: 16px;
  line-height: 1;
  transition: transform .15s ease;
}
.fold__title:hover { color: var(--text); }
.fold[open] > .fold__title::after { transform: rotate(180deg); }

/* у первого блока панели разделителя сверху быть не должно */
.fold--first > .fold__title { margin-top: 0; padding-top: 0; border-top: none; }
.backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(28, 37, 48, .35);
  opacity: 0; visibility: hidden; transition: opacity .18s ease, visibility .18s ease;
}
.backdrop--visible { opacity: 1; visibility: visible; }

.title { font-size: 22px; margin: 0 0 16px; }
.title--page { margin-bottom: 4px; }
.subtitle { font-size: 17px; margin: 0 0 12px; }
.section-title {
  margin: 22px 0 10px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.strong { font-weight: 600; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; }

/* ---------- шапка ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 20px; min-width: 0;
}
.nav {
  display: flex; align-items: center; gap: 4px;
  min-width: 0; flex: 1 1 auto; flex-wrap: nowrap;
}
.nav__home {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; min-width: 42px; flex: 0 0 42px;
  height: 34px; margin-right: 10px; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--accent); text-decoration: none;
}
.nav__home:hover { background: #eef3f9; border-color: var(--accent); }
.nav__home-icon { width: 19px; height: 19px; display: block; }
.nav__home-path { fill: currentColor; }
.nav__logout-icon { width: 18px; height: 18px; display: block; fill: currentColor; }

.nav__brand {
  font-weight: 700; margin-right: 16px; color: var(--accent);
  padding: 14px 0; font-size: 16px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav__link {
  padding: 14px; text-decoration: none; color: var(--text);
  border-bottom: 2px solid transparent;
}
.nav__link:hover { background: #eef3f9; }
.nav__link--active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.nav__burger {
  display: none; margin-right: 10px; padding: 6px 11px;
  font: inherit; font-size: 18px; line-height: 1; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
}
.nav__burger:hover { background: #eef3f9; }
.userbox {
  display: flex; align-items: center; gap: 12px;
  flex: 0 0 auto; white-space: nowrap;
}
.userbox__name { color: var(--muted); font-size: 14px; }

/* ---------- карточки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.card--empty { text-align: center; color: var(--muted); padding: 40px; }
.card--login { width: 340px; }

/* ---------- формы ---------- */
.filters { margin-bottom: 16px; }
.filter-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 12px;
}
.filter-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  justify-content: center; margin-top: 14px;
}
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px; align-items: start;
}
.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field--login { margin-bottom: 12px; color: var(--text); }
.field__input, .field__select {
  display: block; width: 100%; margin-top: 4px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 6px;
  font: inherit; color: var(--text); background: var(--surface);
  box-sizing: border-box;
}
.field__input:focus, .field__select:focus {
  outline: 2px solid var(--accent); border-color: transparent;
}
.field__check {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-size: 14px; margin-top: 8px;
}
.field__checkbox { width: auto; margin: 0; }
.fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin: 8px 0; }
.fieldset__legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.form-inline { display: inline; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; min-width: 116px; padding: 0 16px;
  border-radius: 6px; cursor: pointer; text-align: center; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; font: inherit; box-sizing: border-box;
}
.btn:hover { background: #eef3f9; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); }
.btn--ghost { background: transparent; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--small { min-height: 28px; min-width: 0; padding: 0 10px; font-size: 13px; }
.btn--block { display: flex; width: 100%; margin-top: 8px; }
/* Неактивная операция: видно, что она существует, но сейчас неприменима */
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); }
.btn--primary:disabled:hover { background: var(--accent); }
.btn--danger:disabled:hover { background: var(--danger); }

/* ---------- таблицы ---------- */
.table-wrap {
  position: relative;                 /* опора для липких строк внутри */
  overflow: auto; max-height: calc(100vh - 210px);
  border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.table-wrap--tall { max-height: calc(100vh - 80px); }
.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
.grid__th {
  padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: center;
  white-space: nowrap; background: #eef3f9; font-weight: 600;
  position: sticky; top: 0; z-index: 2;
}
.grid__tf {
  padding: 7px 10px; border-top: 1px solid var(--border); text-align: left;
  white-space: nowrap; background: #eef3f9; font-weight: 600;
  position: sticky; bottom: 0; z-index: 2;
}
.grid__td {
  padding: 7px 10px; border-bottom: 1px solid var(--border);
  text-align: left; white-space: nowrap;
}
.grid__row:hover { background: #f7fbff; }
.grid__th--num, .grid__td--num, .grid__tf--num {
  text-align: right; font-variant-numeric: tabular-nums;
}
.grid__td--ok { color: var(--ok); }
.grid__td--neg { color: var(--neg); }
.grid__td--strong { font-weight: 600; }
.grid__row--edit { display: none; }
.grid__row--edit:target { display: table-row; background: #f7fbff; }
.grid__row--link { cursor: pointer; }
.grid__row--link:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- мелочи ---------- */
.tag {
  display: inline-block; padding: 2px 8px; margin: 2px 3px 2px 0;
  background: #eef3f9; border: 1px solid var(--border);
  border-radius: 12px; font-size: 12px;
}
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; margin: 0; }
.kv__key { color: var(--muted); font-size: 13px; }
.kv__value { margin: 0; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.flash--error { background: #fdecea; border-color: #f5c6c2; color: #8a1f16; }
.flash--ok { background: #e8f6ee; border-color: #bfe3ce; color: #12653a; }
.note { margin: 8px 0 0; }

/* ---------- вход ---------- */
.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }

/* ---------- модальные окна ---------- */
.modal {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(28, 37, 48, .38);
  opacity: 0; visibility: hidden;
  transition: opacity .16s ease, visibility .16s ease;
}
.modal--open { opacity: 1; visibility: visible; }
.modal__box {
  position: relative;             /* опора для содержимого окна */
  width: 420px; max-width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
  box-sizing: border-box;
}
.modal__title { margin: 0 0 14px; font-size: 18px; }

/* ---------- индикатор загрузки ---------- */
.loader {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(28, 37, 48, .28);
  backdrop-filter: blur(1px);
  opacity: 0; visibility: hidden;
  transition: opacity .15s ease, visibility .15s ease;
}
.loader--visible { opacity: 1; visibility: visible; }
.loader__box {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: var(--surface); border-radius: var(--radius);
  padding: 22px 30px; box-shadow: 0 6px 26px rgba(0, 0, 0, .18);
}
.loader__spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #dfe6ee; border-top-color: var(--accent);
  animation: loader-spin .7s linear infinite;
}
.loader__text { color: var(--muted); font-size: 14px; }

@keyframes loader-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .loader__spinner { animation-duration: 2.4s; }
  .tile { transition: none; }
}

/* ---------- мобильная версия ---------- */
@media (max-width: 900px) {
  .layout--with-sidebar { display: block; }

  .nav__burger { display: inline-flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    width: 300px; max-width: 88vw; padding: 14px;
    overflow-y: auto; background: var(--bg);
    box-shadow: 2px 0 16px rgba(0, 0, 0, .18);
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-sizing: border-box;
  }
  .sidebar--open { transform: translateX(0); }

  .topbar { flex-wrap: nowrap; padding: 0 12px; }
  .nav__link { padding: 12px 10px; }
  .layout { padding: 14px; }
  .filter-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv__value { margin-bottom: 8px; }
  .title { font-size: 19px; }
  .page-head { flex-direction: column; gap: 10px; }
}

@media (min-width: 901px) {
  /* на широком экране панель всегда видна, затемнение не нужно */
  .backdrop { display: none; }
}
