/* 53.5: админка nili. Светлая и тёмная темы, без сборки и внешних ресурсов. */

@font-face {
  font-family: 'Medeo';
  src: url('/MedeoSans-Variable.ttf') format('truetype');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #edeef1;
  --card: #ffffff;
  --card-2: #f6f1f4;
  --text: #14161b;
  --muted: #7a808c;
  --line: #e2e5ea;
  --rose: #c9739f;
  --rose-soft: #f6eaf0;
  --plum: #3e2a4e;
  --plum-2: #6b3555;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --ok: #3f7d3a;
  --ok-soft: #edf5ec;
  --warn: #8a6100;
  --warn-soft: #fdf3dd;
  --shadow: 0 1px 2px rgba(16, 17, 20, .06), 0 10px 30px rgba(16, 17, 20, .08);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0d10;
    --card: #16171c;
    --card-2: #1e2027;
    --text: #edeef2;
    --muted: #9aa0ac;
    --line: #2a2c35;
    --rose: #e3a2c2;
    --rose-soft: #2a1e26;
    --danger: #ff8f87;
    --danger-soft: #2b1a19;
    --ok: #8fce88;
    --ok-soft: #17251a;
    --warn: #e8c26a;
    --warn-soft: #2a2313;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 14px 34px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Medeo', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

img { display: block; }

.only-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .only-light { display: none; }
  .only-dark { display: block; }
}

[hidden] { display: none !important; }

a { color: var(--plum-2); }
@media (prefers-color-scheme: dark) { a { color: var(--rose); } }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- кнопки и поля --------------------------------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  border-radius: 11px;
  padding: 10px 16px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--rose); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: default; }

.btn.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, #3e2a4e 0%, #6b3555 55%, #d88eb8 130%);
}
.btn.primary:hover { filter: brightness(1.08); }

.btn.ghost { background: transparent; }

.btn.danger {
  border-color: transparent;
  color: var(--danger);
  background: var(--danger-soft);
}
.btn.danger:hover { border-color: var(--danger); }

.btn.small { padding: 7px 12px; border-radius: 9px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 10px; }

.field {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 14px;
}
.field input, .search, select {
  width: 100%;
  margin-top: 6px;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 400;
  outline: none;
}
.field input:focus, .search:focus, select:focus { border-color: var(--rose); }
select { width: auto; margin: 0; padding: 9px 11px; }

.error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* --- вход ------------------------------------------------------------ */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 14px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 30px 30px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}
.login-brand img { width: auto; height: 26px; }

.login-card h1 { margin: 20px 0 4px; font-size: 26px; line-height: 1.2; }
.login-card > .muted { margin: 0 0 10px; font-size: 14px; }
.code-hint { margin: 0 0 4px; font-size: 14px; }

.enroll {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  font-size: 13px;
}
.enroll p { margin: 0 0 10px; }
.enroll code {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  font-family: Consolas, 'Courier New', monospace;
  font-size: 13px;
  letter-spacing: 1px;
  overflow-wrap: anywhere;
  user-select: all;
}
.enroll .link { display: inline-block; margin-top: 10px; font-size: 13px; }

/* --- шапка ----------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand img { width: auto; height: 24px; }
.brand-tail {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  padding-left: 9px;
  border-left: 1px solid var(--line);
}

.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wrap { max-width: 1440px; margin: 0 auto; padding: 22px 24px 60px; }

/* --- сводка ---------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.stat b { display: block; font-size: 23px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat.warn b { color: var(--warn); }

/* --- поиск и фильтры ------------------------------------------------- */

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.search { flex: 1 1 320px; max-width: 560px; margin: 0; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { border-color: var(--rose); }
.chip.active { background: var(--plum); border-color: var(--plum); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.active { background: var(--rose); color: #1a1118; border-color: var(--rose); } }

/* --- список и карточка ----------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 460px);
  gap: 16px;
  align-items: start;
}

.list-pane { min-width: 0; }

.list { display: flex; flex-direction: column; gap: 8px; }

.user-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .05s;
}
.user-row:hover { border-color: var(--rose); }
.user-row.selected { border-color: var(--rose); background: var(--rose-soft); }
.user-row:active { transform: translateY(1px); }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--rose-soft);
  color: var(--plum-2);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  overflow: hidden;
  flex: none;
}
@media (prefers-color-scheme: dark) { .avatar { color: var(--rose); } }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 64px; height: 64px; font-size: 22px; }

.user-line { min-width: 0; }
.user-name { font-weight: 700; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; min-width: 0; }
.user-name .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.user-sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.badges { display: flex; flex-wrap: wrap; gap: 5px; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.admin { background: var(--rose-soft); color: var(--plum-2); }
.badge.block1 { background: var(--warn-soft); color: var(--warn); }
.badge.block2 { background: var(--danger-soft); color: var(--danger); }
.badge.deleted { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
@media (prefers-color-scheme: dark) { .badge.admin { color: var(--rose); } }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 2px 0; }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

/* --- карточка пользователя ------------------------------------------ */

.detail {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  position: sticky;
  top: 74px;
  max-height: calc(100vh - 92px);
  overflow: auto;
}

.detail-head { display: flex; gap: 14px; align-items: flex-start; }
.detail-head .title { min-width: 0; flex: 1; }
.detail-head h2 { margin: 2px 0 2px; font-size: 21px; line-height: 1.25; overflow-wrap: anywhere; }
.detail-head .close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
.detail-head .close:hover { color: var(--text); }

.id-line { margin-top: 8px; font-family: Consolas, monospace; font-size: 11.5px; color: var(--muted); overflow-wrap: anywhere; }
.id-line button { border: 0; background: transparent; color: var(--rose); cursor: pointer; font-size: 11.5px; padding: 0 0 0 6px; }

.meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin: 14px 0 0;
}
.meta div { background: var(--card-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.meta b { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.meta span { font-size: 13px; overflow-wrap: anywhere; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 6px; }
.actions .group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.actions select { max-width: 210px; }

.card {
  border: 1px solid var(--line);
  border-radius: 13px;
  margin-top: 12px;
  background: var(--card);
  overflow: hidden;
}
.card > summary {
  cursor: pointer;
  padding: 11px 14px;
  font-weight: 700;
  font-size: 14px;
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary .count { color: var(--muted); font-weight: 600; font-size: 12px; }
.card > summary:hover { background: var(--card-2); }
.card .body { padding: 0 14px 12px; }

.item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
  align-items: baseline;
}
.item:first-child { border-top: 0; }
.item .left { min-width: 0; overflow-wrap: anywhere; }
.item .right { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.item .right.wrap { white-space: normal; }
.item .name { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 12px; }

.empty-line { color: var(--muted); font-size: 13px; padding: 8px 0; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* --- служебные ------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: min(92vw, 560px);
  background: var(--plum);
  color: #fff;
  padding: 11px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  font-size: 14px;
}
.toast.error { background: var(--danger); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 14, .55);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}
.modal-card {
  width: min(440px, 100%);
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}
.modal-card h2 { margin: 0 0 6px; font-size: 20px; }
.modal-card p { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.spinner { color: var(--muted); text-align: center; padding: 28px 10px; }

/* --- адаптив --------------------------------------------------------- */

@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .detail {
    position: fixed;
    inset: 0;
    z-index: 30;
    border-radius: 0;
    max-height: none;
    padding: 18px 16px 40px;
    overflow: auto;
  }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .brand-tail { display: none; }
  .wrap { padding: 16px 14px 50px; }
  .search { flex-basis: 100%; max-width: none; }
  .user-row { grid-template-columns: 38px minmax(0, 1fr); }
  .user-row .user-side { grid-column: 2; flex-direction: row; align-items: center; justify-content: flex-start; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kv { grid-template-columns: 100px 1fr; }
}
