/* ===== Токены ===== */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --text: #172033;
  --muted: #667085;
  --line: #e4e7ee;
  --primary: #2f6fed;
  --primary-hover: #245bd0;
  --primary-soft: #eaf1fe;
  --on-primary: #ffffff;
  --side-bg: #111a2e;
  --side-text: #c9d2e3;
  --side-active: #ffffff;
  --side-active-bg: rgba(255, 255, 255, .09);
  --ok: #e7f6ec;   --ok-text: #1d7a3e;
  --warn: #fff5dc; --warn-text: #8f5f00;
  --bad: #fdecec;  --bad-text: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e121a; --surface: #161b25; --surface-2: #1b2130; --text: #e6e9ef; --muted: #98a2b3;
    --line: #273042; --primary: #5b8ff5; --primary-hover: #7aa5f7; --primary-soft: #1c2a47;
    --side-bg: #0a0e16; --ok: #12321f; --ok-text: #7fd8a0; --warn: #3a2f12; --warn-text: #f2c96b;
    --bad: #3d1a1a; --bad-text: #f5a3a3; --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; font-weight: 650; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 650; margin: 0 0 .9rem; }
h3 { font-size: .95rem; font-weight: 600; margin: 1.2rem 0 .6rem; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ===== Каркас: боковое меню + содержимое ===== */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column;
  padding: 1.1rem .8rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .65rem; color: #fff; font-weight: 650; padding: .3rem .6rem 1.3rem;
  font-size: .98rem; line-height: 1.2; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; }
.brand-mark .icon { width: 20px; height: 20px; color: #fff; }
.brand small { display: block; font-weight: 400; color: var(--side-text); font-size: .75rem; opacity: .8; }
.nav { display: flex; flex-direction: column; gap: .15rem; }
.nav a, .nav button { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 8px;
  color: var(--side-text); font: inherit; background: none; border: 0; cursor: pointer; width: 100%; text-align: left; }
.nav a:hover, .nav button:hover { background: var(--side-active-bg); color: #fff; text-decoration: none; }
.nav a.active { background: var(--side-active-bg); color: var(--side-active); font-weight: 600; }
.nav-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; opacity: .55; padding: 1rem .7rem .35rem; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .08); padding-top: .8rem; }
.who { display: flex; align-items: center; gap: .6rem; padding: .3rem .7rem .6rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255, 255, 255, .12); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: .85rem; flex: none; }
.who b { color: #fff; font-weight: 600; font-size: .88rem; display: block; line-height: 1.25; }
.who span { font-size: .75rem; opacity: .7; }
.content { padding: 1.6rem 2rem 3rem; max-width: 1240px; width: 100%; }
.menu-toggle { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .6rem .8rem; }
  .brand { padding: .2rem; flex: 1; }
  .brand small { display: none; }
  .menu-toggle { display: inline-flex; background: none; border: 0; color: #fff; padding: .4rem; cursor: pointer; }
  .menu-toggle .icon { width: 24px; height: 24px; }
  .sidebar .nav, .sidebar .side-foot { display: none; width: 100%; }
  .sidebar.open .nav, .sidebar.open .side-foot { display: flex; }
  .sidebar.open .side-foot { flex-direction: column; }
  .content { padding: 1.1rem 16px 2.5rem; }
}

/* ===== Заголовок страницы ===== */
.page-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.3rem; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
.crumbs a { color: var(--muted); }
.subtitle { color: var(--muted); margin-top: .3rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ===== Карточки и сетки ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem; margin-bottom: 1.1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .9rem; }
.card-head h2 { margin: 0; display: flex; align-items: center; gap: .5rem; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1.1rem; align-items: start; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem; margin-bottom: 1.1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: .9rem; margin-bottom: 1.1rem; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .95rem 1.1rem; display: flex; gap: .85rem; align-items: center; }
.tile-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--primary-soft); color: var(--primary); }
.tile-icon.warn { background: var(--warn); color: var(--warn-text); }
.tile-icon.ok { background: var(--ok); color: var(--ok-text); }
.tile-icon.bad { background: var(--bad); color: var(--bad-text); }
.tile b { display: block; font-size: 1.35rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: .85rem; }

a.item-card { display: block; color: inherit; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; transition: border-color .15s, transform .15s; }
a.item-card:hover { border-color: var(--primary); text-decoration: none; transform: translateY(-1px); }
.item-card h3 { margin: 0 0 .25rem; font-size: 1.05rem; }
.item-card .meta { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin-top: .7rem; font-size: .85rem; color: var(--muted); }
.item-card .meta span { display: inline-flex; align-items: center; gap: .3rem; }

/* ===== Таблицы ===== */
.table-wrap { overflow-x: auto; margin: 0 -1.25rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th:first-child, td:first-child { padding-left: 1.25rem; }
th:last-child, td:last-child { padding-right: 1.25rem; }
th { font-weight: 600; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tbody tr:hover td { background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
tr.row-new td { background: color-mix(in srgb, var(--warn) 55%, transparent); }
td.actions-cell { white-space: nowrap; text-align: right; }
td.num { color: var(--muted); width: 2.5rem; }
@media (max-width: 700px) {
  .table-wrap { margin: 0; }
  table.stack, table.stack thead, table.stack tbody, table.stack tr, table.stack td { display: block; }
  table.stack thead { display: none; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: .6rem 0; }
  table.stack td { border: 0; padding: .15rem 0 !important; }
  table.stack td.actions-cell { text-align: left; white-space: normal; padding-top: .4rem !important; }
}

/* ===== Формы ===== */
form.inline { display: inline; }
.stack-form { display: flex; flex-direction: column; gap: .85rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .85rem 1rem; align-items: end; }
.form-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.form-row > input { flex: 1 1 240px; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 500; }
.check { flex-direction: row; align-items: center; gap: .45rem; font-weight: 400; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 9px; padding: .55rem .7rem; width: 100%; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
input[type=radio], input[type=checkbox] { width: auto; accent-color: var(--primary); }
input[type=file] { padding: .45rem; background: var(--surface-2); }
input.copy { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; background: var(--surface-2); }
fieldset { border: 0; padding: 0; margin: 0; }

/* Поле пароля с кнопкой «показать» */
.pw { position: relative; display: block; }
.pw input { padding-right: 2.6rem; }
.pw-toggle { position: absolute; right: .3rem; top: 50%; transform: translateY(-50%); background: none; border: 0;
  color: var(--muted); padding: .35rem; border-radius: 6px; cursor: pointer; display: grid; place-items: center; }
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }
.pw-toggle .icon-hide { display: none; }
.pw.shown .icon-show { display: none; }
.pw.shown .icon-hide { display: inline; }

/* ===== Кнопки ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font: inherit; font-weight: 550;
  cursor: pointer; border: 1px solid var(--primary); background: var(--primary); color: var(--on-primary);
  border-radius: 9px; padding: .55rem 1rem; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--primary); border-color: transparent; padding-left: .5rem; padding-right: .5rem; }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.danger { background: var(--surface); color: var(--bad-text); border-color: color-mix(in srgb, var(--bad-text) 40%, transparent); }
.btn.danger:hover { background: var(--bad); }
.btn.success { background: var(--ok); color: var(--ok-text); border-color: transparent; }
.btn.success:hover { filter: brightness(.97); }
.btn.sm { padding: .3rem .6rem; font-size: .82rem; border-radius: 7px; }
.btn.block { width: 100%; }

/* ===== Сообщения и метки ===== */
.alert { display: flex; gap: .6rem; align-items: flex-start; padding: .75rem .95rem; border-radius: 10px; margin-bottom: 1rem;
  background: var(--ok); color: var(--ok-text); }
.alert.error { background: var(--bad); color: var(--bad-text); }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.alert .icon { margin-top: 2px; }
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 550; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok); color: var(--ok-text); border-color: transparent; }
.badge.warn { background: var(--warn); color: var(--warn-text); border-color: transparent; }
.badge.bad { background: var(--bad); color: var(--bad-text); border-color: transparent; }
.badges { display: flex; flex-wrap: wrap; gap: .4rem; }
.empty { text-align: center; padding: 1.6rem 1rem; color: var(--muted); }
.empty .icon { width: 32px; height: 32px; opacity: .5; margin-bottom: .4rem; }
details.fold > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: .4rem;
  color: var(--primary); font-weight: 550; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold[open] > summary { margin-bottom: .9rem; }
.danger-zone { border-color: color-mix(in srgb, var(--bad-text) 30%, var(--line)); }

/* ===== Индикатор проверки ===== */
.progress-card { border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); }
.progress-card[hidden] { display: none; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: .7rem 0 .45rem; }
.progress > div { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .6s ease; }
.progress-card.done .progress > div { background: var(--ok-text); }
.progress-card.failed .progress > div { background: var(--bad-text); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } .progress > div { transition: none; } }

/* ===== Страница входа ===== */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent),
              radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--primary) 12%, transparent), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .08); padding: 2rem 1.8rem 1.6rem; }
.auth-logo { width: 52px; height: 52px; border-radius: 14px; background: var(--primary); color: #fff; display: grid;
  place-items: center; margin: 0 auto 1rem; }
.auth-logo .icon { width: 28px; height: 28px; }
.auth-card h1 { text-align: center; font-size: 1.35rem; }
.auth-card .lead { text-align: center; color: var(--muted); margin: .35rem 0 1.5rem; font-size: .92rem; }
.auth-foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 1.3rem; }
.field-icon { position: relative; }
.field-icon > .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.field-icon input { padding-left: 2.4rem; }
