/**
 * Admin Panel Styles
 * Complete styling with optimized structure and full light/dark theme support
 */

/* ============================================================
   CSS VARIABLES - LIGHT THEME
   ============================================================ */
[data-theme="light"],
:root {
    /* Colors */
    --admin-border: #dee2e6;
    --admin-border-hover: #ced4da;
    --admin-text-muted: #6c757d;

    /* Backgrounds */
    --admin-bg-primary: linear-gradient(180deg, #ffffff, #f8f9fa);
    --admin-bg-secondary: linear-gradient(180deg, #f1f3f4, #e9ecef);
    --admin-bg-success: linear-gradient(180deg, #d4edda, #c3e6cb);
    --admin-bg-danger: linear-gradient(180deg, #f8d7da, #f5c6cb);

    /* Interactive States */
    --admin-hover-bg: rgba(0, 102, 204, 0.04);

    /* Tables */
    --admin-table-hover: rgba(0, 102, 204, 0.06);
    --admin-table-header: #f8f9fa;
    --admin-table-border: #dee2e6;

    /* Roles & Permissions */
    --admin-role-bg: #f8f9fa;
    --admin-role-border: #ced4da;
    --admin-role-active: rgba(0, 102, 204, 0.1);
    --admin-role-active-border: #0066cc;

    /* Toggles */
    --admin-toggle-bg: #6c757d;
    --admin-toggle-active: #0066cc;
    --admin-toggle-knob: #ffffff;

    /* Code Blocks */
    --admin-code-bg: rgba(0, 102, 204, 0.1);
    --admin-code-text: #0066cc;

    /* Status */
    --admin-status-success: #28a745;
    --admin-status-danger: #dc3545;
    --admin-status-warning: #ffc107;

    /* Additional */
    --admin-white: #ffffff;
    --admin-black: #1a1a1a;
}

/* ============================================================
   CSS VARIABLES - DARK THEME
   ============================================================ */
[data-theme="dark"] {
    /* Colors */
    --admin-border: #282c3d;
    --admin-border-hover: #31364a;
    --admin-text-muted: #8e95ab;


    /* Backgrounds */
    --admin-bg-primary: linear-gradient(180deg, #181b26, #1d2130);
    --admin-bg-secondary: linear-gradient(180deg, #181b26, #11141d);
    --admin-bg-success: linear-gradient(180deg, #0f1e17, #0b1a13);
    --admin-bg-danger: linear-gradient(180deg, #2a1418, #1f0f12);


    /* Interactive States */
    --admin-hover-bg: rgba(167, 139, 250, 0.06);


    /* Tables */
    --admin-table-hover: rgba(167, 139, 250, 0.06);
    --admin-table-header: #181b26;
    --admin-table-border: #282c3d;


    /* Roles & Permissions */
    --admin-role-bg: #0b0d14;
    --admin-role-border: #282c3d;
    --admin-role-active: rgba(167, 139, 250, 0.12);
    --admin-role-active-border: #31364a;


    /* Toggles */
    --admin-toggle-bg: #31364a;
    --admin-toggle-active: #a78bfa;
    --admin-toggle-knob: #ffffff;


    /* Code Blocks */
    --admin-code-bg: rgba(167, 139, 250, 0.10);
    --admin-code-text: #e3e6ee;


    /* Status */
    --admin-status-success: #6ee7b7;
    --admin-status-danger: #fb7185;
    --admin-status-warning: #fbbf24;


    /* Additional */
    --admin-white: #ffffff;
    --admin-black: #0b0d14;
}


/* ============================================================
   HEADER & NAVIGATION
   ============================================================ */
.admin-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.admin-head h1 {
    margin: 0;
    color: var(--text);
    font-size: 24px;
    font-weight: 700;
}

.admin-nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-nav a {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--admin-border);
    text-decoration: none;
    color: var(--text);
    background: var(--card);
    transition: all 0.2s ease;
    font-weight: 500;
}

.admin-nav a:hover {
    border-color: var(--admin-border-hover);
    background: var(--admin-hover-bg);
    transform: translateY(-1px);
}

.admin-nav a.active {
    background: var(--admin-bg-primary);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

/* ============================================================
   STATISTICS GRID
   ============================================================ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border: 1px solid var(--admin-border);
    border-radius: 12px;
    font-size: 14px;
    color: var(--text);
    background: var(--card);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat.info {
    background: var(--admin-bg-primary);
}

.stat.ok {
    background: var(--admin-bg-success);
    color: var(--ok);
}

.stat .stat-label {
    font-weight: 600;
}

.stat .stat-value {
    font-size: 20px;
    font-weight: 700;
}

/* ============================================================
   SECTIONS
   ============================================================ */
.u-sec,
.section {
    margin: 12px 0;
    border: 1px solid var(--admin-border);
    border-radius: 14px;
    background: var(--card);
    overflow: hidden;
}

.u-head,
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 14px 8px;
    border-bottom: 1px solid var(--admin-border);
}

.u-head h2,
.section-header h2,
.u-head h3,
.section-header h3 {
    margin: 0;
    color: var(--text);
    font-weight: 600;
}

.u-body,
.section-body {
    padding: 10px 14px 14px;
}

.u-body.topless {
    padding-top: 0;
}

/* ============================================================
   GRID LAYOUTS
   ============================================================ */
.grid-3 {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 12px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.row-1 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.muted {
    color: var(--admin-text-muted);
    font-size: 12px;
}

.toolbar,
.perm-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 8px 0 10px;
}

.sp,
.spacer {
    flex: 1;
}

.sticky-actions,
.sticky-save {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--admin-border);
    background: var(--admin-role-bg);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    margin-top: 10px;
    backdrop-filter: blur(8px);
}

.nowrap {
    white-space: nowrap;
}

.mb8 {
    margin-bottom: 8px;
}

.text-center {
    text-align: center;
}

/* ============================================================
   TABLES
   ============================================================ */
.u-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
}

.u-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--admin-table-header);
    border-bottom: 1px solid var(--admin-border);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.u-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--admin-table-border);
    vertical-align: top;
    color: var(--text);
}

.u-table tbody tr {
    transition: background 0.15s ease;
}

.u-table tbody tr:hover {
    background: var(--admin-table-hover);
}

.u-table tbody tr:last-child td {
    border-bottom: none;
}

.roles-list-table .role-order-num {
    display: inline-block;
    min-width: 1.5em;
    font-weight: 600;
    color: var(--admin-text-muted);
}

.roles-list-table .role-move-btns {
    display: inline-flex;
    flex-direction: row;
    gap: 2px;
    margin-left: 0;
    flex-shrink: 0;
}

.inline-form {
    display: inline-block;
    margin-left: 6px;
}

.inline-form .btn {
    margin: 0;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
}

/* ============================================================
   ROLES & PERMISSIONS
   ============================================================ */
.roles-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.role-mini,
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid var(--admin-role-border);
    background: var(--admin-role-bg);
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.role-mini:hover,
.pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--overlay);
}

.role-mini .dot,
.pill .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--ring);
}

.role-mini.muted {
    opacity: 0.7;
}

.role-mini.more {
    background: var(--admin-role-active);
    color: var(--accent);
    border-color: var(--admin-role-active-border);
}

/* ============================================================
   ROLE EDITOR
   ============================================================ */
.role-editor {
    margin-top: 8px;
}

.role-editor summary {
    list-style: none;
    cursor: pointer;
    color: var(--text);
    font-weight: 600;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.role-editor summary:hover {
    background: var(--admin-hover-bg);
}

.role-editor summary::-webkit-details-marker {
    display: none;
}

.role-editor summary::before {
    content: "▸";
    display: inline-block;
    margin-right: 8px;
    transition: transform 0.2s ease;
}

.role-editor[open] summary::before {
    transform: rotate(90deg);
}

.role-tools {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 6px;
}

.role-search,
.perm-search {
    min-width: 220px;
}

/* ============================================================
   ROLE & PERMISSION GRIDS
   ============================================================ */
.role-grid,
.perm-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.role-chip,
.perm-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 999px;
    border: 1px solid var(--admin-role-border);
    background: var(--admin-role-bg);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
}

.role-chip:hover,
.perm-chip:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    border-color: var(--admin-border-hover);
    background: var(--admin-hover-bg);
}

.role-chip input,
.perm-chip input {
    display: none;
}

.role-chip.active,
.perm-chip.active {
    background: var(--admin-role-active);
    border-color: var(--admin-role-active-border);
    font-weight: 600;
}

.role-chip .tick {
    display: none;
    color: var(--accent);
}

.role-chip.active .tick {
    display: inline;
}

.perm-chip .toggle {
    margin-left: 6px;
}

/* ============================================================
   STATUS INDICATORS
   ============================================================ */
.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: statusPulse 2s infinite;
}

.status.ok .dot {
    background: var(--admin-status-success);
}

.status.off .dot {
    background: var(--admin-status-danger);
}

.status.warning .dot {
    background: var(--admin-status-warning);
}

@keyframes statusPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* ============================================================
   TOGGLE SWITCHES
   ============================================================ */
.toggle {
    display: inline-block;
    position: relative;
    width: 46px;
    height: 24px;
    vertical-align: middle;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle .slider {
    position: absolute;
    inset: 0;
    border-radius: 24px;
    background: var(--admin-toggle-bg);
    transition: 0.2s ease;
    cursor: pointer;
}

.toggle .slider:before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    border-radius: 50%;
    background: var(--admin-toggle-knob);
    transition: 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle input:checked+.slider {
    background: var(--admin-toggle-active);
}

.toggle input:checked+.slider:before {
    transform: translateX(22px);
}

.toggle input:focus-visible+.slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Compact Toggle Switches */
.perm-chip .toggle {
    width: 34px;
    height: 18px;
}

.perm-chip .toggle .slider {
    border-radius: 18px;
}

.perm-chip .toggle .slider:before {
    width: 14px;
    height: 14px;
    left: 2px;
    bottom: 2px;
}

.perm-chip .toggle input:checked+.slider:before {
    transform: translateX(16px);
}

/* ============================================================
   CONTROLS
   ============================================================ */
.control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.control:hover {
    background: var(--admin-hover-bg);
}

.control label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    cursor: pointer;
    color: var(--text);
    flex: 1;
}

/* ============================================================
   ROLE CARDS
   ============================================================ */
.roles-card {
    margin: 14px 0;
    border: 1px solid var(--admin-border);
    border-radius: 12px;
    background: var(--card);
    overflow: hidden;
}
.roles-compact.roles-card {
    margin: 10px 0;
    border-radius: 10px;
}

.roles-list-card {
    margin-top: 0;
    border-width: 2px;
    border-color: var(--admin-role-active-border);
}

/* Раскрывающийся блок «Роли» */
.roles-list-details {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.roles-list-summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 20px;
    background: var(--admin-bg-secondary);
    border-bottom: 1px solid var(--admin-border);
    user-select: none;
}
.roles-list-summary::-webkit-details-marker { display: none; }
.roles-list-summary::marker { content: none; }
.roles-list-summary-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}
.roles-list-summary-hint {
    font-size: 12px;
    color: var(--admin-text-muted);
}
.roles-list-summary .role-create-inline {
    margin-left: auto;
}
.roles-list-summary .role-create-inline .role-create-input {
    width: 140px;
}
.roles-list-summary .role-create-inline .btn-primary {
    font-weight: 600;
}
.roles-list-body {
    padding: 16px 18px 20px;
    background: var(--card);
}

/* Подсказки под заголовком «Роли» */
.roles-list-hint-box {
    margin: 0 18px 14px;
    padding: 12px 16px;
    background: rgba(0, 102, 204, 0.06);
    border-left: 4px solid var(--accent, #0066cc);
    border-radius: 0 8px 8px 0;
    font-size: 13px;
    color: var(--admin-text-muted);
}
[data-theme="dark"] .roles-list-hint-box {
    background: rgba(167, 139, 250, 0.08);
    border-left-color: var(--accent);
}
.roles-list-hint-box .roles-list-hint-item {
    margin: 0 0 6px 0;
    line-height: 1.45;
}
.roles-list-hint-box .roles-list-hint-item:last-child {
    margin-bottom: 0;
}
.roles-list-hint-box .roles-list-hint-icon {
    margin-right: 6px;
    opacity: 0.9;
}

/* Компактный режим ролей */
.roles-compact .roles-body,
.roles-compact .roles-body-compact {
    padding: 8px 14px 12px;
}
.roles-compact .roles-body.topless {
    padding-top: 0;
}
.roles-header-compact {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
}
.roles-title-compact {
    font-size: 16px !important;
    margin: 0 !important;
}
.roles-header-actions {
    display: flex;
    align-items: center;
}
.role-create-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.role-create-inline .role-create-input {
    width: 120px;
    padding: 6px 8px;
    font-size: 13px;
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
}
.role-create-inline .role-create-input::placeholder {
    color: var(--admin-text-muted);
}
.role-select-form {
    margin: 0;
}
.role-select-label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 13px;
}
.role-select {
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 8px;
    border: 1px solid var(--admin-border);
    background: var(--card);
    color: var(--text);
    min-width: 160px;
}
.sticky-save-compact {
    padding: 8px 14px;
}
.sticky-save-compact .btn {
    margin: 0;
}

/* Таблица ролей — компактная */
.roles-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.roles-list-table {
    min-width: 620px;
    border-radius: 10px;
    overflow: hidden;
}
.roles-list-table tbody tr {
    transition: background 0.2s ease, box-shadow 0.2s ease;
}
.roles-list-table tbody tr {
    cursor: default;
}
.roles-list-table tbody tr:hover {
    background: var(--admin-table-hover);
}
.roles-list-table tbody td {
    position: relative;
    z-index: 1;
}
.roles-list-table thead th {
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.roles-list-table tbody td {
    padding: 12px;
    font-size: 14px;
    vertical-align: middle;
}
.roles-list-table .col-drag {
    width: 32px;
    padding: 12px 8px !important;
    text-align: center;
    color: var(--admin-text-muted);
    vertical-align: middle;
}
.role-drag-handle {
    cursor: grab;
    font-size: 14px;
    letter-spacing: -2px;
    user-select: none;
}
.role-row-draggable:active .role-drag-handle { cursor: grabbing; }
.role-row.role-dragging {
    opacity: 0.6;
    background: var(--admin-hover-bg);
}
.role-row.role-drag-over {
    border-top: 2px solid var(--accent);
    box-shadow: 0 -2px 8px var(--ring);
}
.roles-list-table .col-order {
    width: 100px;
    min-width: 100px;
    text-align: left;
    white-space: nowrap;
    overflow: visible;
    padding-right: 16px !important;
    box-sizing: border-box;
}
.roles-list-table td.col-order {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}
.roles-list-table .col-order .role-order-num {
    flex-shrink: 0;
    min-width: 1.4em;
    text-align: right;
}
.roles-list-table tbody td:nth-child(3) {
    padding-left: 16px;
}
.roles-list-table .col-key { width: 100px; }
.roles-list-table .col-vis { width: 36px; text-align: center; }
.roles-list-table .col-num {
    width: 90px;
    text-align: center;
    white-space: nowrap;
}
.roles-list-table .col-actions {
    width: 150px;
    text-align: left;
}
.role-name-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}
.role-name-link:hover {
    color: var(--accent);
    text-decoration: underline;
}
.roles-list-table .role-name-link {
    font-size: 14px;
}
.kbd-sm {
    font-size: 11px;
    padding: 2px 5px;
}
.role-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}
.role-actions .btn-icon,
.role-actions .inline-form .btn-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    box-sizing: border-box;
}
.role-actions .inline-form {
    display: inline-flex;
    margin: 0;
}
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--admin-border);
    border-radius: 6px;
    background: var(--card);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    text-decoration: none;
    line-height: 1;
    box-sizing: border-box;
}
.btn-icon:hover {
    border-color: var(--admin-border-hover);
    background: var(--admin-hover-bg);
}
.btn-icon-danger:hover {
    border-color: var(--danger);
    background: var(--danger-bg);
    color: var(--danger);
}
.inline-form.inline-form-icon {
    display: inline-flex;
    margin: 0;
}
.roles-list-table .col-order .role-move-btns {
    margin-left: 4px;
    flex-shrink: 0;
    display: inline-flex;
    gap: 4px;
}
.roles-list-table .col-order .role-move-btns .btn-icon {
    width: 26px;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    font-size: 13px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid var(--admin-border);
    color: var(--text);
    flex-shrink: 0;
}
[data-theme="dark"] .roles-list-table .col-order .role-move-btns .btn-icon {
    background: rgba(255, 255, 255, 0.06);
}
.roles-list-table .col-order .role-move-btns .btn-icon:hover {
    background: var(--admin-hover-bg);
    border-color: var(--admin-border-hover);
    color: var(--text);
}

/* Права — компактные чипы и тулбар */
.perm-toolbar-compact {
    gap: 8px;
    margin-bottom: 8px;
}
.perm-search-compact {
    min-width: 140px;
    padding: 6px 10px;
    font-size: 13px;
}
.perm-chips-compact {
    gap: 6px;
}
.perm-chips-compact .perm-chip {
    padding: 5px 8px;
    font-size: 12px;
}
.perm-legend {
    font-size: 11px;
    margin-top: 6px;
}
.current-perms-block {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.current-perms-block .muted {
    font-size: 12px;
}
.current-perms-list {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
}
.pill-sm {
    padding: 2px 6px;
    font-size: 11px;
}

/* Модалка редактирования роли — компактная */
.modal-window-sm {
    max-width: 400px;
}
.modal-header-compact {
    padding: 12px 16px;
}
.modal-header-compact h3 {
    font-size: 16px;
}
.modal-body-compact {
    padding: 16px;
}
.modal-body-compact .modal-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 13px;
}
.modal-body-compact .modal-label span {
    flex: 0 0 80px;
    color: var(--admin-text-muted);
}
.modal-body-compact .modal-label input[type="text"] {
    flex: 1;
    padding: 8px 10px;
    font-size: 13px;
}
.modal-label-check {
    display: flex !important;
    align-items: center;
    gap: 8px;
}
.modal-label-check input {
    margin: 0;
}
.modal-footer-compact {
    padding: 12px 16px;
}

.restricted-perms-card {
    background: var(--admin-bg-secondary);
    border: 2px solid var(--admin-status-warning);
}
.restricted-perms-summary {
    cursor: pointer;
    padding: 10px 14px;
    list-style: none;
    user-select: none;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.restricted-perms-summary::-webkit-details-marker { display: none; }
.restricted-perms-hint {
    font-size: 12px;
    margin-bottom: 8px;
}

.roles-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 10px 18px;
    border-bottom: 1px solid var(--admin-border);
}

.roles-header h2,
.roles-header h3 {
    margin: 0;
    font-size: 20px;
    color: var(--text);
    font-weight: 600;
}

.roles-body {
    padding: 10px 18px 16px 18px;
}

/* ============================================================
   HELP SECTIONS
   ============================================================ */
.tg-help {
    margin-bottom: 18px;
    display: grid;
    gap: 8px;
    color: var(--admin-text-muted);
    font-size: 14px;
    line-height: 1.6;
}

.tg-help code {
    color: var(--admin-code-text);
    background: var(--admin-code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 95%;
    font-family: 'Courier New', monospace;
}

.tg-help strong {
    color: var(--text);
    font-weight: 600;
}

/* ============================================================
   ALERT BOXES
   ============================================================ */
.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin: 12px 0;
    border: 1px solid;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert.success {
    background: var(--admin-bg-success);
    border-color: var(--admin-status-success);
    color: var(--ok);
}

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

.alert.info {
    background: var(--admin-bg-primary);
    border-color: var(--accent);
    color: var(--accent);
}

/* ============================================================
   FORM ELEMENTS IN ADMIN PANEL
   ============================================================ */
.admin-form-group {
    margin-bottom: 14px;
}

.admin-form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text);
    font-weight: 500;
    font-size: 13px;
}

.admin-form-group input,
.admin-form-group select,
.admin-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--admin-border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.admin-form-group input:focus,
.admin-form-group select:focus,
.admin-form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ring);
}

.admin-form-group .help-text {
    display: block;
    margin-top: 4px;
    color: var(--admin-text-muted);
    font-size: 12px;
}

/* ============================================================
   INVITE LINK DISPLAY
   ============================================================ */
.invite-link-box {
    margin: 12px 0;
    padding: 12px;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--admin-role-active);
}

.invite-link-box .link {
    display: block;
    padding: 8px;
    background: var(--card);
    border-radius: 6px;
    word-break: break-all;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: var(--accent);
}

/* ============================================================
   BADGES & LABELS
   ============================================================ */
.admin-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.admin-badge.primary {
    background: var(--accent);
    color: var(--admin-white);
}

.admin-badge.success {
    background: var(--ok);
    color: var(--admin-white);
}

.admin-badge.danger {
    background: var(--danger);
    color: var(--admin-white);
}

.admin-badge.secondary {
    background: var(--admin-role-bg);
    color: var(--text);
    border: 1px solid var(--admin-border);
}

/* ============================================================
   LOADING STATES
   ============================================================ */
.loading-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--admin-border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================
   EMPTY STATES
   ============================================================ */
.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--admin-text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 16px;
    margin-bottom: 8px;
}

.empty-state-subtext {
    font-size: 14px;
    opacity: 0.7;
}

/* ============================================================
   RESPONSIVE DESIGN - TABLET
   ============================================================ */
@media (max-width: 768px) {
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-3,
    .grid-2,
    .row {
        grid-template-columns: 1fr;
    }

    .admin-head {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .admin-nav {
        justify-content: center;
    }

    .toolbar,
    .perm-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .role-search,
    .perm-search {
        min-width: auto;
        width: 100%;
    }

    .sticky-actions,
    .sticky-save {
        position: relative;
        border-radius: 0;
        margin: 0;
    }

    .u-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* ============================================================
   RESPONSIVE DESIGN - MOBILE
   ============================================================ */
@media (max-width: 480px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .u-head,
    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .roles-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .control {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .toggle {
        align-self: center;
    }

    .role-chip,
    .perm-chip {
        font-size: 12px;
        padding: 6px 9px;
    }
}

/* ============================================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {

    .role-chip,
    .perm-chip,
    .toggle .slider,
    .toggle .slider:before,
    .stat,
    .admin-nav a,
    .role-mini,
    .pill {
        transition: none;
    }

    .role-chip:hover,
    .perm-chip:hover,
    .stat:hover,
    .role-mini:hover,
    .pill:hover {
        transform: none;
    }

    @keyframes statusPulse {

        0%,
        100% {
            opacity: 1;
            transform: scale(1);
        }
    }
}

/* ============================================================
   ACCESSIBILITY - KEYBOARD FOCUS
   ============================================================ */
.role-chip:focus-visible,
.perm-chip:focus-visible,
.admin-nav a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {

    .admin-nav,
    .sticky-actions,
    .sticky-save,
    .toggle {
        display: none;
    }

    .u-sec,
    .section,
    .roles-card {
        break-inside: avoid;
    }
}


/* ============================================================
   INVITE LINK BOX
   ============================================================ */
.invite-link-container {
    margin: 0 0 12px 0;
    padding: 12px;
    border: 1px solid var(--admin-border);
    border-radius: 12px;
    background: var(--admin-bg-secondary);
}

.invite-link-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.invite-link-input {
    flex: 1;
    min-width: 280px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--admin-border);
    border-radius: 10px;
    padding: 8px 10px;
}

/* ============================================================
   EVENT FLAG BOXES
   ============================================================ */
.event-flag-box {
    border: 1px solid var(--admin-border);
    border-radius: 12px;
    padding: 12px;
    background: var(--admin-bg-secondary);
}

/* ============================================================
   SECTION BODY VARIANTS
   ============================================================ */
.section-body.with-border {
    border-bottom: 1px solid var(--admin-border);
}

/* ============================================================
   LIGHT THEME SPECIFIC OVERRIDES
   ============================================================ */
[data-theme="light"] .invite-link-container {
    border-color: #dee2e6;
    background: linear-gradient(180deg, #f1f3f4, #e9ecef);
}

[data-theme="light"] .invite-link-input {
    background: #ffffff;
    color: #1a1a1a;
    border-color: #ced4da;
}

[data-theme="light"] .event-flag-box {
    border-color: #dee2e6;
    background: linear-gradient(180deg, #f8f9fa, #f1f3f4);
}

[data-theme="light"] .section-body.with-border {
    border-bottom-color: #dee2e6;
}

/* ============================================================
   DARK THEME SPECIFIC OVERRIDES
   ============================================================ */
[data-theme="dark"] .invite-link-container {
    border-color: #282c3d;
    background: linear-gradient(180deg, #181b26, #0b0d14);
}


[data-theme="dark"] .invite-link-input {
    background: #0b0d14;
    color: #e3e6ee;
    border-color: #282c3d;
}


[data-theme="dark"] .event-flag-box {
    border-color: #282c3d;
    background: linear-gradient(180deg, #181b26, #1d2130);
}


[data-theme="dark"] .section-body.with-border {
    border-bottom-color: #282c3d;
}

/* ============================================================
   MODAL WINDOWS
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-window {
    background: var(--admin-bg-primary);
    border: 1px solid var(--admin-border);
    border-radius: 12px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--admin-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--admin-table-header);
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: var(--admin-text-muted);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--admin-hover-bg);
    color: var(--admin-black);
}

[data-theme="dark"] .modal-close:hover {
    color: var(--admin-white);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--admin-border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: var(--admin-table-header);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Кнопка «N чел.» — явно кликабельная */
.btn-pill.role-users-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 56px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
    border: 1px solid var(--admin-role-active-border, #0066cc);
    background: var(--admin-role-active, rgba(0, 102, 204, 0.12));
    color: var(--accent, #0066cc);
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    position: relative;
    z-index: 2;
}
.btn-pill.role-users-btn:hover {
    background: var(--admin-role-active);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.25);
}
.btn-pill.role-users-btn:active {
    transform: translateY(0);
}
[data-theme="dark"] .btn-pill.role-users-btn {
    border-color: var(--accent);
    background: rgba(167, 139, 250, 0.15);
    color: var(--accent);
}
[data-theme="dark"] .btn-pill.role-users-btn:hover {
    background: rgba(167, 139, 250, 0.25);
    box-shadow: 0 2px 12px rgba(167, 139, 250, 0.3);
}

/* Иконки действий в таблице ролей — крупнее и с чётким hover */
.role-actions .role-action-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    font-size: 15px;
    border-radius: 8px;
}
.role-actions .role-action-btn:hover {
    background: var(--admin-hover-bg);
    border-color: var(--accent);
    color: var(--accent);
}
.role-actions .btn-icon-danger:hover {
    border-color: var(--admin-status-danger);
    color: var(--admin-status-danger);
    background: rgba(220, 53, 69, 0.1);
}

/* Пользователи с ролью (модалка) */
.role-users-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.role-users-list .role-user-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--admin-border);
}
.role-users-list .role-user-row:last-child {
    border-bottom: none;
}
.role-users-list .role-user-info {
    flex: 1;
    min-width: 180px;
}
.role-users-list .role-user-info .muted {
    margin-left: 8px;
    font-size: 0.9em;
}
.role-users-list .inline-form {
    margin: 0;
}
