/*
 * Role Management — split-panel UI on the Users page.
 * Mirrors design-mockups/role-management.html. Uses the global design tokens
 * defined in css/design-tokens.css for color/spacing — no hard-coded hex unless
 * the mockup used a one-off shade (the drop-target backgrounds).
 *
 * --slate / --slate-bg are defined locally because design-tokens.css does not
 * yet expose them; once the Owner-as-slate decision is finalized we should
 * lift them into the global token sheet.
 */
.rm-scope {
    --slate:    #475569;
    --slate-bg: #e2e8f0;
}

/* Split layout. When .manage-mode is on, right panel slides in 50/50. */
.rm-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    transition: grid-template-columns .2s ease;
}
.rm-layout.manage-mode { grid-template-columns: 1fr 1fr; }

.rm-panel {
    background: var(--bg-panel, #ffffff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    overflow: hidden;
    min-width: 0;
}
.rm-panel-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.rm-panel-title { font-size: 14px; font-weight: 600; color: var(--text, #111827); margin: 0; }
.rm-panel-subtitle { font-size: 12px; color: var(--text-muted, #6b7280); margin: 2px 0 0; }
.rm-panel-body { padding: 14px 18px 18px; }

/* Owner banner — slate-colored info strip near the top of the Manage Roles UI */
.rm-owner-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin: 0 0 12px;
    background: #e2e8f0;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    color: #475569;
    font-size: 13px;
}
.rm-owner-banner .rm-owner-label { font-weight: 600; }
.rm-owner-banner .rm-owner-transfer {
    background: white;
    border: 1px solid #cbd5e1;
    color: #475569;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.rm-owner-banner .rm-owner-transfer:hover { background: #f1f5f9; color: #334155; }

/* User row — replaces the table row when in manage-roles mode */
.rm-user-row {
    display: grid;
    grid-template-columns: 22px 32px 1fr minmax(140px, auto) auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: grab;
    user-select: none;
    transition: background-color .12s ease, border-color .12s ease;
}
.rm-user-row + .rm-user-row { margin-top: 2px; }
.rm-user-row:hover { background: var(--bg-subtle, #f3f4f6); }
.rm-user-row[draggable="true"]:active { cursor: grabbing; }
.rm-user-row.dragging { opacity: 0.4; }
.rm-user-row.is-selected { background: var(--primary-bg-subtle, #eff6ff); border-color: var(--primary-bg, #dbeafe); }
.rm-user-row.is-selected:hover { background: var(--primary-bg, #dbeafe); }
.rm-user-row.in-active-drag { opacity: 0.4; }

.rm-row-select {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.rm-row-select input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary, #2563eb); margin: 0; }

.rm-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary-bg, #dbeafe);
    color: var(--primary, #2563eb);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 12px;
}
.rm-user-name { font-size: 13px; font-weight: 500; color: var(--text, #111827); }
.rm-user-email { font-size: 11px; color: var(--text-muted, #6b7280); }

/* Role chips — rendered both in the list AND inside the role buckets */
.rm-role-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.rm-role-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: 999px;
    font-size: 11px; font-weight: 600;
    background: var(--bg-tertiary, #f1f5f9); color: var(--text-muted, #6b7280);
}
.rm-role-chip.owner  { background: #e2e8f0; color: #475569; }
.rm-role-chip.admin  { background: var(--primary-bg, #dbeafe); color: var(--primary, #2563eb); }
.rm-role-chip.member { background: var(--success-bg, #d1fae5); color: var(--success, #059669); }
.rm-role-chip.viewer { background: var(--bg-tertiary, #f1f5f9); color: var(--text-muted, #6b7280); }
.rm-role-chip.pathwayeditor { background: #ccfbf1; color: #0d9488; }

/* Quick chips — appear on row hover, single-click to add a missing role */
.rm-quick-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .12s ease; }
.rm-user-row:hover .rm-quick-actions { opacity: 1; }
.rm-quick-chip {
    padding: 3px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 600;
    border: 1px solid var(--border-strong, #d1d5db);
    background: var(--bg-panel, #ffffff); color: var(--text-muted, #6b7280);
    cursor: pointer; font-family: inherit;
}
.rm-quick-chip:hover {
    background: var(--primary-bg-subtle, #eff6ff);
    color: var(--primary, #2563eb);
    border-color: var(--primary-bg, #dbeafe);
}

/* Selection bar — sticky-ish header above the list when >=1 user is selected */
.rm-selection-bar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    margin: 0 0 10px;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--primary-bg-subtle, #eff6ff);
    border: 1px solid var(--primary-bg, #dbeafe);
    color: var(--primary-hover, #1d4ed8);
    font-size: 12px; font-weight: 600;
}
.rm-selection-bar .rm-count-pill {
    background: var(--primary, #2563eb); color: white;
    padding: 2px 10px; border-radius: 999px;
    font-size: 11px; font-weight: 700;
}
.rm-selection-bar .rm-hint { font-weight: 500; opacity: 0.85; }
.rm-selection-bar .rm-clear-btn {
    background: white; border: 1px solid var(--primary-bg, #dbeafe);
    color: var(--primary, #2563eb);
    padding: 4px 10px; border-radius: 6px;
    font-size: 12px; font-weight: 600;
    cursor: pointer; font-family: inherit;
}
.rm-selection-bar .rm-clear-btn:hover { background: var(--primary-bg, #dbeafe); }

.rm-select-all-wrap { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted, #6b7280); }
.rm-select-all-wrap input { width: 15px; height: 15px; accent-color: var(--primary, #2563eb); cursor: pointer; margin: 0; }

/* Role buckets grid — 2 columns by default; 4 buckets wrap to a 2x2 layout.
   On wide screens (>= 1400px) expand to 4 columns so all buckets sit in one row. */
.rm-roles-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (min-width: 1400px) {
    .rm-roles-grid { grid-template-columns: repeat(4, 1fr); }
}
.rm-role-bucket {
    position: relative;           /* needed for the .rm-drop-overlay pseudo */
    border: 1.5px solid var(--border, #e5e7eb);
    border-radius: 12px;
    background: var(--bg-subtle, #f3f4f6);
    padding: 12px;
    min-height: 180px;
    transition:
        background-color .15s ease,
        border-color .15s ease,
        transform .15s ease,
        box-shadow .15s ease,
        opacity .15s ease;
}

/* When ANY bucket in the grid is the active drop target, dim the others so
   the eye locks onto where the user is about to release. Uses :has() —
   gracefully degrades to "no dimming" on browsers that don't support it. */
.rm-roles-grid:has(.rm-role-bucket.is-drop-target) .rm-role-bucket:not(.is-drop-target) {
    opacity: 0.45;
    filter: grayscale(0.3);
}

/* Active drop target — bigger, brighter, bordered, with a pulsing glow.
   Per-kind rules below override the base color tint. */
.rm-role-bucket.is-drop-target {
    background: var(--primary-bg, #dbeafe);
    border: 2.5px dashed var(--primary, #2563eb);
    transform: scale(1.025);
    box-shadow:
        0 0 0 4px rgba(37, 99, 235, 0.12),
        0 10px 24px -8px rgba(37, 99, 235, 0.35);
    animation: rm-bucket-pulse 1.6s ease-in-out infinite;
    z-index: 1;
}

@keyframes rm-bucket-pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12), 0 10px 24px -8px rgba(37, 99, 235, 0.35); }
    50%      { box-shadow: 0 0 0 8px rgba(37, 99, 235, 0.18), 0 12px 28px -8px rgba(37, 99, 235, 0.45); }
}

/* Big centered "↓ Drop to add to {Role}" overlay rendered into the bucket
   during drag-over. Sits on top of the existing content so the affordance
   reads even when the bucket already has members in it. The label text is
   injected by the .rm-role-bucket via a CSS var (--rm-drop-label) set on
   the element from the Razor — falls back to "Drop here" if unset. */
.rm-role-bucket.is-drop-target::before {
    content: "↓ Drop here";
    content: var(--rm-drop-label, "↓ Drop here");
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(2px);
    border-radius: 10px;
    font-size: 15px;
    font-weight: 700;
    color: var(--primary, #2563eb);
    letter-spacing: 0.3px;
    pointer-events: none;
    animation: rm-overlay-fade .18s ease-out;
}

@keyframes rm-overlay-fade {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

/* Per-kind color overrides — keep the same pulse/scale geometry, just retint
   the border/glow/overlay text so the bucket's role identity is reinforced. */
.rm-role-bucket.member.is-drop-target {
    background: #d1fae5;
    border-color: var(--success, #059669);
    box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.14), 0 10px 24px -8px rgba(5, 150, 105, 0.4);
    animation-name: rm-bucket-pulse-success;
}
.rm-role-bucket.member.is-drop-target::before { color: var(--success, #059669); }
@keyframes rm-bucket-pulse-success {
    0%, 100% { box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.14), 0 10px 24px -8px rgba(5, 150, 105, 0.4); }
    50%      { box-shadow: 0 0 0 8px rgba(5, 150, 105, 0.22), 0 12px 28px -8px rgba(5, 150, 105, 0.5); }
}

.rm-role-bucket.viewer.is-drop-target {
    background: #e5e7eb;
    border-color: var(--text-muted, #6b7280);
    box-shadow: 0 0 0 4px rgba(107, 114, 128, 0.16), 0 10px 24px -8px rgba(107, 114, 128, 0.35);
    animation-name: rm-bucket-pulse-muted;
}
.rm-role-bucket.viewer.is-drop-target::before { color: var(--text, #111827); }
@keyframes rm-bucket-pulse-muted {
    0%, 100% { box-shadow: 0 0 0 4px rgba(107, 114, 128, 0.16), 0 10px 24px -8px rgba(107, 114, 128, 0.35); }
    50%      { box-shadow: 0 0 0 8px rgba(107, 114, 128, 0.22), 0 12px 28px -8px rgba(107, 114, 128, 0.45); }
}

.rm-role-bucket.pathwayeditor.is-drop-target {
    background: #ccfbf1;
    border-color: #0d9488;
    box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.14), 0 10px 24px -8px rgba(13, 148, 136, 0.4);
    animation-name: rm-bucket-pulse-teal;
}
.rm-role-bucket.pathwayeditor.is-drop-target::before { color: #0d9488; }
@keyframes rm-bucket-pulse-teal {
    0%, 100% { box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.14), 0 10px 24px -8px rgba(13, 148, 136, 0.4); }
    50%      { box-shadow: 0 0 0 8px rgba(13, 148, 136, 0.22), 0 12px 28px -8px rgba(13, 148, 136, 0.5); }
}
.rm-role-bucket-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 8px; margin-bottom: 10px;
}
.rm-role-bucket-title { display: flex; align-items: center; gap: 8px; }
.rm-role-icon {
    width: 28px; height: 28px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: 11px;
}
.rm-role-icon.admin  { background: var(--primary, #2563eb); }
.rm-role-icon.member { background: var(--success, #059669); }
.rm-role-icon.viewer { background: var(--text-muted, #6b7280); }
.rm-role-icon.pathwayeditor { background: #0d9488; }
.rm-role-name { font-size: 13px; font-weight: 700; color: var(--text, #111827); margin: 0; line-height: 1.2; }
.rm-role-desc { font-size: 11px; color: var(--text-muted, #6b7280); margin: 1px 0 0; }
.rm-role-count {
    background: var(--bg-panel, #ffffff);
    border: 1px solid var(--border-strong, #d1d5db);
    color: var(--text-muted, #6b7280);
    font-size: 11px; padding: 2px 8px;
    border-radius: 999px; font-weight: 600;
    flex-shrink: 0;
}
.rm-role-members { display: flex; flex-direction: column; gap: 4px; }
.rm-role-member {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 8px; border-radius: 6px;
    background: var(--bg-panel, #ffffff);
    border: 1px solid var(--border, #e5e7eb);
    font-size: 12px;
}
.rm-role-member-avatar {
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--primary-bg, #dbeafe);
    color: var(--primary, #2563eb);
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 600;
}
.rm-role-member-name { flex: 1; color: var(--text, #111827); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rm-role-member-remove {
    width: 20px; height: 20px;
    border-radius: 4px; border: none;
    background: transparent; color: var(--text-muted, #6b7280);
    cursor: pointer; font-size: 14px; line-height: 1; padding: 0;
}
.rm-role-member-remove:hover { background: var(--danger-bg, #fee2e2); color: var(--danger, #dc2626); }
.rm-role-empty {
    text-align: center; padding: 16px 8px;
    color: var(--text-placeholder, #9ca3af); font-size: 11px;
    border: 1.5px dashed var(--border, #e5e7eb);
    border-radius: 8px;
    background: var(--bg-panel, #ffffff);
}

/* Toast — bottom-center pill */
.rm-toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--text, #111827); color: white;
    padding: 10px 18px; border-radius: 999px;
    font-size: 13px; font-weight: 500;
    opacity: 0; transition: opacity .2s ease;
    pointer-events: none; z-index: 100;
}
.rm-toast.show { opacity: 0.92; }

/* Active state on the Manage Roles toggle button */
.btn-toggle-active {
    background: var(--primary-bg, #dbeafe) !important;
    border-color: var(--primary, #2563eb) !important;
    color: var(--primary-hover, #1d4ed8) !important;
}

/* Multi-role chip column used inside the existing users table — rendered when
   manage mode is OFF but we still want the table to show multi-role users. */
.role-badges-multi { display: inline-flex; flex-wrap: wrap; gap: 4px; }
