/* =====================================================================
   ROLES & PERMISSIONS — list + matrix
   ===================================================================== */

/* Roles grid */
.roles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
    margin-top: 14px;
}

.role-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 18px;
    padding: 18px;
    position: relative;
    overflow: hidden;
    transition: .2s;
    --accent: #6c5ce7;
}
.role-card::before {
    content: ""; position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: var(--accent);
}
.role-card:hover { transform: translateY(-3px); box-shadow: 0 16px 30px rgba(0,0,0,.08); }

.role-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.role-mark {
    width: 48px; height: 48px; border-radius: 14px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
    display: grid; place-items: center;
    flex-shrink: 0;
}
.role-mark .material-symbols-rounded { font-size: 26px; }
.role-titles { flex: 1; min-width: 0; }
.r-name {
    font-size: 16px; font-weight: 800; color: var(--c-text);
    display: flex; align-items: center; gap: 8px;
}
.r-sys-pill {
    background: rgba(108,92,231,.12); color: var(--c-primary);
    font-size: 10.5px; font-weight: 800;
    padding: 2px 8px; border-radius: 999px;
}
.r-key { font-size: 12px; color: var(--c-text-muted); margin-top: 3px; direction: ltr; }

.role-stats {
    display: flex; align-items: center; gap: 12px;
    padding: 14px;
    background: color-mix(in srgb, var(--accent) 5%, transparent);
    border-radius: 12px;
    margin-bottom: 14px;
}
.rs-item { flex: 1; text-align: center; }
.rs-num { display: block; font-size: 22px; font-weight: 800; color: var(--accent); }
.rs-lbl { display: block; font-size: 11px; color: var(--c-text-muted); margin-top: 2px; font-weight: 600; }
.rs-divider { width: 1px; height: 32px; background: var(--c-border); }

.role-perm-bar { margin-bottom: 14px; }
.rpb-track {
    height: 8px;
    background: #f3f4f6;
    border-radius: 999px;
    overflow: hidden;
}
.rpb-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.rpb-label { font-size: 11.5px; color: var(--c-text-muted); margin-top: 5px; text-align: center; font-weight: 600; }

.role-actions { display: flex; gap: 6px; padding-top: 8px; border-top: 1px dashed var(--c-border); }
.role-actions .btn.sm { flex: 1; padding: 7px 12px; font-size: 12.5px; }
.role-actions .btn.sm.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.role-actions .btn.sm.primary:hover { filter: brightness(0.95); }
.role-actions .btn.sm.danger {
    flex: 0 0 auto;
    color: var(--c-red);
    border-color: #fecaca;
}
.role-actions .btn.sm.danger:hover { background: var(--c-red-soft); }

/* ---- Permission summary card on top of matrix ---- */
.perm-summary {
    display: flex; align-items: center; gap: 24px;
    padding: 16px;
    background: rgba(108,92,231,.06);
    border-radius: 12px;
    margin-top: 18px;
    border: 1px dashed rgba(108,92,231,.3);
}
.ps-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ps-num { font-size: 24px; font-weight: 800; color: var(--c-primary); }
.ps-lbl { font-size: 11.5px; color: var(--c-text-muted); font-weight: 600; }
.ps-quick { margin-inline-start: auto; display: flex; gap: 6px; }

.perm-section-title {
    margin: 24px 0 14px;
    font-size: 18px; font-weight: 800;
    color: var(--c-text);
    text-align: end;
    padding-inline-end: 4px;
}

/* ---- Permission matrix grid ---- */
.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 12px;
}

.perm-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 14px;
    overflow: hidden;
}
.perm-card-head {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: rgba(108,92,231,.06);
    border-bottom: 1px solid var(--c-border);
}
.pch-title { flex: 1; font-weight: 800; font-size: 14px; color: var(--c-text); }
.pch-count {
    font-size: 12px; font-weight: 700;
    background: var(--c-surface);
    padding: 4px 10px; border-radius: 999px;
    color: var(--c-text-muted);
    border: 1px solid var(--c-border);
}

.perm-list { padding: 6px 0; }
.perm-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    cursor: pointer;
    transition: .12s;
    user-select: none;
}
.perm-row:hover { background: rgba(108,92,231,.04); }
.perm-row.on { background: rgba(108,92,231,.06); }
.perm-row input[type="checkbox"] {
    width: 18px; height: 18px;
    accent-color: var(--c-primary);
    cursor: pointer;
}
.perm-name { font-size: 13.5px; color: var(--c-text); font-weight: 600; }
.perm-key {
    font-size: 11px;
    color: var(--c-text-muted);
    direction: ltr;
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 6px;
}
