:root {
  --bg: #141416;
  --side: #111113;
  --card: #1c1c20;
  --field: #1f1f23;
  --hover: #232328;
  --border: #2a2a30;
  --border-hi: #3a3a42;
  --text: #f4f4f5;
  --muted: #9b9ba3;
  --faint: #6b6b73;
  --primary: #f4f4f5;
  --on-primary: #111113;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --red-bg: #2b1a1c;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 24px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }

/* ---------- каркас ---------- */
.layout { display: flex; min-height: 100vh; }
.side {
  width: 240px; flex: none; background: var(--side); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 22px 14px; position: sticky; top: 0; height: 100vh;
}
.side .logo { height: 30px; margin: 0 8px 26px; align-self: flex-start; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.nav .sep { font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--faint); padding: 18px 12px 6px; text-transform: uppercase; }
.nav svg { width: 17px; height: 17px; flex: none; }
.client-box { margin-top: auto; padding: 14px 0 12px; display: flex; flex-direction: column; gap: 6px; }
.client-box[hidden] { display: none; }
.client-dl { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border-hi); background: var(--card); color: var(--text); text-decoration: none; }
.client-dl:hover { background: var(--hover); }
.client-dl svg { width: 18px; height: 18px; flex: none; color: var(--primary); }
.client-dl span { display: flex; flex-direction: column; min-width: 0; }
.client-dl b { font-size: 13px; font-weight: 600; }
.client-dl small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-dl.off { opacity: .6; border-style: dashed; }
.client-up { font-size: 12px; color: var(--muted); cursor: pointer; padding: 0 12px; }
.client-up:hover { color: var(--text); }
.side .client-box:not([hidden]) + .foot { margin-top: 0; }
.side .foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--border); font-size: 13px; }
.side .who { font-weight: 600; }
.side .who small { display: block; color: var(--faint); font-weight: 400; }
.side .foot .links { display: flex; gap: 14px; margin-top: 10px; }
.side .foot .links a { color: var(--muted); text-decoration: none; cursor: pointer; }
.side .foot .links a:hover { color: var(--text); }
.side .ver { color: var(--faint); font-size: 12px; margin-top: 10px; }

.main { flex: 1; min-width: 0; padding: 30px 40px 60px; max-width: 1240px; }
.head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head .grow { flex: 1; }
.head .sub { color: var(--muted); margin-top: 2px; }
.back { color: var(--muted); text-decoration: none; font-size: 13px; display: inline-block; margin-bottom: 10px; }
.back:hover { color: var(--text); }

/* ---------- элементы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--border-hi);
  background: #26262b; color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #303036; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn-primary:hover { background: #fff; }
.btn-danger { background: var(--red-bg); color: #ff8a8a; border-color: #4a2428; }
.btn-danger:hover { background: #3a1f23; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }

.input, select.input, textarea.input {
  height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--field); outline: none; width: 100%; transition: border-color .12s;
}
textarea.input { height: auto; padding: 8px 12px; resize: vertical; }
.input:focus { border-color: #d4d4d8; }
.input::placeholder { color: var(--faint); }
.mono { font-family: Consolas, "Cascadia Mono", ui-monospace, monospace; }
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .03em; margin-bottom: 6px; }
.hint { color: var(--faint); font-size: 12px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; margin: 6px 0; }
.check input { width: 16px; height: 16px; accent-color: #e4e4e7; margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .input { width: auto; min-width: 220px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.section + .section { margin-top: 18px; }
:not(.grid2) > .card + .card { margin-top: 18px; }
.section { margin-top: 26px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.kv { display: grid; grid-template-columns: 170px 1fr; row-gap: 8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-all; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 11px;
  font-size: 12px; font-weight: 600; background: #26262b; color: var(--muted); margin: 0 4px 4px 0; white-space: nowrap;
}
.chip.ok { background: rgba(52,211,153,.12); color: var(--green); }
.chip.warn { background: rgba(251,191,36,.12); color: var(--amber); }
.chip.err { background: rgba(248,113,113,.13); color: var(--red); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* таблицы */
.table-wrap { border: 1px solid var(--border); border-radius: 12px; overflow: auto; background: var(--card); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--faint); letter-spacing: .03em; background: #18181b; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td, tbody tr:hover td { background: #202025; }
td .sub { color: var(--faint); font-size: 12px; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.act { text-align: right; white-space: nowrap; }
.empty { color: var(--faint); padding: 34px; text-align: center; }

/* файлы */
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 15px; margin-bottom: 14px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.crumbs .cur { font-weight: 600; }
.crumbs .slash { color: var(--faint); }
.fname { display: flex; align-items: center; gap: 10px; }
.fname svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.fname.dir svg { color: #c7c7cc; }

/* модалки и уведомления */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; z-index: 50; overflow: auto; }
.modal { background: var(--card); border: 1px solid var(--border-hi); border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal.wide { max-width: 720px; }
.modal.xwide { max-width: 1080px; }
.modal header { padding: 18px 22px 0; font-size: 17px; font-weight: 600; }
.modal .body { padding: 18px 22px; }
.modal footer { padding: 14px 22px 18px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--border); }
.modal .err { color: var(--red); margin-top: 6px; min-height: 0; }
.keybox { font-family: Consolas, ui-monospace, monospace; font-size: 20px; letter-spacing: .04em; background: var(--field);
  border: 1px solid var(--border-hi); border-radius: 10px; padding: 16px; text-align: center; user-select: all; margin: 6px 0 12px; }
.warnbox { background: rgba(251,191,36,.08); border: 1px solid rgba(251,191,36,.25); color: #f5d27a; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.assign { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #19191d; }
.assign .groups { display: flex; flex-wrap: wrap; gap: 2px 16px; margin-top: 6px; }
.perm-group { margin-bottom: 14px; }
.perm-group .t { font-size: 12px; font-weight: 600; color: var(--faint); letter-spacing: .04em; text-transform: uppercase; margin-bottom: 4px; }

#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #26262b; border: 1px solid var(--border-hi); border-radius: 10px; padding: 11px 16px; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.err { border-color: #5a2a2e; color: #ffb4b4; }
.toast.ok { border-color: #1f4d3c; color: #a7f3d0; }

/* вход */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 30px 28px; }
.login .logo { height: 36px; display: block; margin: 0 auto 26px; }
.login .btn { width: 100%; height: 42px; margin-top: 6px; }
.login .err { color: var(--red); min-height: 21px; margin-top: 10px; text-align: center; }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border-hi); border-top-color: var(--text); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 30px 4px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; align-items: center; padding: 12px 16px; gap: 14px; overflow-x: auto; }
  .side .logo { margin: 0; height: 24px; }
  .nav { flex-direction: row; }
  .nav .sep { display: none; }
  .side .foot { margin: 0 0 0 auto; border: 0; padding: 0; white-space: nowrap; }
  .side .who, .side .ver { display: none; }
  .side .foot .links { margin: 0; }
  .main { padding: 22px 16px 50px; }
  .kv { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .fname span { white-space: nowrap; }
  th, td { padding: 10px; }
}

/* 1.3: хранилища, просмотр файлов */
.mb { margin-bottom: 12px; }
.mt { margin-top: 12px; }
.grow { flex: 1; }
.break { word-break: break-all; }
.err-text { color: var(--red); }
.kv.sm { grid-template-columns: 150px 1fr; row-gap: 4px; margin-top: 12px; font-size: 13px; }
.card h2 { margin: 0; }
.card .row svg { width: 18px; height: 18px; color: var(--muted); }
textarea.viewer { height: 62vh; min-height: 260px; margin: 10px 0 8px; font-size: 13px; line-height: 1.55; white-space: pre; overflow: auto; tab-size: 4; resize: vertical; padding: 12px 14px; background: #161619; }
textarea.viewer[readonly] { cursor: default; }
textarea.viewer.editing { border-color: #d4d4d8; background: var(--field); }
.progress { height: 6px; border-radius: 3px; background: #2a2a30; overflow: hidden; min-width: 140px; margin-bottom: 4px; }
.progress .bar { height: 100%; width: 0; background: var(--green); transition: width .4s; }
.seg { display: inline-flex; background: var(--field); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; }
.seg-btn { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 7px; cursor: pointer; font-weight: 600; }
.seg-btn.on { background: #303036; color: var(--text); }
.warnbox.mb { margin-bottom: 14px; }

/* 1.4.0: роли - квадратные плитки */
.grid2 { align-items: start; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.role-card { all: unset; box-sizing: border-box; aspect-ratio: 1 / 1; display: flex; flex-direction: column; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; overflow: hidden;
  transition: border-color .12s, background .12s; }
.role-card:hover { border-color: var(--border-hi); background: #202025; }
.role-card:focus-visible { outline: 2px solid #d4d4d8; outline-offset: 2px; }
.role-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.role-icon { width: 36px; height: 36px; border-radius: 10px; background: #26262b; display: inline-flex; align-items: center; justify-content: center; }
.role-icon svg { width: 18px; height: 18px; color: var(--text); }
.role-users { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 600; }
.role-users svg { width: 14px; height: 14px; }
.role-name { font-weight: 600; font-size: 15px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.role-desc { color: var(--muted); font-size: 12px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.role-perms { margin-top: auto; padding-top: 10px; display: flex; flex-wrap: wrap; gap: 4px; }
.role-perms .chip { margin: 0; font-size: 11px; height: 20px; padding: 0 7px; }
/* 1.5.0: устаревший тип подключения - оранжевая рамка */
.chip.legacy { background: rgba(249,115,22,.08); color: #fdba74; border: 1px solid #f97316; height: 20px; margin-left: 8px; }
.section .chip.legacy, dd .chip.legacy { margin-left: 0; }
.chip.legacy-pc { border: 1px solid rgba(249,115,22,.5); color: var(--text); background: transparent; }
.chip.legacy-pc svg { width: 12px; height: 12px; color: #fdba74; }
.row-tight { display: flex; align-items: center; flex-wrap: wrap; gap: 0; }
/* постраничный вывод */
.pager > .grow { flex: 1; }
.pager { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.input.pager-size, select.input.pager-size { width: auto; flex: none; min-width: 150px; height: 32px; padding: 0 8px; font-size: 13px; }
.pager-nums { display: flex; gap: 4px; align-items: center; }
.pager-btn { min-width: 32px; padding: 0 8px; }
.pager-btn.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); opacity: 1; }
.pager-gap { color: var(--faint); padding: 0 2px; }
/* цвет групп */
.group-chip.colored { background: color-mix(in srgb, var(--gc) 16%, transparent); color: color-mix(in srgb, var(--gc) 70%, white); border: 1px solid color-mix(in srgb, var(--gc) 45%, transparent); }
.group-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gc); }
.group-desc { margin-top: 2px; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--card), 0 0 0 4px rgba(255,255,255,.35); }
.swatch.none { background: repeating-linear-gradient(45deg, #2a2a30 0 4px, #1f1f23 4px 8px); }
.swatch-custom { width: 34px; height: 28px; border: 1px solid var(--border-hi); border-radius: 8px; background: var(--field); padding: 2px; cursor: pointer; }
.import-list { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: #19191d; margin-top: 4px; }
.import-list .check { margin: 4px 0; }
.check.dim { opacity: .5; }

/* 1.4.1: виртуальный просмотрщик больших файлов */
.vt { height: 62vh; min-height: 260px; overflow: auto; position: relative; margin: 8px 0; background: #161619;
  border: 1px solid var(--border); border-radius: 8px; font: 13px/20px Consolas, "Cascadia Mono", ui-monospace, monospace; outline: none; }
.vt-spacer { width: 1px; }
.vt-body { position: absolute; top: 0; left: 0; min-width: 100%; }
.vt-line { display: flex; height: 20px; white-space: pre; }
.vt-line.hit { background: rgba(251,191,36,.16); }
.vt-n { position: sticky; left: 0; flex: none; width: var(--gw, 4ch); padding: 0 12px 0 8px; box-sizing: content-box; text-align: right;
  color: var(--faint); background: #161619; user-select: none; border-right: 1px solid var(--border); margin-right: 10px; }
.vt-line.hit .vt-n { color: var(--amber); }
.vt-t { padding-right: 20px; }
.vt-cut { color: var(--faint); font-style: italic; }
.vt-tools { margin-top: 8px; }
.vt-tools .btn-sm { height: 34px; }
.vt-search { width: 260px; height: 34px; }
/* 1.7.0: версии клиента */
.infobox { border: 1px solid var(--border); background: var(--card); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.infobox b { color: var(--text); }
.notes-cell { max-width: 360px; white-space: pre-wrap; font-size: 13px; }
.client-box a.client-dl.off { cursor: pointer; }
td.nowrap .row-tight { flex-wrap: nowrap; white-space: nowrap; }
td.nowrap .chip { margin-left: 8px; }
