:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c222b;
  --border: #2a313c;
  --text: #e6e9ee;
  --text-2: #a3acb9;
  --muted: #6e7887;
  --accent: #5aa9ff;
  --accent-soft: rgba(90, 169, 255, .16);
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f05d5e;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9; --surface: #fff; --surface-2: #f0f2f5; --border: #dfe3e8;
    --text: #1b1f24; --text-2: #4b5563; --muted: #7b8494;
    --accent: #1f6fd1; --accent-soft: rgba(31, 111, 209, .12);
    --good: #1a7f37; --warn: #9a6700; --bad: #cf222e;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
code, pre, .mono { font-family: var(--mono); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.err { color: var(--bad); min-height: 1.2em; margin: 6px 0 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- кнопки и поля ---------- */
.btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; transition: background .15s; }
.btn:hover:not(:disabled) { background: var(--border); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); background: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.icon-btn { background: none; border: 0; color: var(--text-2); cursor: pointer; padding: 2px 6px; border-radius: 6px; font: inherit; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input, select, textarea { background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; color: var(--text-2); margin-bottom: 12px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
.small-input { width: 200px; padding: 4px 8px; font-size: 12px; }
.code-input { font-family: var(--mono); font-size: 20px; letter-spacing: 4px; text-align: center; }

/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-h { font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.form .btn { align-self: flex-start; }
.form { display: flex; flex-direction: column; }

/* ---------- вход ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; }
.auth-card.wide { max-width: 560px; }
.auth-card .btn { margin-top: 4px; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.logo { color: var(--accent); }
.enroll-row { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.qr { width: 200px; height: 200px; background: #fff; border-radius: 8px; padding: 8px; }
.secret { display: block; word-break: break-all; background: var(--bg); padding: 8px; border-radius: 6px; margin: 4px 0 12px; font-size: 12px; }
.recovery { background: var(--bg); padding: 14px; border-radius: 8px; columns: 2; font-size: 15px; line-height: 1.9; }

/* ---------- шапка ---------- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar .brand { margin: 0; }
#nav { display: flex; gap: 4px; }
#nav a { color: var(--text-2); padding: 6px 12px; border-radius: 8px; }
#nav a.active { background: var(--accent-soft); color: var(--accent); }
#nav a:hover { color: var(--text); }
.user { margin-left: auto; display: flex; gap: 10px; align-items: center; color: var(--text-2); }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
body:not(.is-admin) .admin-only { display: none !important; }
body:not(.can-write) .write-only { display: none !important; }

/* ---------- дашборд ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 4px; }
.tile .s { color: var(--text-2); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.status.good { color: var(--good); } .status.warn { color: var(--warn); } .status.bad { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 0 16px; }
.chart { position: relative; height: 160px; }
.chart canvas { width: 100%; height: 100%; display: block; }
.chart .tip { position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; color: var(--text); font-variant-numeric: tabular-nums; }
.chart .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; padding: 10px; }
.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.core .lbl { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s; }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.disk { margin-bottom: 12px; }
.disk .lbl { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.disk .lbl span:last-child { color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- таблицы ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .acts { text-align: right; white-space: nowrap; }
.table td.ua { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; background: var(--surface-2); color: var(--text-2); }
.tag.on { background: var(--accent-soft); color: var(--accent); }
.tag.bad { color: var(--bad); }

/* ---------- файлы ---------- */
.fbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.fbar select { width: auto; }
.fbar input[type=search] { width: 180px; padding: 5px 9px; }
.fbar label { margin: 0; }
.crumbs { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.crumbs a { padding: 3px 6px; border-radius: 6px; color: var(--text-2); }
.crumbs a:hover { background: var(--surface-2); color: var(--text); }
.crumbs a:last-child { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--muted); }
.files td.cb, .files th.cb { width: 28px; }
.files th.fname { width: 60%; }
.table th.num { text-align: right; }
.files .name { display: flex; align-items: center; gap: 8px; cursor: pointer; word-break: break-all; }
.files .name .ic { width: 18px; text-align: center; flex: none; }
.files tr.sel td { background: var(--accent-soft); }
.files tr.blocked { opacity: .5; }
.files tr:hover td { background: var(--surface-2); }
.dropzone { position: relative; border-radius: 8px; }
.dropzone.over { outline: 2px dashed var(--accent); outline-offset: 4px; }
.drop-hint { text-align: center; color: var(--muted); font-size: 12px; padding: 14px; }
.upl { display: flex; gap: 10px; align-items: center; font-size: 12px; margin-bottom: 6px; }
.upl .bar { flex: 1; } .upl .nm { width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- модалка и тосты ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 20; padding: 20px; }
.modal-box { width: 100%; max-width: 640px; max-height: 90vh; overflow: auto; margin: 0; }
.modal-box.wide { max-width: 1000px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 14px; }
.preview-text { background: var(--bg); padding: 12px; border-radius: 8px; max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 12px; margin: 0; }
.preview-img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 6px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface-2); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: 400px; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.toast.bad { border-color: var(--bad); }
.roots-edit textarea { min-height: 90px; font-family: var(--mono); font-size: 12px; }

@media (max-width: 700px) {
  .grid2 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .table .hide-sm { display: none; }
  .topbar { gap: 10px; }
}
