/*
    Оформление CMS. Порядок разделов: токены, база, каркас, типографика,
    сообщения, формы, таблицы, компоненты страниц, вход, адаптив, тёмная тема.

    Размеры кратны 4px, цвета берутся только из переменных: так тёмная тема
    получается сама и правки не расползаются по файлу.
*/

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
    margin: 0;
    font: 13px/1.45 var(--sans);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--info); text-decoration: none; }
a:hover { color: var(--info-ink); text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ── Каркас ─────────────────────────────────────────────────────────── */

.app-chrome {
    position: sticky;
    top: 0;
    z-index: 100;
}

header.app {
    background: var(--swagger-topbar);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 0 20px;
    min-height: 56px;
}

header.app .brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
    flex: 0 0 auto;
}

header.app .brand:hover { text-decoration: none; }

.brand-logo {
    height: 26px;
    width: auto;
    display: block;
}

.brand-sub {
    color: rgba(255, 255, 255, .82);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    border-left: 1px solid rgba(255, 255, 255, .22);
    padding-left: 12px;
    line-height: 1;
}

nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
}

.nav-toggle {
    display: none;
    width: 36px;
    height: 36px;
    border: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.account {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-left: auto;
    color: #fff;
    flex: 0 0 auto;
}

.account form { margin: 0; }

.account-name {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, .72);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-link,
.account-link:link,
.account-link:visited,
button.account-link {
    display: inline-flex;
    align-items: center;
    height: auto;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    color: rgba(255, 255, 255, .78);
    font: 600 13px/1 var(--sans);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.account-link:hover,
.account-link:focus-visible {
    background: none;
    color: #fff;
    text-decoration: none;
}

main {
    max-width: var(--page-w);
    margin: 0 auto;
    padding: 14px 16px 40px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 12px 14px;
    margin-bottom: 10px;
}

.card > *:first-child { margin-top: 0; }
.card > *:last-child { margin-bottom: 0; }

.card.is-prod {
    border-color: var(--danger);
    box-shadow: var(--shadow-sm);
}

.page-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 12px 24px;
}

.page-head > * { min-width: 0; }
.page-head > *:first-child > *:first-child { margin-top: 0; }
.page-head > *:last-child:not(:only-child) { justify-self: end; }
.page-head .muted { max-width: 90ch; }

/* ── Типографика ────────────────────────────────────────────────────── */

h1 {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -.01em;
    margin: 0 0 6px;
}

h2 {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.3;
    margin: 14px 0 8px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

h3 {
    font-size: 14px;
    font-weight: 700;
    margin: 20px 0 8px;
    color: var(--text-2);
}

p { margin: 0 0 12px; }

p.muted, .muted {
    color: var(--muted);
    font-size: 14px;
}

p.muted + p.muted { margin-top: -4px; }

.muted code { color: var(--text-2); }

h1 + .muted, h2 + .muted, h3 + .muted { margin-top: -4px; }

code, pre { font-family: var(--mono); }

code {
    font-size: .92em;
    font-weight: 600;
    color: var(--text-2);
    background: var(--surface-3);
    padding: 1px 6px;
    border-radius: 4px;
}

pre {
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    overflow: auto;
    font-size: 12.5px;
    line-height: 1.6;
    margin: 0;
    tab-size: 2;
}

.title-code {
    font-size: inherit;
    background: none;
    padding: 0;
    font-weight: 700;
    color: inherit;
}

/* ── Сообщения ──────────────────────────────────────────────────────── */

.flash,
.errors,
.alert {
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
}

.flash {
    background: var(--ok-bg);
    border-color: var(--ok);
    color: var(--ok-ink);
}

.errors {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger-ink);
}

.errors div + div { margin-top: 4px; }

.alert { margin-bottom: 12px; }

.alert-info {
    background: var(--info-bg);
    border-color: var(--info);
    color: var(--info-ink);
}

.alert-warn {
    background: var(--warn-bg);
    border-color: var(--warn);
    color: var(--warn-ink);
}

.preview-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--warn-bg);
    color: var(--warn-ink);
    border-bottom: 2px solid var(--warn);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.45;
}

.preview-bar p { margin: 0; }

.preview-bar form { margin: 0 0 0 auto; }

.preview-bar .preview-exit {
    margin-left: auto;
    flex: none;
    display: inline-flex;
    align-items: center;
    height: 32px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--warn-ink);
    color: #fff;
    font: 600 13px/1 var(--sans);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.alert-danger {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger-ink);
}

.team-stack {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.team-stack .alert { margin-bottom: 0; }

.overwrite-bar {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
    padding: 12px 14px;
    background: var(--warn-bg);
    border: 1px solid var(--warn);
    border-radius: var(--radius-sm);
}

.overwrite-lead {
    margin: 0;
    font-weight: 600;
    color: var(--warn-ink);
}

.overwrite-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.overwrite-bar .change-list { margin: 0; }

/* ── Формы ──────────────────────────────────────────────────────────── */

form { margin: 0; }

.row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
    gap: 10px 12px;
    align-items: end;
    margin-bottom: 10px;
}

.row:last-child { margin-bottom: 0; }
.row > .checks { grid-column: 1 / -1; }

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    margin: 0 0 14px;
}

.field:last-child { margin-bottom: 0; }
.row > .field { margin-bottom: 0; }
.field > p { margin: 0; font-size: 14px; }

/* Одинокое короткое поле не растягивается на всю карточку. */
.row > .field:only-child { max-width: 420px; }

.field-wide { grid-column: span 2; }
.field-action { align-items: flex-start; justify-content: flex-end; }
.dict-add { margin-top: 16px; }

label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    margin: 0;
}

input, select, textarea {
    width: 100%;
    min-height: var(--control-h);
    padding: 7px 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font: 14px/1.45 var(--sans);
    color: var(--text);
    background: var(--surface);
}

select {
    appearance: none;
    padding-right: 30px;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 15px) center, calc(100% - 10px) center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

.dd > select {
    min-height: 0;
    width: 1px;
    padding: 0;
    border: 0;
    background: none;
}

textarea { min-height: 80px; resize: vertical; }

input[type="file"] {
    padding: 6px 10px;
    background: var(--surface-2);
    font-size: 13px;
    color: var(--text-2);
    cursor: pointer;
}

input[type="file"]::file-selector-button {
    height: var(--control-h-sm);
    margin-right: 10px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 700 13px/1 var(--sans);
    cursor: pointer;
}

input[type="file"]:hover::file-selector-button {
    border-color: var(--brand);
    color: var(--brand-ink);
}

::placeholder { color: var(--muted); opacity: 1; }

input:hover, select:hover, textarea:hover { border-color: var(--muted); }

input:focus, select:focus, textarea:focus {
    outline: 0;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

input:disabled, select:disabled, textarea:disabled {
    background: var(--surface-3);
    color: var(--muted);
    cursor: not-allowed;
}

input::-webkit-contacts-auto-fill-button,
input::-webkit-credentials-auto-fill-button,
input::-webkit-caps-lock-indicator,
::-webkit-contacts-auto-fill-button,
::-webkit-credentials-auto-fill-button,
::-webkit-strong-password-auto-fill-button {
    appearance: none !important;
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    opacity: 0 !important;
    background: none !important;
}

.checks {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    margin: 0 0 14px;
}

.checks:last-child { margin-bottom: 0; }
.row > .checks { margin-bottom: 0; }

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0 12px;
    min-height: 34px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    user-select: none;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
}

.check:hover { border-color: var(--muted); }

.check input {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    min-height: 16px;
    margin: 0;
    flex: 0 0 16px;
    border: 1.5px solid var(--line-strong);
    border-radius: 4px;
    background: var(--surface);
    display: grid;
    place-content: center;
    padding: 0;
    box-shadow: none;
    cursor: pointer;
}

.check input::after {
    content: "";
    width: 4px;
    height: 8px;
    margin-top: -2px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    opacity: 0;
}

.check input:checked {
    background: var(--brand);
    border-color: var(--brand);
}

.check input:checked::after { opacity: 1; }

.check:has(input:checked) {
    background: var(--brand-soft);
    border-color: var(--brand);
    color: var(--brand-ink);
}

.check:has(input:disabled) {
    background: var(--surface-3);
    color: var(--muted);
    cursor: not-allowed;
}

.check:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.check code {
    background: none;
    padding: 0;
    font-weight: 600;
    color: inherit;
    opacity: .75;
}

.perm-drop {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin: 0 0 8px;
    background: var(--surface);
}

.perm-drop summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

.perm-drop summary::-webkit-details-marker { display: none; }

.perm-count {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.perm-panel { padding: 0 12px 10px; }

.perm-search {
    width: 100%;
    height: var(--control-h-sm);
    margin: 0 0 8px;
    padding: 0 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font: 400 13px/1 var(--sans);
}

.perm-drop .checks { gap: 6px; }

.perm-empty { margin: 4px 0 0; }

/* ── Кнопки ─────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: var(--control-h);
    padding: 0 16px;
    background: var(--brand);
    color: #fff;
    border: 1px solid var(--brand);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    font: 600 14px/1 var(--sans);
    white-space: nowrap;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}

.btn, .btn:link, .btn:visited {
    color: #fff;
    text-decoration: none;
}

.btn:hover {
    background: var(--brand-hover);
    border-color: var(--brand-hover);
    color: #fff;
    text-decoration: none;
}

.btn.secondary,
.btn.secondary:link,
.btn.secondary:visited {
    background: var(--surface);
    color: var(--text-2);
    border-color: var(--line-strong);
}

.btn.secondary:hover {
    background: var(--surface-2);
    border-color: var(--muted);
    color: var(--text);
}

.btn.danger,
.btn.danger:link,
.btn.danger:visited {
    background: var(--surface);
    color: var(--danger-ink);
    border-color: var(--danger);
}

.btn.danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn[disabled],
.btn[aria-disabled="true"] {
    opacity: .55;
    pointer-events: none;
}

.btn-sm {
    height: var(--control-h-sm);
    padding: 0 12px;
    font-size: 13px;
}

/* Ряды действий: одна строка, всё по левому краю, формы не ломают поток. */
.actions,
.btn-row,
.btn-row-start {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
}

.actions > form,
.btn-row > form,
.btn-row-start > form { margin: 0; }

.actions-sep {
    flex: 1 1 auto;
    min-width: 0;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.row-actions {
    display: inline-flex;
    vertical-align: top;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
}

.fields-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 16px 0;
}

.fields-toolbar .muted { margin: 0 4px 0 0; }
.fields-toolbar .btn { height: var(--control-h-sm); padding: 0 12px; font-size: 13px; }

.search-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 16px;
}

.search-bar .field {
    flex: 1 1 240px;
    max-width: 420px;
    margin: 0;
}

.filter-bar .row { margin-bottom: 0; }

/* ── Таблицы ────────────────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -8px;
    padding: 0 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 520px;
    font-size: 14px;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th:first-child, td:first-child { padding-left: 4px; }
th:last-child, td:last-child { padding-right: 4px; }

th {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
    vertical-align: bottom;
}

/* Вправо уезжает только колонка действий, а не любая последняя ячейка. */
th:last-child:empty,
td:last-child:has(> .btn),
td:last-child:has(> .row-actions),
td:last-child:has(> form) {
    text-align: right;
    white-space: nowrap;
    vertical-align: middle;
}

td[colspan] {
    text-align: left;
    white-space: normal;
}

td > form { margin: 0; }

tbody td .muted { font-size: 12px; }
tbody td > div + div { margin-top: 2px; }

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-current { background: var(--surface-2); }
tbody tr.is-current td:first-child { box-shadow: inset 3px 0 0 var(--brand); }

.secret { position: relative; }
.secret input { padding-right: 36px; }
.secret-toggle {
    position: absolute;
    top: 0;
    right: 0;
    display: grid;
    place-items: center;
    width: 32px;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.secret-toggle:hover { color: var(--text); }
.secret-toggle svg { width: 16px; height: 16px; }
.secret-toggle .icon-hide { display: none; }
.secret-toggle.is-on .icon-show { display: none; }
.secret-toggle.is-on .icon-hide { display: block; }

.table-wrap .btn {
    height: var(--control-h-sm);
    padding: 0 12px;
    font-size: 13px;
}

.sort-link,
.sort-link:link,
.sort-link:visited {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.sort-link:hover { color: var(--brand); text-decoration: none; }

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
}

.pager .btn-row-start { margin-top: 0; }
.pager .muted { margin: 0; font-size: 13px; }

/* ── Бейджи ─────────────────────────────────────────────────────────── */

.tag,
.pill,
.auth-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
}

.tag { font-family: var(--mono); font-size: 11.5px; }
.auth-pill { font-size: 11px; letter-spacing: .03em; }

.pill-ok {
    color: var(--ok-ink);
    border-color: var(--ok);
    background: var(--ok-bg);
}

.pill-err {
    color: var(--danger-ink);
    border-color: var(--danger);
    background: var(--danger-bg);
}

.pill-open {
    color: var(--warn-ink);
    border-color: var(--warn);
    background: var(--warn-bg);
}

/* ── Список операций ────────────────────────────────────────────────── */

.op-list { display: grid; gap: 8px; }

.opblock-row {
    display: flex;
    align-items: stretch;
    gap: 6px;
}

.opblock-row .opblock { flex: 1 1 auto; }

.opblock {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 46px;
    padding: 5px 10px 5px 5px;
    border: 1px solid var(--post);
    border-radius: 4px;
    background: var(--post-bg);
    box-shadow: 0 0 3px rgba(24, 28, 36, .08);
    text-decoration: none;
    color: var(--text);
}

.opblock:hover {
    box-shadow: 0 0 6px rgba(24, 28, 36, .16);
    color: var(--text);
    text-decoration: none;
}

.opblock-method {
    flex: 0 0 80px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    min-height: 32px;
    padding: 6px 0;
    border-radius: 3px;
    background: var(--post);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
    text-shadow: 0 1px 0 rgba(0, 0, 0, .1);
}

.opblock-path {
    font-family: var(--mono);
    font-weight: 600;
    font-size: 16px;
    background: none;
    padding: 0;
    color: var(--text);
}

.opblock-head .star {
    color: var(--brand);
    font-weight: 700;
    margin-left: -6px;
}

.opblock-head .star-conditional { color: var(--muted); }

.opblock-summary {
    color: var(--text-2);
    font-size: 13px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.opblock-meta {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* ── Карточки полей ─────────────────────────────────────────────────── */

.field-block { margin-bottom: 8px; }

.field-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: 0 0 3px rgba(24, 28, 36, .08);
    padding: 0;
    overflow: hidden;
}

.field-card[open] { box-shadow: 0 0 6px rgba(24, 28, 36, .12); }

.field-card > summary.opblock-head {
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.field-card > summary.opblock-head::-webkit-details-marker,
.field-card > summary.opblock-head::marker {
    display: none;
    content: none;
}

.field-card > summary.opblock-head::after {
    content: "";
    margin-left: auto;
    width: 0;
    height: 0;
    border: 4px solid transparent;
    border-top-color: var(--muted);
    transform: translateY(2px);
    flex-shrink: 0;
}

.field-card[open] > summary.opblock-head::after {
    transform: translateY(-2px) rotate(180deg);
}

.field-card .opblock-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 5px 10px 5px 5px;
    background: transparent;
    min-height: 46px;
}

.field-card:not([open]) > summary.opblock-head { border-bottom: none; }
.field-card[open] > summary.opblock-head { border-bottom: 1px solid var(--line); }

.field-card .field-body {
    padding: 14px;
    background: var(--surface);
}
.field-card .field-body > .row:first-child { margin-top: 0; }

/* Как opblock в Swagger: цветная рамка и лёгкая заливка всего блока, без полосы слева. */
.field-card.section-info { border-color: var(--get); background: var(--get-bg); }
.field-card.section-info > summary.opblock-head { border-bottom-color: var(--get); }
.field-card.section-info .opblock-method { background: var(--get); }

.field-card.section-body { border-color: var(--post); background: var(--post-bg); }
.field-card.section-body > summary.opblock-head { border-bottom-color: var(--post); }
.field-card.section-body .opblock-method { background: var(--post); }

.field-card.section-answer { border-color: var(--put); background: var(--put-bg); }
.field-card.section-answer > summary.opblock-head { border-bottom-color: var(--put); }
.field-card.section-answer .opblock-method { background: var(--put); }

.field-card.section-error { border-color: var(--danger); background: var(--danger-bg); }
.field-card.section-error > summary.opblock-head { border-bottom-color: var(--danger); }
.field-card.section-error .opblock-method { background: var(--danger); }

.field-card > summary.opblock-head:hover { filter: brightness(.98); }

.field-nest { margin-bottom: 8px; }

.field-nest.is-child {
    margin-left: 24px;
}

.field-group { display: block; }

.drag-handle,
.drag-hint {
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1;
    color: var(--muted);
    cursor: grab;
    user-select: none;
}

.drag-handle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
}

.opblock-row .drag-handle { align-self: stretch; }

.drag-handle:hover {
    color: var(--brand);
    border-color: var(--line);
    background: var(--surface-2);
}

.drag-hint { cursor: default; }

[data-reorder-id].is-dragging {
    opacity: .5;
    outline: 2px dashed var(--brand);
    outline-offset: 2px;
}

[data-reorder-status] { min-height: 1.5em; }
[data-reorder-status].is-error { color: var(--danger-ink); }

/* ── Выдача продуктов и операций ────────────────────────────────────── */

.grant-details { margin: 16px 0; }

.grant-details > summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-2);
}

.grant-details > summary::-webkit-details-marker,
.grant-details > summary::marker {
    display: none;
    content: none;
}

.grant-details > summary::after {
    content: "";
    width: 0;
    height: 0;
    border: 4px solid transparent;
    border-top-color: currentcolor;
    transform: translateY(2px);
}

.grant-details[open] > summary::after { transform: translateY(-2px) rotate(180deg); }
.grant-details > summary:hover { color: var(--brand); }
.grant-details[open] > summary { margin-bottom: 8px; }

.grant-tree { display: grid; gap: 10px; }

.grant-product {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.grant-product > .check {
    width: 100%;
    border: 0;
    border-radius: 0;
    background: var(--surface-2);
    min-height: 40px;
    font-size: 14px;
}

.grant-product:has(> .check input:checked) { border-color: var(--brand); }
.grant-product > .check:has(input:checked) { background: var(--brand-soft); }

.grant-ops {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 6px;
    margin: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--line);
}

.grant-ops .check {
    justify-content: flex-start;
    align-self: stretch;
    padding: 6px 12px;
}
.grant-ops .muted { margin: 0; grid-column: 1 / -1; }

/* ── Роли, здоровье, журнал правок ──────────────────────────────────── */

.role-preview {
    margin: 16px 0;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.role-preview h3 { margin: 0 0 8px; font-size: 14px; color: var(--text); }
.role-preview p { margin: 0 0 8px; font-size: 14px; }
.role-preview p:last-child { margin-bottom: 0; }

.role-preview-list {
    margin: 0 0 8px;
    padding-left: 18px;
    font-size: 14px;
    color: var(--text-2);
}

.role-preview-list li { margin-bottom: 4px; }
.role-preview .alert { margin: 8px 0 0; }

.health-list { display: grid; gap: 8px; }

.health-row {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.health-row h3 { margin: 0 0 4px; font-size: 14px; color: var(--text); }
.health-row p { margin: 0; font-size: 14px; color: var(--muted); }

.health-warn p, .health-danger p { color: var(--text-2); }

.health-ok { border-color: var(--ok); background: var(--ok-bg); }
.health-warn { border-color: var(--warn); background: var(--warn-bg); }
.health-danger { border-color: var(--danger); background: var(--danger-bg); }

.change-list {
    display: grid;
    gap: 10px;
    margin: 0;
    font-size: 13px;
    color: var(--text-2);
}

.change-row {
    display: grid;
    grid-template-columns: minmax(0, 150px) minmax(0, 1fr);
    gap: 3px 12px;
    align-items: start;
}

.change-field {
    color: var(--muted);
    font-weight: 700;
    overflow-wrap: anywhere;
}

.change-values {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.change-from,
.change-to {
    display: block;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    overflow-wrap: anywhere;
}

.change-from {
    color: var(--danger-ink);
    background: var(--danger-bg);
}

.change-to {
    color: var(--ok-ink);
    background: var(--ok-bg);
}

.change-tag {
    display: inline-block;
    margin-right: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    opacity: .75;
}

/* ── Пароль в MD5 ───────────────────────────────────────────────────── */

.md5-box {
    display: grid;
    gap: 8px;
    margin: 0 0 16px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.md5-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.md5-box .md5-plain {
    flex: 0 1 260px;
    background: var(--surface);
}

.md5-box .md5-out {
    flex: 1 1 320px;
    display: inline-flex;
    align-items: center;
    min-height: var(--control-h);
    margin: 0;
    padding: 0 12px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    word-break: break-all;
}

.md5-box .md5-out.is-filled { color: var(--text); border-style: solid; }
.md5-box .md5-copy { flex: 0 0 auto; }
.md5-box .muted { margin: 0; font-size: 13px; }

/* ── Вход ───────────────────────────────────────────────────────────── */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    display: grid;
    gap: 14px;
}

.login-card h1 { margin: 0; font-size: 22px; }
.login-card .muted { margin: -6px 0 0; font-size: 13px; }
.login-card .brand-logo { height: 30px; }
.login-card .btn { width: 100%; margin-top: 2px; }
.login-card .errors { margin: 0; }

.login-card > .check {
    border: 0;
    background: none;
    padding: 0;
    min-height: 0;
    justify-content: flex-start;
    font-weight: 600;
    color: var(--text-2);
}

.login-card > .check:has(input:checked) { background: none; color: var(--text-2); }

/* ── Прочее ─────────────────────────────────────────────────────────── */

.danger-form { margin: 0; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ── Адаптив ────────────────────────────────────────────────────────── */

@media (max-width: 960px) {
    header.app {
        padding: 8px 12px;
        gap: 8px;
    }
    header.app .brand { flex: 0 1 auto; min-width: 0; }
    .brand-logo { height: 22px; max-width: 150px; }
    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        order: 3;
    }
    .account {
        order: 2;
        margin-left: auto;
        gap: 12px;
    }
    .account-name { display: none; }
    nav {
        order: 4;
        display: none;
        width: 100%;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 4px 0 8px;
    }
    header.app.nav-open nav { display: flex; }
    .menu { display: block; width: 100%; margin: 0; }
    .menu-btn { width: 100%; text-align: left; }
    .menu-list {
        position: static;
        min-width: 0;
        max-width: none;
        margin-top: 4px;
        box-shadow: none;
    }
    main { padding: 16px 12px 48px; }
    .card { padding: 16px; }
    h1 { font-size: 23px; }
    h2 { font-size: 18px; margin-top: 24px; }
    .field-wide { grid-column: 1 / -1; }
    .page-head { grid-template-columns: minmax(0, 1fr); }
    .page-head > *:last-child { justify-self: start; }
    .page-head .btn { width: 100%; }
    .opblock { flex-wrap: wrap; }
    .opblock-summary {
        flex-basis: 100%;
        white-space: normal;
        padding-left: 92px;
    }
    .opblock-meta { margin-left: 0; }
    .field-card .opblock-head {
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
        gap: 4px 8px;
    }
    .field-card .opblock-head .drag-handle { grid-row: 1 / span 2; }
    .field-card .opblock-head .opblock-method { grid-row: 1 / span 2; }
    .field-card .opblock-head .opblock-path { grid-column: 2; }
    .field-card .opblock-head .opblock-summary {
        grid-column: 2 / -1;
        white-space: normal;
        padding-left: 0;
        font-size: 12px;
    }
    .field-card > summary.opblock-head::after {
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
    }
    .field-nest.is-child { margin-left: 16px; }
}

@media (max-width: 560px) {
    .brand-sub { display: none; }
    .search-bar .field { max-width: none; }
    .btn-row .btn,
    .btn-row-start .btn,
    .actions .btn { flex: 1 1 auto; }
    .check { flex: 1 1 100%; }
    table { min-width: 420px; }
}

/* ── Тёмная тема ────────────────────────────────────────────────────── */
/* Переменные темы живут в tokens.css, здесь только точечные поправки. */

html[data-theme="dark"] body {
    background: var(--bg);
    color: var(--text);
}

html[data-theme="dark"] .btn.secondary,
html[data-theme="dark"] .btn.danger { background: var(--surface-2); }

html[data-theme="dark"] .btn.secondary:hover { background: var(--surface-3); }

html[data-theme="dark"] input[type="file"] { color: var(--text-2); }
