/* Admin panel: reuses assets/css/style.css tokens (colors/spacing/type/depth)
   — this is the same grimoire world, just its workbench rather than its
   reading room, so density is tighter and structure leans on tables/lists
   instead of cards. */

.admin-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: calc(100vh - var(--header-h));
  background: linear-gradient(115deg, rgba(141, 92, 245, 0.035), transparent 34%);
}

.admin-nav {
  border-right: 1px solid var(--line);
  padding: var(--sp-6) var(--sp-4);
  position: sticky; top: var(--header-h); align-self: start;
  height: calc(100vh - var(--header-h)); overflow-y: auto;
  /* Keep the rail scrollable without leaving a bright browser-owned bar in
     the middle of the reading/work surface. The focus/keyboard scroll path
     remains intact; the active section and drawer affordance communicate
     where the user is. */
  scrollbar-width: none;
  background: rgba(18, 11, 30, 0.42);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.admin-nav::-webkit-scrollbar { width: 0; height: 0; }
.admin-nav__group { margin-bottom: var(--sp-6); }
.admin-nav__label { font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-400); padding: 0 var(--sp-3); margin-bottom: var(--sp-2); }
.admin-nav a {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--text-300);
  font-size: var(--fs-small);
  font-weight: 500;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.admin-nav a:hover { color: var(--text-100); background: rgba(141, 92, 245, 0.1); }
.admin-nav a:active { transform: scale(0.98); }
.admin-nav a.is-active { color: var(--text-100); background: rgba(141, 92, 245, 0.16); box-shadow: inset 2px 0 0 var(--violet-400); }
.admin-nav-toggle, .admin-nav-scrim { display: none; }
.admin-nav-toggle[hidden], .admin-nav-scrim[hidden], .admin-nav[hidden] { display: none !important; }
.admin-nav[hidden] + .admin-main { grid-column: 1 / -1; }

.admin-main { min-width: 0; padding: var(--sp-6) var(--sp-7) var(--sp-9); max-width: 1120px; width: 100%; }
.admin-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-6); padding-bottom: var(--sp-5); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.admin-header h1 { font-size: var(--fs-h1); }
.admin-header p { color: var(--text-400); font-size: var(--fs-small); margin-top: var(--sp-1); }

/* ---- dashboard stat tiles ---- */
.admin-focus {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-5);
  margin-bottom: var(--sp-5); padding: var(--sp-5) var(--sp-6);
  background: linear-gradient(135deg, rgba(116, 64, 221, 0.18), var(--ink-800));
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.admin-focus h2 { font: 700 var(--fs-h4)/1.35 var(--font-body); color: var(--text-100); }
.admin-focus p { margin-top: var(--sp-1); color: var(--text-400); font-size: var(--fs-small); }
.admin-focus p strong { color: var(--gold-300); font-variant-numeric: tabular-nums; }
.admin-focus .btn { flex: none; white-space: nowrap; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-7); }
.stat-tile {
  background: linear-gradient(160deg, var(--ink-700), var(--ink-800));
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), background var(--dur-base) var(--ease);
}
.stat-tile__value { font-family: var(--font-display); font-size: 2rem; color: var(--text-100); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-tile__of { font-size: 1.1rem; color: var(--text-500); }
.stat-tile__label { font-size: var(--fs-small); color: var(--text-400); margin-top: var(--sp-1); }
.stat-tile--link {
  display: block;
  transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.stat-tile--link:hover { border-color: var(--violet-400); }
.stat-tile--link:hover { transform: translateY(-2px); }
.stat-tile--link:active { transform: translateY(0) scale(0.98); }

.admin-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); }
@media (max-width: 860px) { .admin-panels { grid-template-columns: minmax(0, 1fr); } }
.admin-panel {
  min-width: 0;
  background: linear-gradient(160deg, var(--ink-700), var(--ink-800));
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  box-shadow: var(--shadow-md);
}
.admin-panel h2 { font-size: var(--fs-h4); font-family: var(--font-body); font-weight: 700; margin-bottom: var(--sp-4); }
.admin-panel ul { list-style: none; display: flex; flex-direction: column; gap: var(--sp-3); }
.admin-panel li { display: flex; min-width: 0; align-items: baseline; justify-content: space-between; gap: var(--sp-3); font-size: var(--fs-small); border-bottom: 1px solid var(--line); padding-bottom: var(--sp-3); }
.admin-panel li > :first-child { min-width: 0; overflow-wrap: anywhere; }
.admin-panel li:last-child { border-bottom: none; padding-bottom: 0; }
.admin-panel .num { font-variant-numeric: tabular-nums; color: var(--text-300); font-weight: 600; }
/* A settings row that reads as "first of a list" even when it's currently
   the only one — the bottom divider is deliberately not conditional on
   :last-child (unlike .admin-panel li above) so a lone setting still
   invites more to be added below it later. */
.admin-panel__row { border-bottom: 1px solid var(--line); padding-bottom: var(--sp-4); }
.admin-empty { color: var(--text-400); font-size: var(--fs-small); }

/* ---- guides list ---- */
.admin-table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }
.admin-table th { text-align: left; color: var(--text-400); font-weight: 600; font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.05em; padding: var(--sp-3); border-bottom: 1px solid var(--line-strong); }
.admin-table td { padding: var(--sp-3); border-bottom: 1px solid var(--line); vertical-align: middle; transition: background var(--dur-fast) var(--ease); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: rgba(141, 92, 245, 0.055); }
.admin-table .guide-title-cell { display: flex; align-items: center; gap: var(--sp-3); }
.admin-table .guide-swatch { width: 28px; height: 28px; border-radius: var(--radius-sm); flex: none; display: flex; align-items: center; justify-content: center; }
.admin-table .guide-swatch svg { width: 16px; height: 16px; }
.row-actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

/* .badge base + .badge--role live in style.css — shared with the public
   guide-author credit, not just this admin panel. */
.badge--published { color: #7fd99a; background: rgba(102, 176, 127, 0.16); }
.badge--draft { color: var(--text-400); background: rgba(255,255,255,0.06); }
/* Generic "needs attention" pill (pending-submissions count, etc.) — not a
   role badge, see style.css's .badge--role for those. */
.badge--staff { color: var(--gold-400); background: rgba(226, 186, 107, 0.14); }

.visibility-lock { display: inline-flex; vertical-align: -3px; color: var(--gold-400); opacity: 0.85; }
.visibility-lock svg { width: 14px; height: 14px; }

.accent-color-warning:not([hidden]) { display: block; margin-top: var(--sp-2); color: #ff9494; }

/* ---- ajax confirm modal (replaces window.confirm on destructive forms) ---- */
.confirm-dialog__message { color: var(--text-300); font-size: var(--fs-small); margin-bottom: var(--sp-4); }
.confirm-dialog__input { width: 100%; margin-bottom: var(--sp-4); }
.confirm-dialog [data-ok]:disabled { opacity: 0.4; cursor: default; }

/* ---- inline ajax feedback — no toast component: a failed action flashes
   the row/element it happened in and drops a short-lived note next to it.
   Same 1.1s exception as style.css's card-flash-error: an alert cue needs
   longer than the usual ≤300ms direct-feedback budget to actually register. ---- */
@keyframes row-flash-error {
  0%, 100% { background: transparent; }
  30% { background: rgba(255, 90, 90, 0.16); }
}
.flash-error { animation: row-flash-error 1.1s ease; }
.row-inline-error { display: block; margin-top: var(--sp-1); font-size: var(--fs-meta); color: #ff9494; }

.icon-btn:disabled, .btn--sm:disabled, .btn:disabled { opacity: 0.5; cursor: default; pointer-events: none; }

.icon-btn, .btn--sm {
  font: inherit;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: var(--sp-1);
  /* Vertical padding bumped from --sp-1 (4px) to --sp-2 (8px) — every admin
     table row's action buttons (reorder arrows, Изменить/Удалить/etc.) were
     rendering at roughly 23-30px tall, well under the ~44px minimum touch
     target these pages need since they're fully responsive with a mobile
     nav, not desktop-only. */
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-meta);
  font-weight: 600;
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.02);
  color: var(--text-300);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.icon-btn:hover, .btn--sm:hover { color: var(--text-100); border-color: var(--violet-400); }
.icon-btn:active, .btn--sm:active { transform: scale(0.96); }
/* Irreversible actions ("Удалить", "Удалить навсегда") previously matched
   every other button until hover — no resting-state cue, and no cue at all
   on touch. Same red already used for row-flash-error/row-inline-error, so
   this reads as "the site's one danger color" rather than a new one. */
.btn--sm.danger { color: #ff9494; border-color: rgba(226, 99, 107, 0.35); background: rgba(226, 99, 107, 0.07); }
.btn--sm.danger:hover { color: #ffb3b3; border-color: var(--acc-blood-magic); background: rgba(226, 99, 107, 0.14); }
.move-form { display: inline; }

/* ---- users table: role picker ---- */
.role-form { display: inline-flex; align-items: center; gap: var(--sp-2); }
.form-select--sm {
  font: inherit;
  cursor: pointer;
  background: var(--ink-900);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--fs-meta);
  color: var(--text-300);
  transition: border-color var(--dur-fast) var(--ease);
}
.form-select--sm:focus { border-color: var(--violet-400); }

/* ---- editor ---- */
.editor-grid { display: grid; grid-template-columns: 1fr 300px; gap: var(--sp-6); align-items: start; }
/* A 240px admin rail + 300px metadata rail leaves a false-narrow writing
   column on normal 1280–1440px laptops. Stack metadata before the authored
   page would fall below its real 780px reading measure; on wide displays it
   stays conveniently alongside the document. */
@media (max-width: 1480px) { .editor-grid { grid-template-columns: 1fr; } }
.editor-main { min-width: 0; }
.editor-side { display: flex; flex-direction: column; gap: var(--sp-4); }

.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: var(--sp-2); }
.icon-picker label {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--ink-900); color: var(--text-400);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.icon-picker label:active { transform: scale(0.94); }
.icon-picker input { position: absolute; opacity: 0; pointer-events: none; }
.icon-picker input:checked + label,
.icon-picker label:has(input:checked) { border-color: var(--violet-400); color: var(--violet-300); background: rgba(141,92,245,0.12); }
.icon-picker input:focus-visible + label { outline: 2px solid var(--violet-400); outline-offset: 2px; }
.icon-picker svg { width: 18px; height: 18px; }

.checkbox-row { display: flex; align-items: center; gap: var(--sp-2); }
.checkbox-row input { width: 16px; height: 16px; }
.checkbox-row label { font-size: var(--fs-small); color: var(--text-300); }

/* Modal chrome shared by every dialog built on it — currently just
   confirmDialog (assets/admin.js) — kept under its original "size-picker"
   name from the EasyMDE-era picker this shell was first built for, rather
   than a churn-only rename now that it's the only caller. */
.size-picker-backdrop {
  position: fixed; inset: 0; background: rgba(6,3,10,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-in);
}
.size-picker-backdrop.is-open { opacity: 1; pointer-events: auto; transition-timing-function: var(--ease); }
.size-picker {
  background: linear-gradient(160deg, var(--ink-700), var(--ink-800));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  width: min(420px, 90vw);
  transform: scale(0.95); opacity: 0;
  transition: transform var(--dur-base) var(--ease-in), opacity var(--dur-base) var(--ease-in);
}
.size-picker-backdrop.is-open .size-picker { transform: scale(1); opacity: 1; transition-timing-function: var(--ease); }
.size-picker h3 { font-size: var(--fs-h4); font-family: var(--font-body); font-weight: 700; margin-bottom: var(--sp-4); }
/* ---- co-author / author-reassign search picker ---- */
.user-picker { position: relative; }
.user-picker__chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.user-picker__chips:empty { display: none; }
.user-chip {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: 2px var(--sp-1) 2px var(--sp-3);
  border-radius: 999px;
  background: rgba(141, 92, 245, 0.14);
  border: 1px solid var(--line-strong);
  color: var(--text-200, var(--text-300));
  font-size: var(--fs-small);
}
.user-chip button {
  position: relative;
  font: inherit; cursor: pointer; line-height: 1;
  width: 20px; height: 20px; border-radius: 50%;
  border: none; background: none; color: var(--text-400);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
/* Same expanded-hit-area technique as .img-widget__handle — 20px visible
   chip stays compact, 40px minimum tap target underneath. */
.user-chip button::before { content: ""; position: absolute; inset: -10px; }
.user-chip button:hover { background: rgba(255,255,255,0.1); color: var(--text-100); }
.user-picker__results {
  position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin-top: var(--sp-1);
  background: linear-gradient(160deg, var(--ink-700), var(--ink-800));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 220px; overflow-y: auto;
}
.user-picker__item {
  display: block; width: 100%; text-align: left; font: inherit; cursor: pointer;
  padding: var(--sp-2) var(--sp-3);
  border: none; background: none; color: var(--text-300);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.user-picker__item:hover { background: rgba(141, 92, 245, 0.12); color: var(--text-100); }
.user-picker__status { padding: var(--sp-2) var(--sp-3); color: var(--text-500); font-size: var(--fs-small); }

/* ---- custom roles (views/admin/settings.ejs, role-editor.ejs) ----
   --accent set inline per role from its stored color, same convention as
   guide/folder cards (assets/css/style.css's .card --accent). Background
   is still the required ink-700→ink-800 diagonal gradient (DESIGN.md's
   Gradient-Not-Flat rule) — the accent only tints each stop, it never
   replaces the gradient with a flat color-mix fill. */
.role-list { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-5); }
/* One row = drag handle + the pill itself (flex: 1, so its own gradient/
   click target stay full width) + up/down move buttons — kept as siblings
   rather than nested inside .role-pill's <a>, since a <button>/<form>
   can't legally nest inside an anchor. wireReorderableList in admin.js
   drag-reorders these against POST /admin/settings/roles/reorder; the
   move buttons are the keyboard/no-JS path to the same endpoint's sibling,
   POST .../roles/:id/move — same pattern as folders-table's rows. */
.role-row { display: flex; align-items: center; gap: var(--sp-2); }
.role-row .role-pill { flex: 1; }
/* Plain glyph, no icon-btn border/box — this isn't a discrete action
   (dragging the row is, via .role-row[draggable]), just a quiet grab
   affordance, so it shouldn't compete with the pill's own gradient. */
.role-row__handle { cursor: grab; flex: none; color: var(--text-500); padding: var(--sp-2); border: none; background: none; }
.role-row__handle:active { cursor: grabbing; }
/* Up/down as one bordered unit instead of two separate .icon-btn boxes —
   same two actions, one visual shape, less clutter next to the pill. */
.role-row__move { display: flex; flex: none; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.role-row__move .icon-btn { border: none; border-radius: 0; background: none; padding: var(--sp-2) var(--sp-3); }
.role-row__move .move-form:first-child .icon-btn { border-right: 1px solid var(--line-strong); }
.role-pill {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 14%, var(--ink-700)), color-mix(in srgb, var(--accent) 7%, var(--ink-800)));
  transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.role-pill:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line-strong)); }
.role-pill:active { transform: scale(0.99); }
.role-pill__dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); flex: none; }
.role-pill__name { font-weight: 600; color: var(--text-100); }
.role-pill__meta { color: var(--text-400); font-size: var(--fs-small); margin-left: auto; white-space: nowrap; }
.role-create-form { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.role-create-form .form-input { flex: 1; min-width: 180px; }
.role-color-input {
  width: 44px; height: 38px; padding: 2px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--ink-800); cursor: pointer;
}

/* ---- role editor (views/admin/role-editor.ejs) ----
   Name + color + a live preview sit in one row so changing either input
   shows its real effect immediately (admin.js's "live badge preview"
   wiring) — the preview IS a .badge--role, not a lookalike, so what you
   see here is exactly what renders on /admin/users and the public guide
   credit. */
.role-editor-head { display: flex; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.role-editor-head .form-field { margin-bottom: 0; }
.role-editor-head__name { flex: 1; min-width: 180px; }
.role-editor-preview { display: flex; flex-direction: column; gap: var(--sp-2); align-items: flex-start; }
.role-permission-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.role-permission-row { align-items: flex-start; gap: var(--sp-2); }
.role-permission-row__label { display: block; color: var(--text-100); }
/* Same fixed-permission-key convention .form-notice already uses elsewhere
   (e.g. auth pages) — reused here rather than inventing a second "this
   matters" visual language for one checkbox. */
.role-permission-notice { margin: var(--sp-1) 0 0; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-meta); }
.role-members { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
/* Hairline divider instead of a boxed-off "danger zone" — DESIGN.md's own
   restraint rule (danger stays visible at rest, but isn't a bigger red
   panel than the action itself warrants). */
.role-danger-zone { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--line); }

/* ---------------------------------------------------------------------
   Responsive — .admin-shell had no mobile breakpoint at all: the 240px
   sidebar never collapsed, leaving ~90-150px of usable width on a phone on
   every one of the 10 admin pages (they all share this shell). Same
   off-canvas-drawer technique already used for the guide page's TOC
   sidebar (assets/css/style.css's .sidebar/.mobile-toc-toggle/
   .sidebar-scrim) — distinct classes because .admin-nav lives in a
   different grid (.admin-shell, not .guide-layout) with its own resting
   styles, but the same mechanism: fixed off-canvas panel, translateX,
   scrim, .is-open toggle.
   --------------------------------------------------------------------- */
@media (max-width: 860px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-main { padding: var(--sp-5) var(--sp-4); }
  .admin-focus { align-items: flex-start; flex-direction: column; padding: var(--sp-4); }
  .admin-nav-toggle {
    display: flex; align-items: center; gap: var(--sp-2);
    width: 100%; margin-bottom: var(--sp-5);
    background: var(--ink-700); border: 1px solid var(--line-strong);
    padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-md);
    color: var(--text-300); font-size: var(--fs-small); font-weight: 600;
  }
  .admin-nav {
    position: fixed; inset: var(--header-h) auto 0 0; width: min(280px, 82vw);
    background: var(--ink-900); border-right: 1px solid var(--line);
    height: calc(100vh - var(--header-h)); overflow-y: auto;
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-in);
    z-index: 95;
    box-shadow: var(--shadow-lg);
  }
  .admin-nav.is-open { transform: translateX(0); transition-timing-function: var(--ease); }
  .admin-nav-scrim {
    display: none; position: fixed; inset: 0; background: rgba(6,3,10,0.6); z-index: 94;
  }
  .admin-nav-scrim.is-open { display: block; }
}

@media (max-width: 540px) {
  .stat-grid { grid-template-columns: 1fr; }
}
