.qep-root {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--header-height, 64px));
    background: var(--rz-base-50, #fafafa);
}

.qep-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

/* ════════ Header ════════ */

.qep-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--rz-base-background-color);
    border-bottom: 1px solid var(--rz-base-200);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    isolation: isolate;
}

.qep-header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1rem 1.75rem 1.1rem;
}

.qep-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.75rem;
    color: var(--rz-text-tertiary-color);
    margin-bottom: 0.6rem;
}

.qep-breadcrumb-link {
    color: var(--rz-text-secondary-color);
    text-decoration: none;
    transition: color 0.15s ease;
}

.qep-breadcrumb-link:hover {
    color: var(--rz-primary);
}

.qep-breadcrumb-sep {
    color: var(--rz-text-tertiary-color);
    opacity: 0.6;
}

.qep-breadcrumb-current {
    color: var(--rz-text-color);
    font-weight: 500;
}

.qep-header-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.qep-header-title-block {
    display: flex;
    align-items: center;
    gap: 0.95rem;
    min-width: 0;
    flex: 1 1 auto;
}

.qep-color-chip {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.2rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.qep-header-text {
    min-width: 0;
}

.qep-header-eyebrow {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--rz-text-tertiary-color);
    font-weight: 600;
}

.qep-header-h1 {
    font-size: 1.375rem;
    line-height: 1.25;
    font-weight: 600;
    margin: 0.1rem 0 0.15rem;
    color: var(--rz-text-color);
}

.qep-header-subtitle {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--rz-text-secondary-color);
    max-width: 640px;
}

.qep-header-subtitle.qep-muted {
    color: var(--rz-text-tertiary-color);
    font-style: italic;
}

.qep-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
}

.qep-pending-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    font-size: 0.72rem;
    font-weight: 500;
    color: #b45309;
}

.qep-pending-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f59e0b;
    animation: qep-pulse 1.5s ease-in-out infinite;
}

@keyframes qep-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ════════ Body: nav + main ════════ */

.qep-body {
    display: flex;
    gap: 1.5rem;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1.75rem 3rem;
    flex: 1 1 auto;
    align-items: flex-start;
}

.qep-nav {
    flex: 0 0 240px;
    position: sticky;
    top: 132px;
}

.qep-nav-inner {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.qep-nav-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--rz-text-secondary-color);
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    border-left: 3px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.qep-nav-item:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--rz-text-color);
}

.qep-nav-item-active {
    background: color-mix(in srgb, var(--rz-primary) 8%, transparent);
    color: var(--rz-primary);
    border-left-color: var(--rz-primary);
}

.qep-nav-item-active:hover {
    background: color-mix(in srgb, var(--rz-primary) 12%, transparent);
    color: var(--rz-primary);
}

.qep-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ════════ Cards ════════ */

.qep-card {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.qep-card-head {
    padding: 1rem 1.25rem 0.85rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.qep-card-head-inline {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.qep-card-head-actions {
    display: flex;
    gap: 0.25rem;
    flex: 0 0 auto;
}

.qep-card-title {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--rz-text-color);
    line-height: 1.3;
}

.qep-card-hint {
    margin: 0.2rem 0 0;
    font-size: 0.78rem;
    color: var(--rz-text-tertiary-color);
    line-height: 1.4;
}

.qep-card-body {
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.qep-card-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.25rem;
    color: var(--rz-text-tertiary-color);
    font-size: 0.8125rem;
}

.qep-card-empty {
    padding: 2.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
}

.qep-empty-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--rz-text-tertiary-color);
    font-size: 1.8rem;
}

.qep-empty-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--rz-text-color);
}

.qep-empty-hint {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--rz-text-tertiary-color);
    max-width: 380px;
}

/* ════════ Toggles ════════ */

.qep-toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.qep-toggle-row:last-child {
    border-bottom: none;
}

.qep-toggle-text {
    min-width: 0;
    flex: 1 1 auto;
}

.qep-toggle-title {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--rz-text-color);
}

.qep-toggle-hint {
    font-size: 0.75rem;
    color: var(--rz-text-tertiary-color);
    line-height: 1.4;
    margin-top: 0.2rem;
}

.qep-suffixed {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.qep-suffix {
    font-size: 0.75rem;
    color: var(--rz-text-tertiary-color);
    font-weight: 500;
}

/* ════════ Types section (master-detail) ════════ */

.qep-types-split {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.qep-types-list {
    flex: 0 0 320px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.qep-type-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 0.8rem;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    border-left: 3px solid transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    transition: background 0.15s ease, border-color 0.15s ease;
}

.qep-type-item:last-of-type {
    border-bottom: none;
}

.qep-type-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

.qep-type-item-active {
    background: color-mix(in srgb, var(--rz-primary) 6%, transparent);
    border-left-color: var(--rz-primary);
}

.qep-type-item-active:hover {
    background: color-mix(in srgb, var(--rz-primary) 10%, transparent);
}

.qep-type-item-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.qep-type-item-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--rz-text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qep-type-item-pill {
    font-size: 0.7rem;
    padding: 0.1rem 0.5rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    color: var(--rz-text-tertiary-color);
    align-self: flex-start;
}

.qep-type-item-count {
    flex: 0 0 auto;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--rz-text-tertiary-color);
    background: rgba(0, 0, 0, 0.04);
    padding: 0.15rem 0.45rem;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}

.qep-type-add {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0.8rem;
    border: none;
    background: transparent;
    color: var(--rz-primary);
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    border-top: 1px dashed rgba(0, 0, 0, 0.08);
}

.qep-type-add:hover {
    background: color-mix(in srgb, var(--rz-primary) 6%, transparent);
}

.qep-type-editor {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.qep-type-editor-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 3rem 1rem;
    background: #fff;
    border: 1px dashed rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    color: var(--rz-text-tertiary-color);
    font-size: 0.85rem;
}

.qep-type-danger-zone {
    display: flex;
    justify-content: flex-end;
}

/* ════════ Categories tree ════════ */

.qep-cat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.9rem;
}

.qep-cat-group {
    background: rgba(0, 0, 0, 0.015);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
}

.qep-cat-root {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--rz-text-color);
    cursor: pointer;
}

.qep-cat-children {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-top: 0.45rem;
    padding-left: 1.25rem;
}

.qep-cat-child {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    color: var(--rz-text-secondary-color);
    cursor: pointer;
}

.qep-cat-tree {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.qep-cat-branch {
    display: flex;
    flex-direction: column;
}

.qep-cat-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.qep-cat-row:hover {
    background: rgba(0, 0, 0, 0.03);
}

.qep-cat-row-edit {
    background: rgba(0, 0, 0, 0.02);
}

.qep-cat-row-child {
    margin-left: 1.5rem;
    font-size: 0.82rem;
}

.qep-cat-name {
    flex: 1 1 auto;
    font-size: 0.875rem;
    color: var(--rz-text-color);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qep-cat-actions {
    display: flex;
    gap: 0.15rem;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.qep-cat-row:hover .qep-cat-actions,
.qep-cat-row-edit .qep-cat-actions {
    opacity: 1;
}

.qep-cat-child-list {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-top: 0.1rem;
}

/* ════════ Inline add ════════ */

.qep-inline-add {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* ════════ Drag & drop ════════ */

.qep-type-item-wrap {
    position: relative;
}

.qep-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--rz-text-tertiary-color);
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease;
    cursor: grab;
    font-size: 1.05rem;
}

.qep-drag-handle:active {
    cursor: grabbing;
}

.qep-type-item:hover .qep-drag-handle,
.qep-cat-row:hover .qep-drag-handle {
    opacity: 0.75;
}

.qep-dragging {
    opacity: 0.4;
}

/* Top / bottom 2px indicator bars. Use box-shadow so we don't disturb layout. */
.qep-drop-indicator-above {
    box-shadow: inset 0 2px 0 0 var(--rz-primary);
}

.qep-drop-indicator-below {
    box-shadow: inset 0 -2px 0 0 var(--rz-primary);
}

.qep-drop-indicator-into {
    outline: 2px dashed var(--rz-primary);
    outline-offset: -2px;
    background: color-mix(in srgb, var(--rz-primary) 6%, transparent);
}

.qep-drop-forbidden {
    outline: 2px dashed #dc2626;
    outline-offset: -2px;
    background: rgba(220, 38, 38, 0.06);
    cursor: not-allowed;
}

/* ════════ Permissions section ════════ */

.qep-perm-search {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.qep-perm-suggestion {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.25rem 0;
}

.qep-perm-suggestion-avatar {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
}

.qep-perm-suggestion-text {
    min-width: 0;
}

.qep-perm-suggestion-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--rz-text-color);
}

.qep-perm-suggestion-email {
    font-size: 0.72rem;
    color: var(--rz-text-tertiary-color);
}

.qep-perm-empty {
    flex-direction: column;
    padding: 2rem 1rem;
    gap: 0.45rem;
    text-align: center;
}

.qep-perm-empty .rzi {
    font-size: 1.6rem;
    opacity: 0.6;
}

.qep-perm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.qep-perm-table thead th {
    text-align: left;
    padding: 0.5rem 0.65rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--rz-text-tertiary-color);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.qep-perm-table tbody td {
    padding: 0.65rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    vertical-align: middle;
}

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

.qep-perm-col-user {
    min-width: 220px;
}

.qep-perm-col-status {
    width: 140px;
}

.qep-perm-col-load {
    width: 110px;
    color: var(--rz-text-secondary-color);
}

.qep-perm-col-actions {
    width: 90px;
    text-align: right;
}

.qep-perm-user {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.qep-perm-avatar {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
}

.qep-perm-user-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.qep-perm-user-name {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--rz-text-color);
}

.qep-perm-user-email {
    font-size: 0.72rem;
    color: var(--rz-text-tertiary-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qep-perm-lead-badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    background: color-mix(in srgb, var(--rz-primary) 15%, transparent);
    color: var(--rz-primary);
}

.qep-perm-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 500;
}

.qep-perm-chip-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.qep-perm-chip-ok {
    background: rgba(16, 185, 129, 0.1);
    color: #047857;
}

.qep-perm-chip-ok .qep-perm-chip-dot {
    background: #10b981;
}

.qep-perm-chip-off {
    background: rgba(107, 114, 128, 0.12);
    color: #4b5563;
}

.qep-perm-chip-off .qep-perm-chip-dot {
    background: #9ca3af;
}

.qep-perm-load {
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.qep-perm-actions {
    display: flex;
    gap: 0.15rem;
    justify-content: flex-end;
}

/* ════════ Responsive ════════ */

@media (max-width: 960px) {
    .qep-body {
        flex-direction: column;
    }

    .qep-nav {
        position: static;
        flex: 0 0 auto;
        width: 100%;
    }

    .qep-nav-inner {
        flex-direction: row;
        overflow-x: auto;
        gap: 0.25rem;
        padding-bottom: 0.25rem;
    }

    .qep-nav-item {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .qep-types-split {
        flex-direction: column;
    }

    .qep-types-list {
        flex: 0 0 auto;
        width: 100%;
    }

    .qep-header-main {
        flex-direction: column;
        align-items: stretch;
    }

    .qep-header-actions {
        justify-content: flex-end;
    }
}
